28 #include <mc_rbdyn/rpy_utils.h> 40 orientation_ = X_0_fb.rotation();
41 position_ = X_0_fb.translation();
46 estimateOrientation(realRobot);
47 estimatePosition(realRobot);
50 void FloatingBaseObserver::estimateOrientation(
const mc_rbdyn::Robot & realRobot)
56 sva::PTransformd X_0_rBase = realRobot.posW();
57 sva::PTransformd X_0_rIMU = realRobot.bodyPosW(realRobot.bodySensor().parentBody());
58 sva::PTransformd X_rIMU_rBase = X_0_rBase * X_0_rIMU.inv();
60 Eigen::Matrix3d R_0_cBase = controlRobot_.posW().rotation();
61 Eigen::Matrix3d R_0_mBase = X_rIMU_rBase.rotation() * R_0_mIMU;
62 Eigen::Vector3d cRPY = mc_rbdyn::rpyFromMat(R_0_cBase);
63 Eigen::Vector3d mRPY = mc_rbdyn::rpyFromMat(R_0_mBase);
64 orientation_ = mc_rbdyn::rpyToMat(mRPY(0), mRPY(1), cRPY(2));
67 void FloatingBaseObserver::estimatePosition(
const mc_rbdyn::Robot & realRobot)
71 const sva::PTransformd & X_0_real = realRobot.posW();
72 sva::PTransformd X_real_s = X_0_s * X_0_real.inv();
73 const Eigen::Vector3d & r_c_0 = X_0_c.translation();
74 const Eigen::Vector3d & r_s_real = X_real_s.translation();
75 position_ = r_c_0 - orientation_.transpose() * r_s_real;
80 sva::PTransformd X_0_l = robot.surface(
"LeftFoot").X_0_s(robot);
81 sva::PTransformd X_0_r = robot.surface(
"RightFoot").X_0_s(robot);
82 return sva::interpolate(X_0_r, X_0_l, leftFootRatio_);
87 realRobot.posW(sva::PTransformd{orientation_, position_});
EIGEN_MAKE_ALIGNED_OPERATOR_NEW FloatingBaseObserver(const mc_rbdyn::Robot &controlRobot)
Initialize floating base observer.
void reset(const sva::PTransformd &X_0_fb)
Reset floating base estimate.
void run(const mc_rbdyn::Robot &realRobot)
Update floating-base transform of real robot.
void updateRobot(mc_rbdyn::Robot &robot)
Write observed floating-base transform to the robot's configuration.
sva::PTransformd getAnchorFrame(const mc_rbdyn::Robot &robot)
Get anchor frame of a robot for a given contact state.
const Eigen::Quaterniond & imuOrientation()
Get the orientation of the IMU with respect to the inertial frame.
Main controller namespace.