Skip to content

Commit c057785

Browse files
authored
Corrected the errors present in sensor.py
1 parent 81da4b9 commit c057785

File tree

3 files changed

+88
-21
lines changed

3 files changed

+88
-21
lines changed

constants_1U.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,22 @@
101101
SS_THRESHOLD = 0.5
102102

103103
ADC_BIAS = np.array([0,0,0,0,0,0])
104-
ADC_COV = np.array([0,0,0,0,0,0])
104+
ADC_COV = 0.01*np.identity(6)
105+
105106
#GPS (random values)
106-
GPS_POS_COV = np.array([0,0,0])
107-
GPS_VEL_COV = np.array([0,0,0])
108-
GPS_TIME_COV = np.array([0,0,0])
109107
GPS_POS_BIAS = np.array([0,0,0])
110108
GPS_VEL_BIAS = np.array([0,0,0])
111-
GPS_TIME_BIAS = 0
109+
GPS_TIME_BIAS = np.array([0])
110+
GPS_POS_COV = np.identity(3)
111+
GPS_VEL_COV = np.identity(3)
112+
GPS_TIME_COV = np.array([[0]])
112113

113114
#Magnetometer (random values)
114115
MAG_BIAS = np.array([0,0,0])
115-
MAG_COV = np.array([0,0,0])
116+
MAG_COV = 1e-9*np.identity(3)
116117

117118
#Gyroscope (random values)
118119
GYRO_F_BIAS = np.array([0,0,0])
119-
GYRO_F_COV = np.array([0,0,0])
120+
GYRO_F_COV = 1e-9*np.identity(3)
120121

121122
k_detumbling = 4*np.pi*(1+sin(radians(Inclination-11)))*Jmin/TimePeriod #gain constant in B_dot controller (from book by F. Landis Markley)

sensor.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from constants_1U import *
22
import frames as fs
33
import numpy as np
4-
from numpy import nultivariate_normal as mvg
54
import qnv
65

76
def ADC(sun_vector):
@@ -11,7 +10,7 @@ def ADC(sun_vector):
1110
#sunsensor gain : multiplying factor that converts dot product of sunvector with normal to voltage
1211
#output : 6 voltages, 1 per sunsensor
1312

14-
u=1/(SS_QUANTIZER-1)
13+
u=1/(SS_QUANTIZER-1) #Reference for this
1514

1615
m_normalVectors = np.zeros([6,3]) #matrix of normal vectors of sensors
1716
#S1 and S2 are opposite, S3 and S4 are opposite, S5 and S6 are opposite
@@ -31,7 +30,7 @@ def ADC(sun_vector):
3130
v=(u)*(round(v/u))*SS_GAIN #conversion from dot product to voltage
3231
v_output[iter] = v
3332

34-
v_output = v_output + mvg(ADC_BIAS,ADC_COV) #add error to true quantity
33+
v_output = v_output + np.random.multivariate_normal(ADC_BIAS,ADC_COV) #add error to true quantity
3534

3635
return v_output
3736

@@ -81,9 +80,9 @@ def calc_SV(ss):
8180

8281
def sunsensor(sat):
8382

84-
v_q_BO = sat.getQ_BO()
85-
v_s_o = sat.getSun_o() #obtain sunvector in orbit frame
86-
v_s_b = qnv.quatRotate(v_q_BO,v_s_o) #obtain sunvector in body frame
83+
v_q_BI = sat.getQ_BI()
84+
v_s_i = sat.getSun_i() #obtain sunvector in orbit frame
85+
v_s_b = qnv.quatRotate(v_q_BI,v_s_i) #obtain sunvector in body frame
8786
ss_read = ADC(v_s_b) #find reading per sunsensor, error already incorporated in ADC code
8887
v_sun_b_m = calc_SV(ss_read) #calculate sunvector from sunsensor readings
8988

@@ -101,9 +100,9 @@ def GPS(sat):
101100
time = sat.getTime()
102101

103102
#add errors to true quantities
104-
v_pos_m = v_pos + mvg(GPS_POS_BIAS,GPS_POS_COV)
105-
v_vel_m = v_vel + mvg(GPS_VEL_BIAS,GPS_VEL_COV)
106-
time_m = time + mvg(GPS_TIME_BIAS,GPS_TIME_COV)
103+
v_pos_m = v_pos + np.random.multivariate_normal(GPS_POS_BIAS,GPS_POS_COV)
104+
v_vel_m = v_vel + np.random.multivariate_normal(GPS_VEL_BIAS,GPS_VEL_COV)
105+
time_m = time + np.random.multivariate_normal(GPS_TIME_BIAS,GPS_TIME_COV)
107106

108107
return np.hstack([v_pos_m,v_vel_m,time_m])
109108

@@ -112,16 +111,16 @@ def magnetometer(sat):
112111
#input : satellite class object
113112
#output : measured magnetic field
114113

