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

[attitudeObserver] Add gyro-bias management #17

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const auto & X_Camera_Object = datastore().call<const sva::PTransformd &>(name_+
## Dependencies

- [gram_savitzky_golay](https://github.com/arntanguy/gram_savitzky_golay)
- [state-observation](https://github.com/jrl-umi3218/state-observation) > 1.3.3
- [state-observation](https://github.com/jrl-umi3218/state-observation) > 1.4.1
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make this a version requirement in cmake find_package.
While trying this PR locally, I didn't update the state-observation package. Viciously, this builds, but the estimation is nonsense (with the stabilizer just standing, the robot estimate leans backwards and the robot falls forward). I assume this is because of an index mismatch.

Enforcing the minimal version of state-observation would prevent such subtle errors.

- [mc_rtc](https://github.com/jrl-umi3218/mc_rtc)
- Eigen3
- Boost
41 changes: 32 additions & 9 deletions include/mc_state_observation/AttitudeObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace mc_state_observation
struct AttitudeObserver : public mc_observers::Observer
{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
using indexes = stateObservation::kine::indexes<stateObservation::kine::rotationVector>;
using indexes = stateObservation::IMUDynamicalSystem::indexes;

public:
public:
AttitudeObserver(const std::string & type, double dt);

void configure(const mc_control::MCController & ctl, const mc_rtc::Configuration &) override;
Expand All @@ -32,7 +32,10 @@ struct AttitudeObserver : public mc_observers::Observer
double gyroCovariance = 1e-10;
double orientationAccCov = 0.003;
double linearAccCov = 1e-13;
double biasDriftCov = 1e-10;
double biasInitCov = 1e-7;
double stateCov = 3e-14;
double oriCov = 1e-12;
double stateInitCov = 1e-8;
Comment on lines 32 to 39
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not directly related to this PR, but I found a bug in gui_helpers (dangling reference making the GUI for these parameters meaningless), fixed by 0fd1bb4. You'll need to rebase to fix the GUI.

Eigen::Matrix3d offset = Eigen::Matrix3d::Identity(); ///< Offset to apply to the estimation result
void addToLogger(mc_rtc::Logger & logger, const std::string & category);
Expand Down Expand Up @@ -62,6 +65,11 @@ struct AttitudeObserver : public mc_observers::Observer
mc_rtc::gui::StateBuilder &,
const std::vector<std::string> & /* category */) override;

void switchWithGyroBias(bool);

void setGyroBiasToMeanValue(); /// set the value of the bias to the mean identified value
void startGyroBiasIdentification(); /// start the identification of the bias from the curren gyro readings
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
void startGyroBiasIdentification(); /// start the identification of the bias from the curren gyro readings
void startGyroBiasIdentification(); /// start the identification of the bias from the current gyro readings


protected:
/// @{
std::string robot_ = ""; ///< Name of robot to which the IMU sensor belongs
Expand All @@ -72,12 +80,14 @@ struct AttitudeObserver : public mc_observers::Observer
KalmanFilterConfig config_; ///< Current configuration for the KF (GUI, etc...)
bool log_kf_ = false; ///< Whether to log the parameters of the kalman filter
bool initFromControl_ = true; ///< Whether to initialize from the control state
/// @}
bool withGyroBias_ = false; ///< Whether the estimator will be considering gyro bias

/// Sizes of the states for the state, the measurement, and the input vector
static constexpr unsigned STATE_SIZE = 18;
static constexpr unsigned MEASUREMENT_SIZE = 6;
static constexpr unsigned INPUT_SIZE = 6;
static constexpr stateObservation::Index STATE_SIZE_BASE = 18;
static constexpr stateObservation::Index MEASUREMENT_SIZE = 6;
static constexpr stateObservation::Index INPUT_SIZE = 6;

stateObservation::Index stateSize_ = STATE_SIZE_BASE;

double lastStateInitCovariance_;

Expand All @@ -93,12 +103,23 @@ struct AttitudeObserver : public mc_observers::Observer
stateObservation::Vector uk_;
stateObservation::Vector xk_;

stateObservation::Matrix3 Kpt_, Kdt_;
stateObservation::Matrix3 Kpo_, Kdo_;
stateObservation::Matrix3 Kpt_, Kdt_, Kat_;
stateObservation::Matrix3 Kpo_, Kdo_, Kao_;

Eigen::Matrix3d m_orientation = Eigen::Matrix3d::Identity(); ///< Result
};
Eigen::Vector3d m_gyrobias = Eigen::Vector3d::Zero();
Eigen::Vector3d m_gyroMeasurementTotal =
Eigen::Vector3d::Zero(); /// the sum of values of gyro measurements (used to compute the mean value)
unsigned m_numberOfValues = 0;

bool m_resetGUI = false;
std::vector<std::string> m_category;

bool m_gyroBiasFromMeasurement_running = false; /// sets if the identification of the gyro bias is stoped

Eigen::Vector3d m_accIn = Eigen::Vector3d::Zero();
Eigen::Vector3d m_rateIn = Eigen::Vector3d::Zero();
};

} // namespace mc_state_observation

Expand All @@ -116,6 +137,7 @@ struct ConfigurationLoader<mc_state_observation::AttitudeObserver::KalmanFilterC
config("gyr_cov", c.gyroCovariance);
config("ori_acc_cov", c.orientationAccCov);
config("lin_acc_cov", c.linearAccCov);
config("bias_drift_cov", c.biasDriftCov);
config("state_cov", c.stateCov);
config("state_init_cov", c.stateInitCov);
return c;
Expand All @@ -128,6 +150,7 @@ struct ConfigurationLoader<mc_state_observation::AttitudeObserver::KalmanFilterC
config.add("acc_cov", c.acceleroCovariance);
config.add("gyr_cov", c.gyroCovariance);
config.add("ori_acc_cov", c.orientationAccCov);
config.add("bias_drift_cov", c.biasDriftCov);
config.add("lin_acc_cov", c.linearAccCov);
config.add("state_cov", c.stateCov);
config.add("state_init_cov", c.stateInitCov);
Expand Down
7 changes: 7 additions & 0 deletions include/mc_state_observation/gui_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ auto make_number_input(std::string name, T & value)
return NumberInputImpl<decltype(GetF), decltype(SetF)>(name, GetF, SetF);
}

auto make_xyz_input(std::string name, Eigen::Vector3d & vec)
{
auto GetF = [&vec]() -> Eigen::Vector3d { return vec; };
auto SetF = [&vec](const Eigen::Vector3d & vecIn) { vec = vecIn; };
return ArrayInputImpl<decltype(GetF), decltype(SetF)>(name, {"x", "y", "z"}, GetF, SetF);
}

auto make_rpy_input(std::string name, Eigen::Matrix3d & orientation)
{
auto GetF = [&orientation]() -> Eigen::Vector3d
Expand Down
Loading