XBotInterface
2.4.1
XBotInterface provides a generic API to model and control a robot.
|
Go to the documentation of this file.
22 #ifndef __MODEL_INTERFACE_H__
23 #define __MODEL_INTERFACE_H__
29 #include <Eigen/Geometry>
30 #include <kdl/frames.hpp>
31 #include <kdl/jacobian.hpp>
32 #include <eigen_conversions/eigen_kdl.h>
56 typedef std::shared_ptr<ModelInterface>
Ptr;
61 typedef std::shared_ptr<const ModelInterface>
ConstPtr;
170 template <
typename... SyncFlags>
200 template <
typename... SyncFlags>
212 bool update(
bool update_position =
true,
213 bool update_velocity =
true,
214 bool update_desired_acceleration =
true );
329 virtual bool getPose(
const std::string& source_frame,
330 KDL::Frame& pose )
const = 0;
341 bool getPose(
const std::string& source_frame,
342 const std::string& target_frame,
343 KDL::Frame& pose )
const;
354 KDL::Rotation& orientation)
const;
366 const std::string& target_frame,
367 KDL::Rotation& orientation)
const;
379 const KDL::Vector& source_point,
380 KDL::Vector& world_point)
const;
392 const std::string& target_frame,
393 const KDL::Vector& source_point,
394 KDL::Vector& target_point)
const;
404 virtual bool getJacobian(
const std::string& link_name,
405 const KDL::Vector& reference_point,
406 KDL::Jacobian& J)
const = 0;
417 KDL::Jacobian& J)
const;
431 const std::string& target_frame,
432 KDL::Jacobian& J)
const;
454 const std::string& base_link_name,
455 KDL::Jacobian& J)
const;
466 KDL::Twist& velocity)
const = 0;
479 KDL::Twist& velocity)
const;
492 const std::string& target_frame,
493 KDL::Twist& velocity)
const;
504 KDL::Twist& acceleration)
const = 0;
515 KDL::Twist& acceleration)
const = 0;
527 const KDL::Vector& point,
528 KDL::Vector& acceleration)
const = 0;
540 const KDL::Vector& point,
541 KDL::Twist& jdotqdot)
const;
552 const std::string& base_link_name,
553 KDL::Twist& jdotqdot)
const = 0;
561 virtual void getCOM( KDL::Vector& com_position )
const = 0;
570 bool getCOM(
const std::string& reference_frame,
571 KDL::Vector& com_position )
const;
584 virtual void getCOMJacobian( KDL::Jacobian& J, KDL::Vector& dJcomQdot)
const;
647 virtual double getMass()
const = 0;
656 virtual void getGravity( KDL::Vector& gravity )
const = 0;
665 bool getGravity(
const std::string& reference_frame,
666 KDL::Vector& gravity )
const;
673 virtual void setGravity(
const KDL::Vector& gravity ) = 0;
682 bool setGravity(
const std::string& reference_frame,
683 const KDL::Vector& gravity );
790 bool maskJacobian(
const std::string& chain_name, KDL::Jacobian& J)
const;
869 bool getPose(
const std::string& source_frame,
870 const std::string& target_frame,
871 Eigen::Affine3d& pose )
const;
880 bool getPose(
const std::string& source_frame,
881 Eigen::Affine3d& pose )
const;
892 Eigen::Matrix3d& orientation)
const;
903 const std::string& target_frame,
904 Eigen::Matrix3d& orientation)
const;
914 const Eigen::Vector3d& source_point,
915 Eigen::Vector3d& world_point)
const;
927 const std::string& target_frame,
928 const Eigen::Vector3d& source_point,
929 Eigen::Vector3d& target_point)
const;
940 Eigen::MatrixXd& J)
const;
954 const std::string& target_frame,
955 Eigen::MatrixXd& J)
const;
967 const Eigen::Vector3d& reference_point,
968 Eigen::MatrixXd& J)
const;
980 const std::string& base_link_name,
981 Eigen::MatrixXd& J)
const;
989 void getCOM( Eigen::Vector3d& com_position )
const;
998 bool getCOM(
const std::string& reference_frame,
999 Eigen::Vector3d& com_position )
const;
1011 virtual void getCOMJacobian( Eigen::MatrixXd& J, Eigen::Vector3d& dJcomQdot)
const;
1085 const std::string& target_frame,
1086 Eigen::Matrix<double,6,1>& velocity)
const;
1108 const Eigen::Vector3d& point,
1109 Eigen::Vector3d& acceleration)
const;
1121 const Eigen::Vector3d& point,
1133 const std::string& base_link_name,
1142 void getGravity( Eigen::Vector3d& gravity )
const;
1151 bool getGravity(
const std::string& reference_frame,
1152 Eigen::Vector3d& gravity )
const;
1160 void setGravity(
const Eigen::Vector3d& gravity );
1169 bool setGravity(
const std::string& reference_frame,
1170 const Eigen::Vector3d& gravity );
1180 bool maskJacobian(
const std::string& chain_name, Eigen::MatrixXd& J)
const;
1187 virtual int getLinkID(
const std::string& link_name)
const = 0;
1220 bool update_velocity,
1221 bool update_desired_acceleration) = 0;
1223 inline void rotationEigenToKDL(
const Eigen::Matrix3d& eigen_rotation, KDL::Rotation& kdl_rotation)
const;
1224 inline void rotationKDLToEigen(
const KDL::Rotation& kdl_rotation, Eigen::Matrix3d& eigen_rotation)
const;
1235 std::map<std::string, XBot::ModelChain::Ptr> _model_chain_map;
1239 std::map<int, int> _joint_id_to_model_id;
1241 bool fillModelOrderedChain();
1243 mutable KDL::Twist _tmp_kdl_twist;
1244 mutable KDL::Frame _tmp_kdl_frame, _tmp_kdl_frame_1;
1245 mutable KDL::Jacobian _tmp_kdl_jacobian, _tmp_kdl_jacobian_1;
1246 mutable KDL::Vector _tmp_kdl_vector, _tmp_kdl_vector_1;
1247 mutable KDL::Rotation _tmp_kdl_rotation, _tmp_kdl_rotation_1;
1248 mutable std::vector<int> _tmp_int_vector;
1249 mutable std::string _floating_base_link;
1250 mutable Eigen::MatrixXd _tmp_postural_jacob;
1251 mutable Eigen::MatrixXd _tmp_inertia;
1252 mutable Eigen::MatrixXd _tmp_inverse_inertia;
1253 mutable Eigen::VectorXd _tmp_inv_inertia_vec;
1254 mutable Eigen::MatrixXd _tmp_jacobian, _tmp_cmm, _tmp_jacobiandot;
1255 mutable Eigen::MatrixXd _tmp_M;
1256 mutable Eigen::MatrixXd _tmp_I;
1257 mutable Eigen::VectorXd _tmp_gcomp, _tmp_h, _tmp_jstate, _M_col;
1258 mutable Eigen::MatrixXd _tmp_jacobian_relative;
1260 mutable bool _compute_inverse_inertia;
1283 void seekAndDestroyFixedControlledJoints();
1294 for(
int i = 0; i < 3; i++){
1295 for(
int j = 0; j < 3; j++){
1296 kdl_rotation.data[3*i+j] = eigen_rotation(i,j);
1303 for(
int i = 0; i < 3; i++){
1304 for(
int j = 0; j < 3; j++){
1305 eigen_rotation(i,j) = kdl_rotation.data[3*i+j];
1310 template <
typename... SyncFlags>
1314 update(
true,
true,
true);
1322 template <
typename... SyncFlags>
1326 update(
true,
true,
true);
1335 #endif // __MODEL_INTERFACE_H__
virtual int getLinkID(const std::string &link_name) const =0
getLinkID return the link ID
bool setDamping(const Eigen::VectorXd &D)
Sets the XBotInterface internal joint damping according to the provided vector, which must be ordered...
Definition: XBotInterface.cpp:1008
int getActuatedJointNum() const
Gets the number of actuated joints in the model, i.e.
Definition: ModelInterface.cpp:874
virtual bool getPose(const std::string &source_frame, KDL::Frame &pose) const =0
Computes the pose of the source_frame w.r.t.
Definition: ConfigOptions.h:36
bool getJointEffort(Eigen::VectorXd &tau) const
Gets the robot joint efforts as an Eigen vector.
Definition: XBotInterface.cpp:740
void rotationEigenToKDL(const Eigen::Matrix3d &eigen_rotation, KDL::Rotation &kdl_rotation) const
Definition: ModelInterface.h:1292
bool getEffortReference(Eigen::VectorXd &tau) const
Gets the robot effort references as an Eigen vector.
Definition: XBotInterface.cpp:751
bool getMotorPosition(Eigen::VectorXd &q) const
Gets the robot motor positions as an Eigen vector.
Definition: XBotInterface.cpp:786
virtual void getModelOrderedJoints(std::vector< std::string > &joint_name) const =0
Gets a vector with the joint names ordered according to the model.
bool getJointPosition(Eigen::VectorXd &q) const
Gets the robot joint positions as an Eigen vector.
Definition: XBotInterface.cpp:348
std::shared_ptr< ModelInterface > Ptr
Shared pointer to a ModelInterface.
Definition: ModelInterface.h:56
std::map< std::string, XBot::KinematicChain::Ptr > _chain_map
Definition: XBotInterface.h:1382
virtual bool update_internal(bool update_position, bool update_velocity, bool update_desired_acceleration)=0
bool getMotorVelocity(Eigen::VectorXd &qdot) const
Gets the robot motor velocities as an Eigen vector.
Definition: XBotInterface.cpp:797
bool getFloatingBaseTwist(KDL::Twist &floating_base_twist) const
Gets the floating base twist w.r.t.
Definition: ModelInterface.cpp:918
virtual void computeGravityCompensation(Eigen::VectorXd &g) const =0
Computes gravity compensation torques.
ModelChain & operator()(const std::string &chain_name)
Returns a handle to the kinematic chain named chain_name.
Definition: ModelInterface.cpp:234
bool setJointPosition(const Eigen::VectorXd &q)
Sets the XBotInterface internal joint positions according to the provided vector, which must be order...
Definition: XBotInterface.cpp:1050
static ModelInterface::Ptr getModel(const ConfigOptions &config)
Factory method for generating instances of the ModelInterface class according to the provided configu...
Definition: ModelInterface.cpp:39
ModelInterface & operator=(const ModelInterface &other)=delete
bool setFloatingBaseOrientation(const KDL::Rotation &world_R_floating_base)
Sets the floating base orientation w.r.t.
Definition: ModelInterface.cpp:983
bool getTemperature(Eigen::VectorXd &temp) const
Gets the robot joint temperatures as an Eigen vector.
Definition: XBotInterface.cpp:819
std::vector< std::string > _ordered_chain_names
Definition: XBotInterface.h:1391
bool setStiffness(const Eigen::VectorXd &K)
Sets the XBotInterface internal joint stiffness according to the provided vector, which must be order...
Definition: XBotInterface.cpp:1135
virtual void getInertiaInverseTimesMatrix(const Eigen::MatrixXd &Mat, Eigen::MatrixXd &Minv_Mat) const
getInertiaInverseTimesMatrix Computes the inverse of the Inertia Matrix times a given matrix
Definition: ModelInterface.cpp:1059
bool setMotorPosition(const Eigen::VectorXd &q)
Sets the XBotInterface internal motor positions according to the provided vector, which must be order...
Definition: XBotInterface.cpp:1093
virtual bool getJacobian(const std::string &link_name, const KDL::Vector &reference_point, KDL::Jacobian &J) const =0
Gets the Jacobian of link_name expressed in the world frame, i.e a matrix such that its product with ...
bool sync(const XBotInterface &other, SyncFlags... flags)
Synchronize the current XBotInterface with another XBotInterface object: only the common chains will ...
Definition: XBotInterface.h:1421
bool setFloatingBaseState(const KDL::Frame &pose, const KDL::Twist &twist)
Sets the floating base pose and twist w.r.t.
Definition: ModelInterface.cpp:1121
bool getDamping(Eigen::VectorXd &D) const
Gets the robot damping as an Eigen vector.
Definition: XBotInterface.cpp:729
virtual void getCOMJacobian(KDL::Jacobian &J, KDL::Vector &dJcomQdot) const
Gets the COM Jacobian expressed in the world frame and the d(Jcom)/dt * qdot term,...
Definition: ModelInterface.cpp:1042
bool getVelocityReference(Eigen::VectorXd &qdot) const
Gets the robot velocity references as an Eigen vector.
Definition: XBotInterface.cpp:830
Eigen::Matrix< double, 6, 1 > Vector6d
Typedef for a 6 element column vector of double.
Definition: TypedefAndEnums.h:132
virtual void getCOMVelocity(KDL::Vector &velocity) const =0
Gets the COM velocity expressed in the world frame.
bool setJointVelocity(const Eigen::VectorXd &qdot)
Sets the XBotInterface internal joint velocities according to the provided vector,...
Definition: XBotInterface.cpp:1064
bool syncFrom(const XBotInterface &other, SyncFlags... flags)
Synchronizes the internal model state to the one of the XBotInterface given as an argument.
Definition: ModelInterface.h:1311
bool getJointSelectionMatrix(const std::string &joint_name, Eigen::RowVectorXd &S) const
Gets a selection matrix for the requested joint, i.e.
Definition: ModelInterface.cpp:778
bool getFloatingBasePose(KDL::Frame &floating_base_pose) const
Gets the floating base pose w.r.t.
Definition: ModelInterface.cpp:909
virtual bool init_model(const ConfigOptions &config)=0
void getPosturalJacobian(Eigen::MatrixXd &J) const
Gets the Jacacobian matrix corresponding to a joint-space postural task, i.e.
Definition: ModelInterface.cpp:861
const std::map< std::string, XBot::KinematicChain::Ptr > & getChainMap() const
Getter for the chain map inside the XBotInterface.
Definition: XBotInterface.cpp:1389
virtual bool getVelocityTwist(const std::string &link_name, KDL::Twist &velocity) const =0
Gets the velocity twist of link_name (first linear, then angular velocity).
std::shared_ptr< const ModelInterface > ConstPtr
Shared pointer to const ModelInterface.
Definition: ModelInterface.h:61
bool setJointEffort(const Eigen::VectorXd &tau)
Sets the XBotInterface internal joint efforts according to the provided vector, which must be ordered...
Definition: XBotInterface.cpp:1022
virtual void getGravity(KDL::Vector &gravity) const =0
Gets the gravity vector expressed in the world frame.
bool getPointPosition(const std::string &source_frame, const KDL::Vector &source_point, KDL::Vector &world_point) const
Gets the position in world coordinates for a source_point expressed w.r.t.
Definition: ModelInterface.cpp:560
virtual void computeInverseDynamics(Eigen::VectorXd &tau) const =0
Computes inverse dynamics.
bool getChainSelectionMatrix(const std::string &chain_name, Eigen::MatrixXd &S) const
Gets a selection matrix for the requested chain, i.e.
Definition: ModelInterface.cpp:750
virtual bool getFloatingBaseLink(std::string &floating_base_link) const =0
Gets the name of the floating base link.
bool setJointAcceleration(const Eigen::VectorXd &qddot)
Sets the XBotInterface internal joint accelerations according to the provided vector,...
Definition: XBotInterface.cpp:1078
virtual bool getRelativeAccelerationTwist(const std::string &link_name, const std::string &base_link_name, KDL::Twist &acceleration) const =0
getRelativeAccelerationTwist compute the relative acceleration of body "link" wrt body "base_link" ex...
virtual void setGravity(const KDL::Vector &gravity)=0
Sets the gravity vector expressed in the world frame.
virtual void getInertiaInverse(Eigen::MatrixXd &Minv) const
getInertiaInverse compute the inverse of the Inertia Matrix
Definition: ModelInterface.cpp:1073
virtual void getCOMAcceleration(KDL::Vector &acceleration) const =0
Gets the COM acceleration expressed in the world frame.
virtual bool getAccelerationTwist(const std::string &link_name, KDL::Twist &acceleration) const =0
Gets the acceleration twist of link_name (first linear, then angular acceleration).
bool _is_floating_base
Definition: ModelInterface.h:1226
ModelInterface is an abstraction layer for a kinematic/dynamic model of a robot.
Definition: ModelInterface.h:46
virtual void getCentroidalMomentumMatrix(Eigen::MatrixXd ¢roidal_momentum_matrix, Eigen::Vector6d &CMMdotQdot) const
Gets the robot centroidal momentum matrix, i.e.
Definition: ModelInterface.cpp:1001
bool getJointVelocity(Eigen::VectorXd &qdot) const
Gets the robot joint velocities as an Eigen vector.
Definition: XBotInterface.cpp:762
virtual double getMass() const =0
Gets the weight of the robot.
virtual bool computeJdotQdot(const std::string &link_name, const KDL::Vector &point, KDL::Twist &jdotqdot) const
Computed the product of the link_name jacobian time derivative by the joint velocity vector.
Definition: ModelInterface.cpp:707
virtual bool setFloatingBasePose(const KDL::Frame &floating_base_pose)=0
Sets the floating base pose w.r.t.
bool setFloatingBaseAngularVelocity(const KDL::Vector &floating_base_omega)
Sets the floating base angular velocity w.r.t.
Definition: ModelInterface.cpp:958
std::vector< Joint::Ptr > _ordered_joint_vector
Definition: XBotInterface.h:1383
bool syncFrom_no_update(const XBotInterface &other, SyncFlags... flags)
Synchronizes the internal model state to the one of the XBotInterface given as an argument.
Definition: ModelInterface.h:1323
virtual void getInertiaMatrix(Eigen::MatrixXd &M) const =0
Gets the joint space inertia matrix of the robot.
void rotationKDLToEigen(const KDL::Rotation &kdl_rotation, Eigen::Matrix3d &eigen_rotation) const
Definition: ModelInterface.h:1301
bool setPositionReference(const Eigen::VectorXd &q)
Sets the XBotInterface internal joint position references according to the provided vector,...
Definition: XBotInterface.cpp:1121
std::shared_ptr< const AnyMap > AnyMapConstPtr
Shared pointer to AnyMap.
Definition: TypedefAndEnums.h:84
Definition: RobotInterface.h:36
bool getRelativeVelocityTwist(const std::string &link_name, const std::string &base_link_name, KDL::Twist &velocity) const
Gets the velocity twist of link_name (first linear, then angular velocity) w.r.t.
Definition: ModelInterface.cpp:404
virtual bool init_internal(const ConfigOptions &config)
Definition: ModelInterface.cpp:75
bool getStiffness(Eigen::VectorXd &K) const
Gets the robot stiffness as an Eigen vector.
Definition: XBotInterface.cpp:808
bool setVelocityReference(const Eigen::VectorXd &qdot)
Sets the XBotInterface internal joint velocity references according to the provided vector,...
Definition: XBotInterface.cpp:1163
Kinematic chain useful for a model abstraction.
Definition: ModelChain.h:34
ModelChain & leg(int leg_id)
Returns a handle to the kinematic chain corresponding to the leg n° leg_id.
Definition: ModelInterface.cpp:224
virtual bool computeRelativeJdotQdot(const std::string &target_link_name, const std::string &base_link_name, KDL::Twist &jdotqdot) const =0
computeRelativeJdotQdot return the relative acceleration component between "target_link" and "base_li...
bool getOrientation(const std::string &source_frame, KDL::Rotation &orientation) const
Computes the orientation of the source_frame w.r.t.
Definition: ModelInterface.cpp:495
virtual void getInertiaInverseTimesVector(const Eigen::VectorXd &vec, Eigen::VectorXd &minv_vec) const
getInertiaInverseTimesVector Computes the inverse of the Inertia Matrix times a given vector
Definition: ModelInterface.cpp:1052
virtual void getCentroidalMomentum(Eigen::Vector6d ¢roidal_momentum) const =0
Gets the robot centroidal momentum matrix, i.e.
bool getJointAcceleration(Eigen::VectorXd &qddot) const
Gets the robot joint accelerations as an Eigen vector.
Definition: XBotInterface.cpp:773
virtual void computeNonlinearTerm(Eigen::VectorXd &n) const =0
Computes the non-linear torque term without the contribution from gravity, i.e.
bool update(bool update_position=true, bool update_velocity=true, bool update_desired_acceleration=true)
Updates the kinematic variables of the model according to the current state of the model.
Definition: ModelInterface.cpp:115
bool computeConstrainedInverseDynamics(const Eigen::MatrixXd &J, const Eigen::VectorXd &weights, Eigen::VectorXd &tau) const
Computes inverse dynamics for a constrained system.
Definition: ModelInterface.cpp:816
bool getPositionReference(Eigen::VectorXd &q) const
Gets the robot position references as an Eigen vector.
Definition: XBotInterface.cpp:418
bool setTemperature(const Eigen::VectorXd &temp)
Sets the XBotInterface internal joint temperatures according to the provided vector,...
Definition: XBotInterface.cpp:1149
bool maskJacobian(const std::string &chain_name, KDL::Jacobian &J) const
Applies a mask corresponding to the specified chain to the jacobian provided as an argument.
Definition: ModelInterface.cpp:810
bool setMotorVelocity(const Eigen::VectorXd &qdot)
Sets the XBotInterface internal motor velocities according to the provided vector,...
Definition: XBotInterface.cpp:1107
ModelChain & arm(int arm_id)
Returns a handle to the kinematic chain corresponding to the arm n° arm_id.
Definition: ModelInterface.cpp:214
bool setEffortReference(const Eigen::VectorXd &tau)
Sets the XBotInterface internal joint effort references according to the provided vector,...
Definition: XBotInterface.cpp:1036
std::shared_ptr< const ImuSensor > ConstPtr
Definition: ImuSensor.h:33
virtual bool getRelativeJacobian(const std::string &target_link_name, const std::string &base_link_name, KDL::Jacobian &J) const
Gets the relative Jacobian of target_link_name w.r.t to base_link_name.
Definition: ModelInterface.cpp:369
ModelChain & chain(const std::string &chain_name)
Returns a handle to the kinematic chain named chain_name.
Definition: ModelInterface.cpp:243
Definition: IXBotModel.h:20
bool isFloatingBase() const
True if the robot is floating base, false if it has a fixed base.
Definition: ModelInterface.cpp:34
virtual bool setFloatingBaseTwist(const KDL::Twist &floating_base_twist)=0
Sets the floating base twist w.r.t.
virtual bool getPointAcceleration(const std::string &link_name, const KDL::Vector &point, KDL::Vector &acceleration) const =0
Gets the acceleration of a given point which is solidal with the given link.
Definition: XBotInterface.h:41
virtual void getCOM(KDL::Vector &com_position) const =0
Gets the COM position vector w.r.t.