115-
v_q_BO = sat.getQ_BO()
116-
v_B_o = sat.getMag_o() #obtain magnetic field in orbit frame
117-
v_B_b = qnv.quatRotate(v_q_BO,v_B_o) #obtain magnetic field in body frame
118-
v_B_m = v_B_b + mvg(MAG_BIAS,MAG_COV) #add errors
114+
v_q_BI = sat.getQ_BI()
115+
v_B_i = sat.getMag_i() #obtain magnetic field in orbit frame
116+
v_B_b = qnv.quatRotate(v_q_BI,v_B_i) #obtain magnetic field in body frame
117+
v_B_m = v_B_b + np.random.multivariate_normal(MAG_BIAS,MAG_COV) #add errors
119118
return v_B_m
120119

121120
def gyroscope(sat):
122121

123122
v_w_BIB = sat.getW_BI_b()
124123
v_bias_var = sat.getGyroVarBias()
125-
v_w_BIB_m = v_w_BIB + v_bias_var + mvg(GYRO_F_BIAS,GYRO_F_COV)
124+
v_w_BIB_m = v_w_BIB + v_bias_var + np.random.multivariate_normal(GYRO_F_BIAS,GYRO_F_COV)
126125

127126
return v_w_BIB_m

test_solver.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from solver import updateStateTimeRK4
2+
import numpy as np
3+
import frames
4+
import unittest
5+
import satellite
6+
from dynamics import x_dot_BO
7+
from constants_1U import G, M_EARTH, v_w_IO_o
8+
from ddt import data, ddt
9+
10+
def f_constant(sat):
11+
cons = np.array((1.,1.,1.,1.,1.,1.,1.))
12+
return cons
13+
@ddt
14+
class TestSolver(unittest.TestCase):
15+
16+
def test_constant(self):
17+
t0 = 0.0
18+
mySat = satellite.Satellite(np.array([1.0,0.,0.,0.,0.,0.,0.]),t0)
19+
t = 10
20+
mySat.setPos(np.array([1e6,0.,0.]))
21+
mySat.setVel(np.array([5.0,5.0,0.0]))
22+
h = 0.1
23+
for i in range(0,int(t/h)):
24+
updateStateTimeRK4(mySat,f_constant,h)
25+
mySat.setTime(t0+(i+1)*h)
26+
self.assertTrue(np.allclose([10.0,10.0,10.0],mySat.getW_BO_b()))
27+
28+
@data(0.001,0.005,0.05,0.1,0.5)
29+
def test_dynamics(self,value):
30+
t0 = 0.
31+
h = value
32+
33+
v_q_BO = np.array([0.4,0.254,-0.508,0.71931912])
34+
35+
v_w_BO_b = frames.wBIb2wBOb(np.array([0.1,-0.05,-0.3]),v_q_BO,v_w_IO_o)
36+
37+
mySat1 = satellite.Satellite(np.hstack((v_q_BO, v_w_BO_b)),t0)
38+
39+
mySat1.setPos(np.array([1e6,53e5,0.]))
40+
mySat1.setVel(np.array([5.60,-5.0,0.0]))
41+
mySat1.setDisturbance_b(np.array([10e-10,-4e-6,-3e-5]))
42+
mySat1.setControl_b(np.array([1e-5,1e-5,-8e-4]))
43+
44+
updateStateTimeRK4(mySat1,x_dot_BO,h)
45+
x1 = mySat1.getState()
46+
47+
mySat2 = satellite.Satellite(np.hstack((v_q_BO, v_w_BO_b)),t0)
48+
49+
mySat2.setPos(np.array([1e6,53e5,0.]))
50+
mySat2.setVel(np.array([5.60,-5.0,0.0]))
51+
mySat2.setDisturbance_b(np.array([10e-10,-4e-6,-3e-5]))
52+
mySat2.setControl_b(np.array([1e-5,1e-5,-8e-4]))
53+
54+
mySat2.setState(np.hstack((v_q_BO,v_w_BO_b)))
55+
k1 = h*x_dot_BO(mySat2)
56+
mySat2.setState(np.hstack((v_q_BO,v_w_BO_b))+0.5*k1)
57+
k2 = h*x_dot_BO(mySat2)
58+
mySat2.setState(np.hstack((v_q_BO,v_w_BO_b))+0.5*(k2))
59+
k3 = h*x_dot_BO(mySat2)
60+
mySat2.setState(np.hstack((v_q_BO,v_w_BO_b))+k3)
61+
k4 = h*x_dot_BO(mySat2)
62+
63+
error_state = np.hstack((v_q_BO,v_w_BO_b)) + (1./6.)*(k1 + 2.*k2 + 2.*k3 + k4)
64+
self.assertTrue(np.allclose(error_state,x1))
65+
66+
if __name__=="__main__":
67+
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)