Skip to content

Commit fdf8ea2

Browse files
committed
Bug fix: GPS failure prediction function
1 parent 5dbecea commit fdf8ea2

File tree

2 files changed

+316
-58
lines changed

2 files changed

+316
-58
lines changed

SafeDrones/core/SafeDrones.py

+104-45
Original file line numberDiff line numberDiff line change
@@ -683,69 +683,69 @@ def Chip_MTTF_Model(self,MTTFref=None, Tr=None, Ta = None, u=None,b = None, time
683683
# return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time})
684684

685685

686-
def GPS_Failure_Risk_Calc(self, SatStatus=None, time=None, Lambda = None, MaxSat = 28, MinSat = 7):
686+
# def GPS_Failure_Risk_Calc(self, SatStatus=None, time=None, Lambda = None, MaxSat = 28, MinSat = 7):
687687

688-
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689-
# Program Name : Markov-based Drone's Reliability and MTTF Estimator %
690-
# Author : Koorosh Aslansefat %
691-
# Version : 1.0.5 %
692-
# Description : A Markov Process-Based Approach for Reliability %
693-
# Evaluation of the GPS System for Drones %
694-
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688+
# #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689+
# # Program Name : Markov-based Drone's Reliability and MTTF Estimator %
690+
# # Author : Koorosh Aslansefat %
691+
# # Version : 1.0.5 %
692+
# # Description : A Markov Process-Based Approach for Reliability %
693+
# # Evaluation of the GPS System for Drones %
694+
# #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695695

696-
'''
696+
# '''
697697

698-
SatStatus: is an integer between 0 and MaxSat. 0 means no satellite is available and 14 means fully satellite coverage.
698+
# SatStatus: is an integer between 0 and MaxSat. 0 means no satellite is available and 14 means fully satellite coverage.
699699

700-
Lambda: Failure Rate of the GPS System.
700+
# Lambda: Failure Rate of the GPS System.
701701

702-
time: Time of the mission
703-
'''
702+
# time: Time of the mission
703+
# '''
704704

705-
import numpy as np # linear algebra
706-
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
707-
import sympy as sym # Symbolic Calculation
705+
# import numpy as np # linear algebra
706+
# import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
707+
# import sympy as sym # Symbolic Calculation
708708

709-
t = sym.Symbol('t')
710-
L = Lambda
709+
# t = sym.Symbol('t')
710+
# L = Lambda
711711

712-
if SatStatus > MaxSat:
713-
print("The satellite status can not be more than maximum number of satellites. ")
714-
raise ValueError
715-
return None, None
712+
# if SatStatus > MaxSat:
713+
# print("The satellite status can not be more than maximum number of satellites. ")
714+
# raise ValueError
715+
# return None, None
716716

717-
if MinSat < SatStatus <= MaxSat:
718-
P0_GPS = sym.zeros(MaxSat-MinSat+1, 1)
719-
P0_GPS[SatStatus - MinSat] = 1
720-
Sflag = MaxSat - SatStatus
721-
else:
722-
P_Fail = 1
723-
MTTF = 0
724-
return P_Fail, MTTF
717+
# if MinSat < SatStatus <= MaxSat:
718+
# P0_GPS = sym.zeros(MaxSat-MinSat+1, 1)
719+
# P0_GPS[SatStatus - MinSat] = 1
720+
# Sflag = MaxSat - SatStatus
721+
# else:
722+
# P_Fail = 1
723+
# MTTF = 0
724+
# return P_Fail, MTTF
725725

726-
M_GPS_updated = sym.zeros(MaxSat-MinSat+1, MaxSat-MinSat+1)
727-
start_value = -1*MaxSat
726+
# M_GPS_updated = sym.zeros(MaxSat-MinSat+1, MaxSat-MinSat+1)
727+
# start_value = -1*MaxSat
728728

729-
for i in range(MaxSat-MinSat+1):
730-
if i == (MaxSat-MinSat):
731-
M_GPS_updated[i, i] = (start_value + i) * L
732-
else:
733-
M_GPS_updated[i, i] = (start_value + i) * L
734-
M_GPS_updated[i+1, i] = -(start_value + i) * L
729+
# for i in range(MaxSat-MinSat+1):
730+
# if i == (MaxSat-MinSat):
731+
# M_GPS_updated[i, i] = (start_value + i) * L
732+
# else:
733+
# M_GPS_updated[i, i] = (start_value + i) * L
734+
# M_GPS_updated[i+1, i] = -(start_value + i) * L
735735

736-
M_GPS = sym.Matrix(M_GPS_updated)
736+
# M_GPS = sym.Matrix(M_GPS_updated)
737737

738-
P_GPS = sym.exp(M_GPS*t)*P0_GPS
738+
# P_GPS = sym.exp(M_GPS*t)*P0_GPS
739739

740-
P_GPS_Fail = P_GPS[-1]
740+
# P_GPS_Fail = P_GPS[-1]
741741

742-
N_GPS = M_GPS[:-1, :-1]
742+
# N_GPS = M_GPS[:-1, :-1]
743743

744-
tt = -1*N_GPS.inv()
744+
# tt = -1*N_GPS.inv()
745745

746-
MTTF_GPS = sum(tt[Sflag,:])
746+
# MTTF_GPS = sum(tt[Sflag,:])
747747

748-
return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time})
748+
# return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time})
749749

