-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor GaussMarkov sensor noise handling #881
base: develop
Are you sure you want to change the base?
Changes from all commits
b26e254
b297976
ee6cf0d
d99b5df
16be932
74aea31
e04558d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ class CoarseSunSensor: public SysModel { | |
void scaleSensorValues(); //!< scale the sensor values | ||
void applySaturation(); //!< apply saturation effects to sensed output (floor and ceiling) | ||
void writeOutputMessages(uint64_t Clock); //!< @brief method to write the output message to the system | ||
|
||
public: | ||
ReadFunctor<SpicePlanetStateMsgPayload> sunInMsg; //!< [-] input message for sun data | ||
ReadFunctor<SCStatesMsgPayload> stateInMsg; //!< [-] input message for spacecraft state | ||
|
@@ -88,7 +88,7 @@ class CoarseSunSensor: public SysModel { | |
double kellyFactor; //!< [-] Kelly curve fit for output cosine curve | ||
double fov; //!< [-] rad, field of view half angle | ||
Eigen::Vector3d r_B; //!< [m] position vector in body frame | ||
Eigen::Vector3d r_PB_B; //!< [m] misalignment of CSS platform wrt spacecraft body frame | ||
Eigen::Vector3d r_PB_B; //!< [m] misalignment of CSS platform wrt spacecraft body frame | ||
double senBias; //!< [-] Sensor bias value | ||
double senNoiseStd; //!< [-] Sensor noise value | ||
double faultNoiseStd; //!< [-] Sensor noise value if CSSFAULT_RAND is triggered | ||
|
@@ -99,6 +99,9 @@ class CoarseSunSensor: public SysModel { | |
int CSSGroupID=-1; //!< [-] (optional) CSS group id identifier, -1 means it is not set and default is used | ||
BSKLogger bskLogger; //!< -- BSK Logging | ||
|
||
void setAMatrix(const Eigen::Matrix<double, -1, 1, 0, -1, 1>& propMatrix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make the getAMatrix()? |
||
Eigen::Matrix<double, -1, 1, 0, -1, 1> getAMatrix() const; | ||
|
||
private: | ||
SpicePlanetStateMsgPayload sunData; //!< [-] Unused for now, but including it for future | ||
SCStatesMsgPayload stateCurrent; //!< [-] Current SSBI-relative state | ||
|
@@ -107,11 +110,12 @@ class CoarseSunSensor: public SysModel { | |
GaussMarkov noiseModel; //! [-] Gauss Markov noise generation model | ||
GaussMarkov faultNoiseModel; //! [-] Gauss Markov noise generation model exclusively for CSS fault | ||
Saturate saturateUtility; //! [-] Saturation utility | ||
Eigen::Matrix<double, -1, 1, 0, -1, 1> propagationMatrix; // Store the propagation matrix | ||
}; | ||
|
||
//!@brief Constellation of coarse sun sensors for aggregating output information | ||
/*! This class is a thin container on top of the above coarse-sun sensor class. | ||
It is used to aggregate the output messages of the coarse sun-sensors into a | ||
/*! This class is a thin container on top of the above coarse-sun sensor class. | ||
It is used to aggregate the output messages of the coarse sun-sensors into a | ||
a single output for use by downstream models.*/ | ||
class CSSConstellation: public SysModel { | ||
public: | ||
|
@@ -120,7 +124,7 @@ class CSSConstellation: public SysModel { | |
void Reset(uint64_t CurrentClock); //!< Method for reseting the module | ||
void UpdateState(uint64_t CurrentSimNanos); //!< @brief [-] Main update method for CSS constellation | ||
void appendCSS(CoarseSunSensor *newSensor); //!< @brief [-] Method for adding sensor to list | ||
|
||
public: | ||
Message<CSSArraySensorMsgPayload> constellationOutMsg; //!< [-] CSS constellation output message | ||
std::vector<CoarseSunSensor *> sensorList; //!< [-] List of coarse sun sensors in constellation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update module RST file on how to set noise values. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,10 +54,8 @@ ImuSensor::ImuSensor() | |
this->AMatrixGyro.fill(0.0); | ||
this->PMatrixAccel.fill(0.0); | ||
this->AMatrixAccel.fill(0.0); | ||
this->walkBoundsGyro.fill(0.0); | ||
this->walkBoundsAccel.fill(0.0); | ||
this->navErrorsGyro.fill(0.0); | ||
this->navErrorsAccel.fill(0.0); | ||
this->walkBoundsGyro.fill(0.0); // December 2025: rename to errorBoundsGyro | ||
this->walkBoundsAccel.fill(0.0); // December 2025: rename to errorBoundsAccel | ||
this->previous_omega_BN_B.fill(0.0); | ||
this->current_omega_BN_B.fill(0.0); | ||
this->current_nonConservativeAccelpntB_B.fill(0.0); | ||
|
@@ -103,8 +101,6 @@ void ImuSensor::Reset(uint64_t CurrentSimNanos) | |
bskLogger.bskLog(BSK_ERROR, "imuSensor.scStateInMsg was not linked."); | ||
} | ||
|
||
this->AMatrixAccel.setIdentity(this->numStates,this->numStates); | ||
|
||
//! - Alert the user if the noise matrix was not the right size. That'd be bad. | ||
if(this->PMatrixAccel.cols() != this->numStates || this->PMatrixAccel.rows() != this->numStates) | ||
{ | ||
|
@@ -115,8 +111,6 @@ void ImuSensor::Reset(uint64_t CurrentSimNanos) | |
this->errorModelAccel.setRNGSeed(this->RNGSeed); | ||
this->errorModelAccel.setUpperBounds(this->walkBoundsAccel); | ||
|
||
this->AMatrixGyro.setIdentity(this->numStates, this->numStates); | ||
|
||
//! - Alert the user if the noise matrix was not the right size. That'd be bad. | ||
if(this->PMatrixGyro.rows() != this->numStates || this->PMatrixGyro.cols() != this->numStates) | ||
{ | ||
|
@@ -416,3 +410,79 @@ void ImuSensor::UpdateState(uint64_t CurrentSimNanos) | |
|
||
return; | ||
} | ||
|
||
/*! | ||
Setter for `AMatrixAccel` | ||
@param propMatrix Matrix to set | ||
*/ | ||
void ImuSensor::setAMatrixAccel(const Eigen::MatrixXd& propMatrix) | ||
{ | ||
this->AMatrixAccel = propMatrix; | ||
this->errorModelAccel.setPropMatrix(propMatrix); | ||
} | ||
|
||
/*! | ||
Setter for `AMatrixGyro` | ||
@param propMatrix Matrix to set | ||
*/ | ||
void ImuSensor::setAMatrixGyro(const Eigen::MatrixXd& propMatrix) | ||
{ | ||
this->AMatrixGyro = propMatrix; | ||
this->errorModelGyro.setPropMatrix(propMatrix); | ||
} | ||
|
||
/*! | ||
Getter for `AMatrixAccel` | ||
@return Current matrix | ||
*/ | ||
Eigen::MatrixXd ImuSensor::getAMatrixAccel() const | ||
{ | ||
return this->AMatrixAccel; | ||
} | ||
|
||
/*! | ||
Getter for `AMatrixGyro` | ||
@return Current matrix | ||
*/ | ||
Eigen::MatrixXd ImuSensor::getAMatrixGyro() const | ||
{ | ||
return this->AMatrixGyro; | ||
} | ||
|
||
/*! | ||
Setter for `walkBoundsAccel` | ||
@param bounds Bounds vector to set | ||
*/ | ||
void ImuSensor::setWalkBoundsAccel(const Eigen::Vector3d& bounds) | ||
{ | ||
this->walkBoundsAccel = bounds; | ||
this->errorModelAccel.setUpperBounds(bounds); | ||
} | ||
|
||
/*! | ||
Setter for `walkBoundsGyro` | ||
@param bounds Bounds vector to set | ||
*/ | ||
void ImuSensor::setWalkBoundsGyro(const Eigen::Vector3d& bounds) | ||
{ | ||
this->walkBoundsGyro = bounds; | ||
this->errorModelGyro.setUpperBounds(bounds); | ||
} | ||
|
||
/*! | ||
Getter for `walkBoundsAccel` | ||
@return Current bounds | ||
*/ | ||
Eigen::Vector3d ImuSensor::getWalkBoundsAccel() const | ||
{ | ||
return this->walkBoundsAccel; | ||
} | ||
|
||
/*! | ||
Getter for `walkBoundsGyro` | ||
@return Current bounds | ||
*/ | ||
Eigen::Vector3d ImuSensor::getWalkBoundsGyro() const | ||
{ | ||
return this->walkBoundsGyro; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the imuSensor.rst file to discuss how to properly set the noise values. You can note that the use of directly setting |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ class ImuSensor: public SysModel { | |
public: | ||
ImuSensor(); | ||
~ImuSensor(); | ||
|
||
void Reset(uint64_t CurrentSimNanos); | ||
void UpdateState(uint64_t CurrentSimNanos); | ||
void readInputMessages(); | ||
|
@@ -59,6 +59,14 @@ class ImuSensor: public SysModel { | |
void setRoundDirection(roundDirection_t aRound, roundDirection_t oRound); | ||
void set_oSatBounds(Eigen::MatrixXd oSatBounds); | ||
void set_aSatBounds(Eigen::MatrixXd aSatBounds); | ||
void setAMatrixAccel(const Eigen::MatrixXd& propMatrix); | ||
void setAMatrixGyro(const Eigen::MatrixXd& propMatrix); | ||
Eigen::MatrixXd getAMatrixAccel() const; | ||
Eigen::MatrixXd getAMatrixGyro() const; | ||
void setWalkBoundsAccel(const Eigen::Vector3d& bounds); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update to the new setter and getter names? |
||
void setWalkBoundsGyro(const Eigen::Vector3d& bounds); | ||
Eigen::Vector3d getWalkBoundsAccel() const; | ||
Eigen::Vector3d getWalkBoundsGyro() const; | ||
|
||
public: | ||
ReadFunctor<SCStatesMsgPayload> scStateInMsg; /*!< input essage name for spacecraft state */ | ||
|
@@ -73,19 +81,19 @@ class ImuSensor: public SysModel { | |
bool NominalReady; //!< -- Flag indicating that system is in run | ||
Eigen::Matrix3d PMatrixAccel; //!< [-] Cholesky-decomposition or matrix square root of the covariance matrix to apply errors with | ||
Eigen::Matrix3d AMatrixAccel; //!< [-] AMatrix that we use for error propagation | ||
Eigen::Vector3d walkBoundsAccel;//!< [-] "3-sigma" errors to permit for states | ||
Eigen::Vector3d walkBoundsAccel; //!< [-] Total error bounds for accelerometer states. @warning Will be renamed to errorBoundsAccel in December 2025 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mm, this gives the user 1 year to know a change is coming, but not a true depreciation. Can we create the new |
||
Eigen::Vector3d navErrorsAccel; //!< [-] Current navigation errors applied to truth | ||
Eigen::Matrix3d PMatrixGyro; //!< [-] Cholesky-decomposition or matrix square root of the covariance matrix to apply errors with | ||
Eigen::Matrix3d AMatrixGyro; //!< [-] AMatrix that we use for error propagation | ||
Eigen::Vector3d walkBoundsGyro; //!< [-] "3-sigma" errors to permit for states | ||
Eigen::Vector3d walkBoundsGyro; //!< [-] Total error bounds for gyro states. @warning Will be renamed to errorBoundsGyro in December 2025 | ||
Eigen::Vector3d navErrorsGyro; //!< [-] Current navigation errors applied to truth | ||
|
||
IMUSensorMsgPayload trueValues; //!< [-] total measurement without perturbations | ||
IMUSensorMsgPayload sensedValues; //!< [-] total measurement including perturbations | ||
|
||
Eigen::Vector3d accelScale; //!< (-) scale factor for acceleration axes | ||
Eigen::Vector3d gyroScale; //!< (-) scale factors for acceleration axes | ||
|
||
Discretize aDisc; //!< (-) instance of discretization utility for linear acceleration | ||
Discretize oDisc; //!< (-) instance of idscretization utility for angular rate | ||
Saturate aSat; //!< (-) instance of saturate utility for linear acceleration | ||
|
@@ -100,7 +108,7 @@ class ImuSensor: public SysModel { | |
SCStatesMsgPayload StateCurrent; //!< -- Current SSBI-relative state | ||
GaussMarkov errorModelAccel; //!< [-] Gauss-markov error states | ||
GaussMarkov errorModelGyro; //!< [-] Gauss-markov error states | ||
|
||
Eigen::MRPd previous_sigma_BN; //!< -- sigma_BN from the previous spacecraft message | ||
Eigen::MRPd current_sigma_BN; //!< -- sigma_BN from the most recent spacecraft message | ||
Eigen::Vector3d previous_omega_BN_B; //!< -- omega_BN_B from the previous spacecraft message | ||
|
@@ -109,7 +117,7 @@ class ImuSensor: public SysModel { | |
Eigen::Vector3d current_omegaDot_BN_B; //!< -- omegaDot_BN_B from the curret spacecraft message | ||
Eigen::Vector3d previous_TotalAccumDV_BN_B; //!< -- TotalAccumDV_BN_B from the previous spacecraft message | ||
Eigen::Vector3d current_TotalAccumDV_BN_B; //!< -- TotalAccumDV_BN_B from the current spacecraft message | ||
|
||
Eigen::Vector3d accel_SN_P_out; //!< -- rDotDot_SN_P for either next method or output messages | ||
Eigen::Vector3d DV_SN_P_out; //!< -- time step deltaV for either next method or output messages | ||
Eigen::Vector3d omega_PN_P_out; //!< -- omega_PN_P for either next method or output messages | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,23 @@ Magnetometer::Magnetometer() | |
this->senBias.fill(0.0); // Tesla | ||
this->senNoiseStd.fill(-1.0); // Tesla | ||
this->walkBounds.fill(0.0); | ||
this->noiseModel = GaussMarkov(this->numStates); | ||
|
||
// Initialize noise model | ||
this->noiseModel = GaussMarkov(this->numStates, this->RNGSeed); | ||
|
||
// Initialize noise matrices with defaults | ||
Eigen::MatrixXd nMatrix; | ||
nMatrix.resize(3,3); | ||
nMatrix.setZero(); | ||
this->noiseModel.setNoiseMatrix(nMatrix); | ||
|
||
Eigen::MatrixXd pMatrix; | ||
pMatrix.setIdentity(3,3); | ||
this->noiseModel.setPropMatrix(pMatrix); | ||
|
||
this->noiseModel.setUpperBounds(this->walkBounds); | ||
|
||
// Initialize other parameters | ||
this->scaleFactor = 1.0; | ||
this->maxOutput = 1e200; // Tesla | ||
this->minOutput = -1e200; // Tesla | ||
|
@@ -67,10 +83,19 @@ void Magnetometer::Reset(uint64_t CurrentSimNanos) | |
bskLogger.bskLog(BSK_ERROR, "Spacecraft state message name (stateInMsg) is empty."); | ||
} | ||
|
||
// Update noise model parameters | ||
this->noiseModel.setUpperBounds(this->walkBounds); | ||
auto nMatrix = (this->senNoiseStd).asDiagonal(); | ||
|
||
Eigen::MatrixXd nMatrix; | ||
nMatrix.resize(3,3); | ||
nMatrix.setZero(); | ||
nMatrix(0,0) = this->senNoiseStd(0); | ||
nMatrix(1,1) = this->senNoiseStd(1); | ||
nMatrix(2,2) = this->senNoiseStd(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update module RST file on how to set noise values. |
||
this->noiseModel.setNoiseMatrix(nMatrix); | ||
this->noiseModel.setRNGSeed(this->RNGSeed); | ||
|
||
// Set saturation bounds | ||
Eigen::MatrixXd satBounds; | ||
satBounds.resize(this->numStates, 2); | ||
satBounds(0, 0) = this->minOutput; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default we should have have no noise or random walk? Please ensure that signal is not modified unless the users sets these values.