From 51013f75922136a81a4c5b09575670a03a2be3e6 Mon Sep 17 00:00:00 2001 From: n-akram <31505221+n-akram@users.noreply.github.com> Date: Mon, 16 Oct 2023 14:51:03 +0200 Subject: [PATCH] Updated GPS function --- SafeDrones/core/SafeDrones.py | 173 ++++++++++++++++++++++---------- example/safedrones-gps_v2.ipynb | 1 + 2 files changed, 120 insertions(+), 54 deletions(-) create mode 100644 example/safedrones-gps_v2.ipynb diff --git a/SafeDrones/core/SafeDrones.py b/SafeDrones/core/SafeDrones.py index de2bfa8..ca878c3 100644 --- a/SafeDrones/core/SafeDrones.py +++ b/SafeDrones/core/SafeDrones.py @@ -593,19 +593,109 @@ def Chip_MTTF_Model(self,MTTFref=None, Tr=None, Ta = None, u=None,b = None, time return P_Fail.evalf(subs={t: time}), MTTFchip.evalf(subs={t: time}) - def GPS_Failure_Risk_Calc(self, SatStatus=None, time=None, Lambda = None, ): + # def GPS_Failure_Risk_Calc(self, SatStatus=None, time=None, Lambda = None, ): + + # #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + # # Program Name : Markov-based Drone's Reliability and MTTF Estimator % + # # Author : Koorosh Aslansefat % + # # Version : 1.0.0 % + # # Description : A Markov Process-Based Approach for Reliability % + # # Evaluation of the GPS System for Drones % + # #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + # ''' + + # SatStatus: is an integer between 0 and 11. 0 means no satellite is available and 14 means fully satellite coverage. + + # Lambda: Failure Rate of the GPS System. + + # time: Time of the mission + # ''' + + # import numpy as np # linear algebra + # import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) + # import sympy as sym # Symbolic Calculation + + # t = sym.Symbol('t') + + # if SatStatus == None: + # SatStatus = self.SatStatus + # if Lambda == None: + # Lambda = self.GPS_Lambda + # L = Lambda + + # if SatStatus == 14: + # P0_GPS = sym.Matrix([[1],[0],[0],[0],[0],[0],[0],[0],[0]]) + # Sflag = 7 + # elif SatStatus == 13: + # P0_GPS = sym.Matrix([[0],[1],[0],[0],[0],[0],[0],[0],[0]]) + # Sflag = 6 + # elif SatStatus == 12: + # P0_GPS = sym.Matrix([[0],[0],[1],[0],[0],[0],[0],[0],[0]]) + # Sflag = 5 + # elif SatStatus == 11: + # P0_GPS = sym.Matrix([[0],[0],[0],[1],[0],[0],[0],[0],[0]]) + # Sflag = 4 + # elif SatStatus == 10: + # P0_GPS = sym.Matrix([[0],[0],[0],[0],[1],[0],[0],[0],[0]]) + # Sflag = 3 + # elif SatStatus == 9: + # P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[1],[0],[0],[0]]) + # Sflag = 2 + # elif SatStatus == 8: + # P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[0],[1],[0],[0]]) + # Sflag = 1 + # elif SatStatus == 7: + # P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[0],[0],[1],[0]]) + # Sflag = 0 + # else: + # P_Fail = 1 + # MTTF = 0 + # return P_Fail, MTTF + + # M_GPS = sym.Matrix([[-14*L, 0, 0, 0, 0, 0, 0, 0, 0], + # [ 14*L, -13*L, 0, 0, 0, 0, 0, 0, 0], + # [ 0, 13*L, -12*L, 0, 0, 0, 0, 0, 0], + # [ 0, 0, 12*L, -11*L, 0, 0, 0, 0, 0], + # [ 0, 0, 0, 11*L, -10*L, 0, 0, 0, 0], + # [ 0, 0, 0, 0, 10*L, -9*L, 0, 0, 0], + # [ 0, 0, 0, 0, 0, 9*L, -8*L, 0, 0], + # [ 0, 0, 0, 0, 0, 0, 8*L, -7*L, 0], + # [ 0, 0, 0, 0, 0, 0, 0, 7*L, 0]]) + + # P_GPS = sym.exp(M_GPS*t)*P0_GPS + + # P_GPS_Fail = P_GPS[-1] + + # N_GPS = sym.Matrix([[-14*L, 0, 0, 0, 0, 0, 0, 0], + # [ 14*L, -13*L, 0, 0, 0, 0, 0, 0], + # [ 0, 13*L, -12*L, 0, 0, 0, 0, 0], + # [ 0, 0, 12*L, -11*L, 0, 0, 0, 0], + # [ 0, 0, 0, 11*L, -10*L, 0, 0, 0], + # [ 0, 0, 0, 0, 10*L, -9*L, 0, 0], + # [ 0, 0, 0, 0, 0, 9*L, -8*L, 0], + # [ 0, 0, 0, 0, 0, 0, 8*L, -7*L]]) + + # tt = -1*N_GPS.inv() + + # MTTF_GPS = sum(tt[Sflag,:]) + + # return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time}) + + + def GPS_Failure_Risk_Calc(self, SatStatus=None, time=None, Lambda = None, MaxSat = 28, MinSat = 7): #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # Program Name : Markov-based Drone's Reliability and MTTF Estimator % # Author : Koorosh Aslansefat % - # Version : 1.0.0 % + # Version : 1.0.5 % # Description : A Markov Process-Based Approach for Reliability % # Evaluation of the GPS System for Drones % #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ''' - SatStatus: is an integer between 0 and 11. 0 means no satellite is available and 14 means fully satellite coverage. + SatStatus: is an integer between 0 and MaxSat. 0 means no satellite is available and 14 means fully satellite coverage. Lambda: Failure Rate of the GPS System. @@ -617,71 +707,46 @@ def GPS_Failure_Risk_Calc(self, SatStatus=None, time=None, Lambda = None, ): import sympy as sym # Symbolic Calculation t = sym.Symbol('t') - - if SatStatus == None: - SatStatus = self.SatStatus - if Lambda == None: - Lambda = self.GPS_Lambda L = Lambda + + if SatStatus > MaxSat: + print("The satellite status can not be more than maximum number of satellites. ") + raise ValueError + return None, None - if SatStatus == 14: - P0_GPS = sym.Matrix([[1],[0],[0],[0],[0],[0],[0],[0],[0]]) - Sflag = 7 - elif SatStatus == 13: - P0_GPS = sym.Matrix([[0],[1],[0],[0],[0],[0],[0],[0],[0]]) - Sflag = 6 - elif SatStatus == 12: - P0_GPS = sym.Matrix([[0],[0],[1],[0],[0],[0],[0],[0],[0]]) - Sflag = 5 - elif SatStatus == 11: - P0_GPS = sym.Matrix([[0],[0],[0],[1],[0],[0],[0],[0],[0]]) - Sflag = 4 - elif SatStatus == 10: - P0_GPS = sym.Matrix([[0],[0],[0],[0],[1],[0],[0],[0],[0]]) - Sflag = 3 - elif SatStatus == 9: - P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[1],[0],[0],[0]]) - Sflag = 2 - elif SatStatus == 8: - P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[0],[1],[0],[0]]) - Sflag = 1 - elif SatStatus == 7: - P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[0],[0],[1],[0]]) - Sflag = 0 + if MinSat < SatStatus <= MaxSat: + P0_GPS = sym.zeros(MaxSat-MinSat+1, 1) + P0_GPS[SatStatus - MinSat] = 1 + Sflag = MaxSat - SatStatus else: P_Fail = 1 MTTF = 0 return P_Fail, MTTF - - M_GPS = sym.Matrix([[-14*L, 0, 0, 0, 0, 0, 0, 0, 0], - [ 14*L, -13*L, 0, 0, 0, 0, 0, 0, 0], - [ 0, 13*L, -12*L, 0, 0, 0, 0, 0, 0], - [ 0, 0, 12*L, -11*L, 0, 0, 0, 0, 0], - [ 0, 0, 0, 11*L, -10*L, 0, 0, 0, 0], - [ 0, 0, 0, 0, 10*L, -9*L, 0, 0, 0], - [ 0, 0, 0, 0, 0, 9*L, -8*L, 0, 0], - [ 0, 0, 0, 0, 0, 0, 8*L, -7*L, 0], - [ 0, 0, 0, 0, 0, 0, 0, 7*L, 0]]) - + + M_GPS_updated = sym.zeros(MaxSat-MinSat+1, MaxSat-MinSat+1) + start_value = -1*MaxSat + + for i in range(MaxSat-MinSat+1): + if i == (MaxSat-MinSat): + M_GPS_updated[i, i] = (start_value + i) * L + else: + M_GPS_updated[i, i] = (start_value + i) * L + M_GPS_updated[i+1, i] = -(start_value + i) * L + + M_GPS = sym.Matrix(M_GPS_updated) + P_GPS = sym.exp(M_GPS*t)*P0_GPS P_GPS_Fail = P_GPS[-1] - - N_GPS = sym.Matrix([[-14*L, 0, 0, 0, 0, 0, 0, 0], - [ 14*L, -13*L, 0, 0, 0, 0, 0, 0], - [ 0, 13*L, -12*L, 0, 0, 0, 0, 0], - [ 0, 0, 12*L, -11*L, 0, 0, 0, 0], - [ 0, 0, 0, 11*L, -10*L, 0, 0, 0], - [ 0, 0, 0, 0, 10*L, -9*L, 0, 0], - [ 0, 0, 0, 0, 0, 9*L, -8*L, 0], - [ 0, 0, 0, 0, 0, 0, 8*L, -7*L]]) + + N_GPS = M_GPS[:-1, :-1] tt = -1*N_GPS.inv() MTTF_GPS = sum(tt[Sflag,:]) return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time}) - + def calculate_collision_risk(self, uav_1_trajectory, uav_2_trajectory, danger_threshold=-1, collision_threshold=-1): # self.danger_threshold, self.collision_threshold # Check that both trajectories have the same length assert len(uav_1_trajectory) == len(uav_2_trajectory), "Trajectories must have the same length" @@ -699,7 +764,7 @@ def calculate_collision_risk(self, uav_1_trajectory, uav_2_trajectory, danger_th if distance < self.collision_threshold: collision_zone_count += 1 - elif distance < self.danger_threshold: + if distance < self.danger_threshold: danger_zone_count += 1 danger_zone_risk = danger_zone_count / len(uav_1_trajectory) diff --git a/example/safedrones-gps_v2.ipynb b/example/safedrones-gps_v2.ipynb new file mode 100644 index 0000000..d909b4d --- /dev/null +++ b/example/safedrones-gps_v2.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"code","execution_count":1,"metadata":{"execution":{"iopub.execute_input":"2023-10-01T21:19:29.450543Z","iopub.status.busy":"2023-10-01T21:19:29.450121Z","iopub.status.idle":"2023-10-01T21:19:29.468957Z","shell.execute_reply":"2023-10-01T21:19:29.467929Z","shell.execute_reply.started":"2023-10-01T21:19:29.450512Z"},"trusted":true},"outputs":[],"source":["def GPS_Failure_Risk_Calc(SatStatus=None, time=None, Lambda = None, ):\n","\n"," #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"," # Program Name : Markov-based Drone's Reliability and MTTF Estimator %\n"," # Author : Koorosh Aslansefat %\n"," # Version : 1.0.0 %\n"," # Description : A Markov Process-Based Approach for Reliability %\n"," # Evaluation of the GPS System for Drones %\n"," #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"," \n"," '''\n"," \n"," SatStatus: is an integer between 0 and 11. 0 means no satellite is available and 14 means fully satellite coverage. \n"," \n"," Lambda: Failure Rate of the GPS System.\n"," \n"," time: Time of the mission\n"," '''\n"," \n"," import numpy as np # linear algebra\n"," import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n"," import sympy as sym # Symbolic Calculation\n"," \n"," t = sym.Symbol('t')\n","\n"," L = Lambda\n"," \n"," if SatStatus == 14:\n"," P0_GPS = sym.Matrix([[1],[0],[0],[0],[0],[0],[0],[0],[0]])\n"," Sflag = 7\n"," elif SatStatus == 13:\n"," P0_GPS = sym.Matrix([[0],[1],[0],[0],[0],[0],[0],[0],[0]])\n"," Sflag = 6\n"," elif SatStatus == 12:\n"," P0_GPS = sym.Matrix([[0],[0],[1],[0],[0],[0],[0],[0],[0]])\n"," Sflag = 5\n"," elif SatStatus == 11:\n"," P0_GPS = sym.Matrix([[0],[0],[0],[1],[0],[0],[0],[0],[0]])\n"," Sflag = 4\n"," elif SatStatus == 10:\n"," P0_GPS = sym.Matrix([[0],[0],[0],[0],[1],[0],[0],[0],[0]])\n"," Sflag = 3\n"," elif SatStatus == 9:\n"," P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[1],[0],[0],[0]])\n"," Sflag = 2\n"," elif SatStatus == 8:\n"," P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[0],[1],[0],[0]])\n"," Sflag = 1\n"," elif SatStatus == 7:\n"," P0_GPS = sym.Matrix([[0],[0],[0],[0],[0],[0],[0],[1],[0]])\n"," Sflag = 0\n"," else:\n"," P_Fail = 1\n"," MTTF = 0\n","\n"," M_GPS = sym.Matrix([[-14*L, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [ 14*L, -13*L, 0, 0, 0, 0, 0, 0, 0],\n"," [ 0, 13*L, -12*L, 0, 0, 0, 0, 0, 0],\n"," [ 0, 0, 12*L, -11*L, 0, 0, 0, 0, 0],\n"," [ 0, 0, 0, 11*L, -10*L, 0, 0, 0, 0],\n"," [ 0, 0, 0, 0, 10*L, -9*L, 0, 0, 0],\n"," [ 0, 0, 0, 0, 0, 9*L, -8*L, 0, 0],\n"," [ 0, 0, 0, 0, 0, 0, 8*L, -7*L, 0],\n"," [ 0, 0, 0, 0, 0, 0, 0, 7*L, 0]])\n","\n"," P_GPS = sym.exp(M_GPS*t)*P0_GPS\n","\n"," P_GPS_Fail = P_GPS[-1]\n","\n"," N_GPS = sym.Matrix([[-14*L, 0, 0, 0, 0, 0, 0, 0],\n"," [ 14*L, -13*L, 0, 0, 0, 0, 0, 0],\n"," [ 0, 13*L, -12*L, 0, 0, 0, 0, 0],\n"," [ 0, 0, 12*L, -11*L, 0, 0, 0, 0],\n"," [ 0, 0, 0, 11*L, -10*L, 0, 0, 0],\n"," [ 0, 0, 0, 0, 10*L, -9*L, 0, 0],\n"," [ 0, 0, 0, 0, 0, 9*L, -8*L, 0],\n"," [ 0, 0, 0, 0, 0, 0, 8*L, -7*L]])\n"," \n"," tt = -1*N_GPS.inv()\n"," \n"," MTTF_GPS = sum(tt[Sflag,:])\n","\n"," return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time})"]},{"cell_type":"code","execution_count":2,"metadata":{"execution":{"iopub.execute_input":"2023-10-01T21:19:31.149297Z","iopub.status.busy":"2023-10-01T21:19:31.148906Z","iopub.status.idle":"2023-10-01T21:19:32.515866Z","shell.execute_reply":"2023-10-01T21:19:32.514877Z","shell.execute_reply.started":"2023-10-01T21:19:31.149265Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["1.19038762535297e-5\n","1142.85714285714\n"]}],"source":["GPS_P_Fail, GPS_MTTF = GPS_Failure_Risk_Calc(SatStatus=14, time=100, Lambda = 0.001)\n","print(GPS_P_Fail)\n","print(GPS_MTTF)"]},{"cell_type":"code","execution_count":3,"metadata":{"execution":{"iopub.execute_input":"2023-10-01T21:19:47.988701Z","iopub.status.busy":"2023-10-01T21:19:47.987882Z","iopub.status.idle":"2023-10-01T21:19:49.186513Z","shell.execute_reply":"2023-10-01T21:19:49.185445Z","shell.execute_reply.started":"2023-10-01T21:19:47.988668Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["0.0107555729878382\n","363.636363636364\n"]}],"source":["GPS_P_Fail, GPS_MTTF = GPS_Failure_Risk_Calc(SatStatus=10, time=100, Lambda = 0.001)\n","print(GPS_P_Fail)\n","print(GPS_MTTF)"]},{"cell_type":"code","execution_count":4,"metadata":{"execution":{"iopub.execute_input":"2023-10-16T08:48:04.936442Z","iopub.status.busy":"2023-10-16T08:48:04.934777Z","iopub.status.idle":"2023-10-16T08:48:06.165009Z","shell.execute_reply":"2023-10-16T08:48:06.164308Z","shell.execute_reply.started":"2023-10-16T08:48:04.936365Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["⎡-28⋅L 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢28⋅L -27⋅L 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 27⋅L -26⋅L 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 26⋅L -25⋅L 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 25⋅L -24⋅L 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 24⋅L -23⋅L 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 23⋅L -22⋅L 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 22⋅L -21⋅L 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 21⋅L -20⋅L 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 20⋅L -19⋅L 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 19⋅L -18⋅L \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 18⋅L \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎢ 0 0 0 0 0 0 0 0 0 0 0 \n","⎢ \n","⎣ 0 0 0 0 0 0 0 0 0 0 0 \n","\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎤\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n","-17⋅L 0 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n","17⋅L -16⋅L 0 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 16⋅L -15⋅L 0 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 15⋅L -14⋅L 0 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 14⋅L -13⋅L 0 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 13⋅L -12⋅L 0 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 12⋅L -11⋅L 0 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 11⋅L -10⋅L 0 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 10⋅L -9⋅L 0 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 9⋅L -8⋅L 0 ⎥\n"," ⎥\n"," 0 0 0 0 0 0 0 0 0 8⋅L -7⋅L⎦\n"]}],"source":["import sympy as sym\n","\n","L = sym.symbols('L') \n","\n","M_GPS_updated = sym.zeros(22, 22)\n","\n","start_value = -28\n","\n","for i in range(22):\n"," if i == 21:\n"," M_GPS_updated[i, i] = (start_value + i) * L\n"," else:\n"," M_GPS_updated[i, i] = (start_value + i) * L\n"," M_GPS_updated[i+1, i] = -(start_value + i) * L \n","\n","sym.pprint(M_GPS_updated)"]},{"cell_type":"code","execution_count":5,"metadata":{"execution":{"iopub.execute_input":"2023-10-16T08:57:28.635653Z","iopub.status.busy":"2023-10-16T08:57:28.635270Z","iopub.status.idle":"2023-10-16T08:57:28.647962Z","shell.execute_reply":"2023-10-16T08:57:28.645418Z","shell.execute_reply.started":"2023-10-16T08:57:28.635625Z"},"trusted":true},"outputs":[],"source":["def GPS_Failure_Risk_Calc2(SatStatus=None, time=None, Lambda = None, MaxSat = 28, MinSat = 7):\n","\n"," #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"," # Program Name : Markov-based Drone's Reliability and MTTF Estimator %\n"," # Author : Koorosh Aslansefat %\n"," # Version : 1.0.5 %\n"," # Description : A Markov Process-Based Approach for Reliability %\n"," # Evaluation of the GPS System for Drones %\n"," #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"," \n"," '''\n"," \n"," SatStatus: is an integer between 0 and MaxSat. 0 means no satellite is available and 14 means fully satellite coverage. \n"," \n"," Lambda: Failure Rate of the GPS System.\n"," \n"," time: Time of the mission\n"," '''\n"," \n"," import numpy as np # linear algebra\n"," import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n"," import sympy as sym # Symbolic Calculation\n"," \n"," t = sym.Symbol('t')\n","\n"," L = Lambda\n"," \n"," if 7 <= SatStatus <= 28:\n"," P0_GPS = sym.zeros(22, 1)\n"," P0_GPS[SatStatus - 7] = 1\n"," Sflag = 28 - SatStatus\n"," else:\n"," P_Fail = 1\n"," MTTF = 0\n"," \n"," M_GPS_updated = sym.zeros(MaxSat-MinSat+1, MaxSat-MinSat+1)\n"," start_value = -1*MaxSat\n"," \n"," for i in range(MaxSat-MinSat+1):\n"," if i == 21:\n"," M_GPS_updated[i, i] = (start_value + i) * L\n"," else:\n"," M_GPS_updated[i, i] = (start_value + i) * L\n"," M_GPS_updated[i+1, i] = -(start_value + i) * L \n"," \n"," M_GPS = sym.Matrix(M_GPS_updated)\n"," \n"," P_GPS = sym.exp(M_GPS*t)*P0_GPS\n","\n"," P_GPS_Fail = P_GPS[-1]\n"," \n"," N_GPS = M_GPS[:-1, :-1] \n"," \n"," tt = -1*N_GPS.inv()\n"," print(Sflag)\n"," MTTF_GPS = sum(tt[Sflag,:])\n","\n"," return P_GPS_Fail.evalf(subs={t: time}), MTTF_GPS.evalf(subs={t: time})\n"," "]},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[],"source":["import sys\n","import os\n","from sys import platform\n","\n","#from temp import SafeDrones\n","\n","if platform == \"linux\" or platform == \"linux2\":\n"," currentdir = os.path.dirname(os.path.realpath(inspect.getfile(inspect.currentframe())))\n"," parentdir = os.path.dirname(currentdir)\n"," sys.path.insert(0, parentdir)\n","elif platform == \"win32\":\n"," # in Windows, the first path entry contains the directory where the notebook is\n"," sys.path.insert(0, os.path.dirname(sys.path[0]))\n","from SafeDrones.core.SafeDrones import SafeDrones\n","eval = SafeDrones()"]},{"cell_type":"code","execution_count":7,"metadata":{"execution":{"iopub.execute_input":"2023-10-16T09:01:00.302712Z","iopub.status.busy":"2023-10-16T09:01:00.302078Z","iopub.status.idle":"2023-10-16T09:01:10.188535Z","shell.execute_reply":"2023-10-16T09:01:10.187219Z","shell.execute_reply.started":"2023-10-16T09:01:00.302678Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["0.282896728355594\n","111.111111111111\n"]}],"source":["GPS_P_Fail, GPS_MTTF = eval.GPS_Failure_Risk_Calc(SatStatus=27, time=100, Lambda = 0.001, MaxSat = 29, MinSat = 17)\n","print(GPS_P_Fail)\n","print(GPS_MTTF)"]},{"cell_type":"code","execution_count":8,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["0.182683524052735\n","34.4827586206897\n"]}],"source":["GPS_P_Fail, GPS_MTTF = eval.GPS_Failure_Risk_Calc(SatStatus=29, time=100, Lambda = 0.001, MaxSat = 29, MinSat = 17)\n","print(GPS_P_Fail)\n","print(GPS_MTTF)"]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.13"}},"nbformat":4,"nbformat_minor":4}