20
20
21
21
#include " inertialAttitudeUkf.h"
22
22
23
- InertialAttitudeUkf::InertialAttitudeUkf (AttitudeFilterMethod method){
24
- this ->measurementAcceptanceMethod = method;
25
- }
23
+ InertialAttitudeUkf::InertialAttitudeUkf (AttitudeFilterMethod method) { this ->measurementAcceptanceMethod = method; }
26
24
27
- void InertialAttitudeUkf::customreset (){
25
+ void InertialAttitudeUkf::customreset () {
28
26
/* ! No custom reset for this module */
29
- std::function<FilterStateVector (double , const FilterStateVector)> attitudeDynamics = [this ](double t, const FilterStateVector &state){
30
- Eigen::Vector3d mrp (state.getPositionStates ());
31
- Eigen::Vector3d omega (state.getVelocityStates ());
32
- Eigen::MatrixXd bMat = bmatMrp (mrp);
33
-
34
- FilterStateVector stateDerivative;
35
- PositionState mrpDot;
36
- mrpDot.setValues (0.25 *bMat*omega);
37
- stateDerivative.setPosition (mrpDot);
38
-
39
- Eigen::Vector3d wheelTorque = Eigen::Vector3d::Zero ();
40
- for (int i=0 ; i<this ->rwArrayConfigPayload .numRW ; i++){
41
- Eigen::Vector3d gsMatrix = Eigen::Map<Eigen::Vector3d>(&this ->rwArrayConfigPayload .GsMatrix_B [i*3 ]);
42
- wheelTorque -= this ->wheelAccelerations [i]*this ->rwArrayConfigPayload .JsList [i]*gsMatrix;
43
- }
44
-
45
- VelocityState omegaDot;
46
- omegaDot.setValues (-this ->spacecraftInertiaInverse *(tildeMatrix (omega)*this ->spacecraftInertia *omega + wheelTorque));
47
- stateDerivative.setVelocity (omegaDot);
48
-
49
- return stateDerivative;
50
- };
27
+ std::function<FilterStateVector (double , const FilterStateVector)> attitudeDynamics =
28
+ [this ](double t, const FilterStateVector &state) {
29
+ Eigen::Vector3d mrp (state.getPositionStates ());
30
+ Eigen::Vector3d omega (state.getVelocityStates ());
31
+ Eigen::MatrixXd bMat = bmatMrp (mrp);
32
+
33
+ FilterStateVector stateDerivative;
34
+ PositionState mrpDot;
35
+ mrpDot.setValues (0.25 * bMat * omega);
36
+ stateDerivative.setPosition (mrpDot);
37
+
38
+ Eigen::Vector3d wheelTorque = Eigen::Vector3d::Zero ();
39
+ for (int i = 0 ; i < this ->rwArrayConfigPayload .numRW ; i++) {
40
+ Eigen::Vector3d gsMatrix = Eigen::Map<Eigen::Vector3d>(&this ->rwArrayConfigPayload .GsMatrix_B [i * 3 ]);
41
+ wheelTorque -= this ->wheelAccelerations [i] * this ->rwArrayConfigPayload .JsList [i] * gsMatrix;
42
+ }
43
+
44
+ VelocityState omegaDot;
45
+ omegaDot.setValues (-this ->spacecraftInertiaInverse *
46
+ (tildeMatrix (omega) * this ->spacecraftInertia * omega + wheelTorque));
47
+ stateDerivative.setVelocity (omegaDot);
48
+
49
+ return stateDerivative;
50
+ };
51
51
this ->dynamics .setDynamics (attitudeDynamics);
52
52
}
53
53
54
54
/* ! Before every update, check the MRP norm for a shadow set switch
55
55
@return void
56
56
*/
57
- void InertialAttitudeUkf::customInitializeUpdate (){
57
+ void InertialAttitudeUkf::customInitializeUpdate () {
58
58
PositionState mrp;
59
59
mrp.setValues (mrpSwitch (this ->state .getPositionStates (), this ->mrpSwitchThreshold ));
60
60
this ->state .setPosition (mrp);
@@ -63,9 +63,9 @@ void InertialAttitudeUkf::customInitializeUpdate(){
63
63
/* ! After every update, check the MRP norm for a shadow set switch
64
64
@return void
65
65
*/
66
- void InertialAttitudeUkf::customFinalizeUpdate (){
66
+ void InertialAttitudeUkf::customFinalizeUpdate () {
67
67
PositionState mrp;
68
- mrp.setValues ( mrpSwitch (this ->state .getPositionStates (), this ->mrpSwitchThreshold ));
68
+ mrp.setValues (mrpSwitch (this ->state .getPositionStates (), this ->mrpSwitchThreshold ));
69
69
this ->state .setPosition (mrp);
70
70
}
71
71
@@ -90,25 +90,25 @@ void InertialAttitudeUkf::writeOutputMessages(uint64_t currentSimNanos) {
90
90
eigenMatrixXd2CArray (this ->xBar .returnValues (), filterPayload.stateError );
91
91
eigenMatrixXd2CArray (this ->covar , filterPayload.covar );
92
92
93
- for (size_t index = 0 ; index < MAX_MEASUREMENT_NUMBER; index ++){
93
+ for (size_t index = 0 ; index < MAX_MEASUREMENT_NUMBER; index ++) {
94
94
if (this ->measurements [index ].has_value ()) {
95
95
auto measurement = this ->measurements [index ].value ();
96
- if (measurement.getMeasurementName () == " starTracker" ){
96
+ if (measurement.getMeasurementName () == " starTracker" ) {
97
97
starTrackerPayload.valid = true ;
98
98
starTrackerPayload.numberOfObservations = 1 ;
99
99
starTrackerPayload.sizeOfObservations = measurement.size ();
100
100
eigenMatrixXd2CArray (measurement.getObservation (), &starTrackerPayload.observation [0 ]);
101
101
eigenMatrixXd2CArray (measurement.getPostFitResiduals (), &starTrackerPayload.postFits [0 ]);
102
102
eigenMatrixXd2CArray (measurement.getPreFitResiduals (), &starTrackerPayload.preFits [0 ]);
103
- }
104
- if (measurement.getMeasurementName () == " gyro" ){
103
+ }
104
+ if (measurement.getMeasurementName () == " gyro" ) {
105
105
gyroPayload.valid = true ;
106
106
gyroPayload.numberOfObservations = 1 ;
107
107
gyroPayload.sizeOfObservations = measurement.size ();
108
108
eigenMatrixXd2CArray (measurement.getObservation (), &gyroPayload.observation [0 ]);
109
109
eigenMatrixXd2CArray (measurement.getPostFitResiduals (), &gyroPayload.postFits [0 ]);
110
110
eigenMatrixXd2CArray (measurement.getPreFitResiduals (), &gyroPayload.preFits [0 ]);
111
- }
111
+ }
112
112
this ->measurements [index ].reset ();
113
113
}
114
114
}
@@ -120,65 +120,68 @@ void InertialAttitudeUkf::writeOutputMessages(uint64_t currentSimNanos) {
120
120
}
121
121
122
122
/* ! Read current RW speends and populate the accelerations in order to propagate
123
- * @return void
124
- * */
125
- void InertialAttitudeUkf::readRWSpeedData (){
123
+ * @return void
124
+ * */
125
+ void InertialAttitudeUkf::readRWSpeedData () {
126
126
RWSpeedMsgPayload rwSpeedPayload = this ->rwSpeedMsg ();
127
127
uint64_t wheelSpeedTime = this ->rwSpeedMsg .timeWritten ();
128
- if (this ->firstFilterPass ){
129
- this ->wheelAccelerations << 0 ,0 , 0 , 0 ;
128
+ if (this ->firstFilterPass ) {
129
+ this ->wheelAccelerations << 0 , 0 , 0 , 0 ;
130
130
this ->previousWheelSpeeds = Eigen::Map<Eigen::Matrix<double , 1 , 4 >>(rwSpeedPayload.wheelSpeeds );
131
- this ->previousWheelSpeedTime = wheelSpeedTime* NANO2SEC;
132
- }
133
- else {
134
- double dt = wheelSpeedTime*NANO2SEC - this ->previousWheelSpeedTime ;
135
- this -> wheelAccelerations = (Eigen::Map<Eigen::Matrix<double , 1 , 4 >>(rwSpeedPayload.wheelSpeeds ) - this ->previousWheelSpeeds )/ dt;
131
+ this ->previousWheelSpeedTime = wheelSpeedTime * NANO2SEC;
132
+ } else {
133
+ double dt = wheelSpeedTime * NANO2SEC - this -> previousWheelSpeedTime ;
134
+ this ->wheelAccelerations =
135
+ (Eigen::Map<Eigen::Matrix<double , 1 , 4 >>(rwSpeedPayload.wheelSpeeds ) - this ->previousWheelSpeeds ) / dt;
136
136
}
137
137
}
138
138
139
139
/* ! Loop through the all the input star trackers and populate their measurement container if they are foward
140
140
* in time
141
- * @return void
142
- * */
143
- void InertialAttitudeUkf::readStarTrackerData (){
144
- for (int index = 0 ; index < this ->numberOfStarTackers ; index ++){
141
+ * @return void
142
+ * */
143
+ void InertialAttitudeUkf::readStarTrackerData () {
144
+ for (int index = 0 ; index < this ->numberOfStarTackers ; index ++) {
145
145
auto starTracker = this ->starTrackerMessages [index ].starTrackerMsg ();
146
- if (starTracker.timeTag * NANO2SEC > this ->previousFilterTimeTag ){
146
+ if (starTracker.timeTag * NANO2SEC > this ->previousFilterTimeTag ) {
147
147
auto starTrackerMeasurement = MeasurementModel ();
148
148
starTrackerMeasurement.setMeasurementName (" starTracker" );
149
- starTrackerMeasurement.setTimeTag (starTracker.timeTag * NANO2SEC);
149
+ starTrackerMeasurement.setTimeTag (starTracker.timeTag * NANO2SEC);
150
150
starTrackerMeasurement.setValidity (true );
151
151
152
- starTrackerMeasurement.setMeasurementNoise (
153
- this -> measNoiseScaling * this ->starTrackerMessages [index ].measurementNoise );
154
- starTrackerMeasurement.setObservation (mrpSwitch (Eigen::Map<Eigen::Vector3d>(starTracker. MRP_BdyInrtl ),
155
- this ->mrpSwitchThreshold ));
152
+ starTrackerMeasurement.setMeasurementNoise (this -> measNoiseScaling *
153
+ this ->starTrackerMessages [index ].measurementNoise );
154
+ starTrackerMeasurement.setObservation (
155
+ mrpSwitch (Eigen::Map<Eigen::Vector3d>(starTracker. MRP_BdyInrtl ), this ->mrpSwitchThreshold ));
156
156
starTrackerMeasurement.setMeasurementModel (MeasurementModel::mrpStates);
157
157
this ->measurements [this ->measurementIndex ] = starTrackerMeasurement;
158
158
this ->measurementIndex += 1 ;
159
159
this ->validStarTracker = true ;
160
160
/* ! - Only consider the filter started once a Star Tracker image is processed */
161
- if (this ->firstFilterPass ){this ->firstFilterPass = false ;}
161
+ if (this ->firstFilterPass ) {
162
+ this ->firstFilterPass = false ;
163
+ }
164
+ } else {
165
+ this ->validStarTracker = false ;
162
166
}
163
- else {this ->validStarTracker =false ;}
164
167
}
165
168
}
166
169
167
170
/* ! Loop through the entire gyro buffer to find the first index that is in the future compared to the
168
- * previousFilterTimeTag. This does not assume the data comes in chronological order since the gyro data
169
- * is a ring buffer and can wrap around
170
- * @return void
171
- * */
172
- void InertialAttitudeUkf::readGyroData (){
171
+ * previousFilterTimeTag. This does not assume the data comes in chronological order since the gyro data
172
+ * is a ring buffer and can wrap around
173
+ * @return void
174
+ * */
175
+ void InertialAttitudeUkf::readGyroData () {
173
176
IMUSensorMsgPayload gyroBuffer = this ->imuSensorDataInMsg ();
174
- if (gyroBuffer.timeTag * NANO2SEC > this ->previousFilterTimeTag ) {
177
+ if (gyroBuffer.timeTag * NANO2SEC > this ->previousFilterTimeTag ) {
175
178
auto gyroMeasurement = MeasurementModel ();
176
179
gyroMeasurement.setMeasurementName (" gyro" );
177
180
gyroMeasurement.setTimeTag (gyroBuffer.timeTag );
178
181
gyroMeasurement.setValidity (true );
179
182
180
- gyroMeasurement.setMeasurementNoise (
181
- this -> measNoiseScaling * this -> gyroNoise / std::sqrt (gyroBuffer.numberOfValidGyroMeasurements ));
183
+ gyroMeasurement.setMeasurementNoise (this -> measNoiseScaling * this -> gyroNoise /
184
+ std::sqrt (gyroBuffer.numberOfValidGyroMeasurements ));
182
185
gyroMeasurement.setObservation (cArray2EigenVector3d (gyroBuffer.AngVelPlatform ));
183
186
gyroMeasurement.setMeasurementModel (MeasurementModel::velocityStates);
184
187
this ->measurements [this ->measurementIndex ] = gyroMeasurement;
@@ -218,21 +221,17 @@ void InertialAttitudeUkf::readFilterMeasurements() {
218
221
@param Eigen::Matrix3d gyroNoise
219
222
@return void
220
223
*/
221
- void InertialAttitudeUkf::setGyroNoise (const Eigen::Matrix3d &gyroNoiseInput) {
222
- this ->gyroNoise = gyroNoiseInput;
223
- }
224
+ void InertialAttitudeUkf::setGyroNoise (const Eigen::Matrix3d &gyroNoiseInput) { this ->gyroNoise = gyroNoiseInput; }
224
225
225
226
/* ! Get the gyro measurement noise matrix
226
227
@return Eigen::Matrix3d gyroNoise
227
228
*/
228
- Eigen::Matrix3d InertialAttitudeUkf::getGyroNoise () const {
229
- return this ->gyroNoise ;
230
- }
229
+ Eigen::Matrix3d InertialAttitudeUkf::getGyroNoise () const { return this ->gyroNoise ; }
231
230
232
231
/* ! Add a star tracker to the filter solution using the StarTrackerMessage class
233
232
@return StarTrackerMessage starTracker
234
233
*/
235
- void InertialAttitudeUkf::addStarTrackerInput (const StarTrackerMessage &starTracker){
234
+ void InertialAttitudeUkf::addStarTrackerInput (const StarTrackerMessage &starTracker) {
236
235
this ->starTrackerMessages [this ->numberOfStarTackers ] = starTracker;
237
236
this ->numberOfStarTackers += 1 ;
238
237
}
@@ -250,7 +249,7 @@ Eigen::Matrix3d InertialAttitudeUkf::getStarTrackerNoise(int starTrackerNumber)
250
249
@param double step
251
250
@param double frequencyCutOff
252
251
*/
253
- void InertialAttitudeUkf::setLowPassFilter (double step, double frequencyCutOff){
252
+ void InertialAttitudeUkf::setLowPassFilter (double step, double frequencyCutOff) {
254
253
this ->hStep = step;
255
254
this ->cutOffFrequency = frequencyCutOff;
256
255
}
0 commit comments