750750
def calculate_collision_risk(self, uav_1_trajectory, uav_2_trajectory, danger_threshold=-1, collision_threshold=-1): # self.danger_threshold, self.collision_threshold
751751
# Check that both trajectories have the same length
@@ -772,6 +772,65 @@ def calculate_collision_risk(self, uav_1_trajectory, uav_2_trajectory, danger_th
772772

773773
return danger_zone_risk, collision_zone_risk
774774

775+
776+
def GPS_Failure_Risk_Calc(self, SatStatus=None, time=None, Lambda = None, MaxSat = 29, MinSat = 17):
777+
778+
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
779+
# Program Name : Markov-based Drone's Reliability and MTTF Estimator %
780+
# Authors : Koorosh Aslansefat and Mohammed Naveed Akram %
781+
# Version : 1.0.6 %
782+
# Description : A Markov Process-Based Approach for Reliability %
783+
# Evaluation of the GPS System for Drones %
784+
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
785+
786+
'''
787+
SatStatus: is an integer between 0 and MaxSat. 0 means no satellite is available and 14 means fully satellite coverage.
788+
Lambda: Failure Rate of the GPS System.
789+
time: Time of the mission
790+
'''
791+
792+
t = sym.Symbol('t')
793+
794+
L = Lambda
795+
796+
if SatStatus is None:
797+
SatStatus = self.SatStatus
798+
799+
if MinSat < SatStatus <= MaxSat:
800+
P0_GPS = sym.zeros(MaxSat-MinSat+2, 1) # +2 to account for the additional row
801+
P0_GPS[MaxSat - SatStatus] = 1
802+
Sflag_GPS = (MaxSat-MinSat) - (MaxSat - SatStatus)
803+
else:
804+
P_Fail = 1
805+
MTTF = 0
806+
return P_Fail, MTTF
807+
808+
M_GPS_updated = sym.zeros(MaxSat-MinSat+2, MaxSat-MinSat+2) # +2 to account for the additional row and column
809+
start_value = -1*MaxSat
810+
811+
for i in range(MaxSat-MinSat+2): # +2 to loop through the additional row
812+
if i == MaxSat-MinSat+1: # +1 to account for the additional row
813+
M_GPS_updated[i, i] = (start_value + i) * L
814+
else:
815+
M_GPS_updated[i, i] = (start_value + i) * L
816+
M_GPS_updated[i+1, i] = -(start_value + i) * L
817+
818+
M_GPS_updated[-1,-1] = 0
819+
820+
M_GPS = sym.Matrix(M_GPS_updated)
821+
822+
P_GPS = sym.exp(M_GPS*t)*P0_GPS
823+
824+
P_GPS_Fail = P_GPS[-1]
825+
826+
N_GPS = M_GPS[:-1, :-1]
827+
828+
tt = -1*N_GPS.inv()
829+
830+
MTTF_GPS = sum(tt[Sflag_GPS,:])
831+
832+
return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time})
833+
775834
def Drone_Risk_Calc(self):
776835

777836
import numpy as np

example/SafeDrone-demo-2.ipynb

+212-13
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)