Skip to content
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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
42 changes: 35 additions & 7 deletions src/simulation/sensors/starTracker/starTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ StarTracker::StarTracker()
{
this->sensorTimeTag = 0;
m33SetIdentity(RECAST3X3 this->dcm_CB);

// Initialize noise model
this->errorModel = GaussMarkov(3, this->RNGSeed);

// Initialize matrices
this->PMatrix.resize(3, 3);
this->AMatrix.resize(3, 3);
this->walkBounds.resize(3);

this->PMatrix.fill(0.0);
this->AMatrix.fill(0.0);
this->AMatrix.setIdentity(3, 3);
this->walkBounds.fill(0.0);
return;
}
Expand All @@ -50,20 +58,17 @@ void StarTracker::Reset(uint64_t CurrentSimNanos)
bskLogger.bskLog(BSK_ERROR, "starTracker.scStateInMsg was not linked.");
}

int numStates = 3;

this->AMatrix.setIdentity(numStates, numStates);

//! - Alert the user if the noise matrix was not the right size. That'd be bad.
if(this->PMatrix.size() != numStates*numStates)
if(this->PMatrix.size() != 9)
{
bskLogger.bskLog(BSK_ERROR, "Your process noise matrix (PMatrix) is not 3*3. Quitting.");
return;
}
if(this->walkBounds.size() != numStates){
if(this->walkBounds.size() != 3){
bskLogger.bskLog(BSK_ERROR, "Your walkbounds is not size 3. Quitting");
return;
}

this->errorModel.setNoiseMatrix(this->PMatrix);
this->errorModel.setRNGSeed(this->RNGSeed);
this->errorModel.setUpperBounds(this->walkBounds);
Expand Down Expand Up @@ -142,3 +147,26 @@ void StarTracker::UpdateState(uint64_t CurrentSimNanos)
this->applySensorErrors();
this->writeOutputMessages(CurrentSimNanos);
}

/*!
Setter for `AMatrix` used for error propagation
@param propMatrix Matrix to set
*/
void StarTracker::setAMatrix(const Eigen::MatrixXd& propMatrix)
{
if(propMatrix.rows() != 3 || propMatrix.cols() != 3) {
bskLogger.bskLog(BSK_ERROR, "StarTracker: Propagation matrix must be 3x3");
return;
}
this->AMatrix = propMatrix;
this->errorModel.setPropMatrix(propMatrix);
}

/*!
Getter for `AMatrix` used for error propagation
@return Current matrix
*/
Eigen::MatrixXd StarTracker::getAMatrix() const
{
return this->AMatrix;
}
9 changes: 6 additions & 3 deletions src/simulation/sensors/starTracker/starTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class StarTracker: public SysModel {
public:
StarTracker();
~StarTracker();

void UpdateState(uint64_t CurrentSimNanos);
void Reset(uint64_t CurrentClock); //!< Method for reseting the module
void readInputMessages();
Expand All @@ -47,9 +47,12 @@ class StarTracker: public SysModel {
void applySensorErrors();
void computeTrueOutput();
void computeQuaternion(double *sigma, STSensorMsgPayload *sensorValue);


void setAMatrix(const Eigen::MatrixXd& propMatrix);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have a getAMatrix()?

Eigen::MatrixXd getAMatrix() const;

public:

uint64_t sensorTimeTag; //!< [ns] Current time tag for sensor out
ReadFunctor<SCStatesMsgPayload> scStateInMsg; //!< [-] sc input state message
Message<STSensorMsgPayload> sensorOutMsg; //!< [-] sensor output state message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update starTracker.rst as well to discuss how to set the noise values.

Expand Down