XBotInterface
2.4.1
XBotInterface provides a generic API to model and control a robot.
|
Go to the documentation of this file.
20 #ifndef __I_XBOT_INTERFACE_H__
21 #define __I_XBOT_INTERFACE_H__
28 #include <yaml-cpp/yaml.h>
30 #include <matlogger2/matlogger2.h>
46 typedef std::shared_ptr<XBotInterface>
Ptr;
47 typedef std::shared_ptr<const XBotInterface>
ConstPtr;
56 bool init (
const std::string& path_to_cfg);
83 const urdf::ModelInterface&
getUrdf()
const;
97 const srdf_advr::Model&
getSrdf()
const;
133 bool getRobotState (
const std::string& state_name, Eigen::VectorXd& q )
const;
170 bool hasChain (
const std::string& chain_name )
const;
213 bool hasJoint (
const std::string& joint_name )
const;
222 bool hasJoint (
int joint_id )
const;
272 int getDofIndex (
const std::string& joint_name )
const;
291 bool getDofIndex (
const std::string& chain_name, std::vector<int>& ids )
const;
304 void initLog(MatLogger2::Ptr logger,
int buffer_size = -1,
int interleave = 1, std::string prefix =
"");
314 void log(MatLogger2::Ptr logger,
double timestamp,
const std::string& prefix =
"")
const;
326 std::map< std::string, ForceTorqueSensor::ConstPtr >
getForceTorque()
const;
356 std::map< std::string, ImuSensor::ConstPtr >
getImu();
386 std::map< std::string, Hand::Ptr >
getHand();
1089 bool setDamping (
const Eigen::VectorXd& D );
1202 void getJointLimits ( Eigen::VectorXd& q_min, Eigen::VectorXd& q_max )
const;
1229 std::vector<std::string>& violating_joints )
const;
1240 std::vector<std::string>& violating_joints )
const;
1251 std::vector<std::string>& violating_joints )
const;
1325 template <
typename... SyncFlags>
1333 const std::map<std::string, XBot::KinematicChain::Ptr>&
getChainMap()
const;
1364 const std::map<std::string, ImuSensor::Ptr>&
getImuInternal()
const;
1385 std::map<std::string, ForceTorqueSensor::Ptr>
_ft_map;
1400 mutable Eigen::VectorXd _qlink, _qmot, _qdotlink, _qdotmot, _tau, _stiffness, _damping, _temp;
1402 std::string _urdf_string, _srdf_string, _joint_map_string;
1403 std::string _urdf_path;
1404 std::string _srdf_path;
1405 std::string _joint_map_config;
1409 std::vector<std::string> _ordered_joint_name;
1410 std::vector<int> _ordered_joint_id;
1412 std::string _path_to_cfg;
1414 MatLogger2::Ptr _matlogger;
1420 template <
typename... SyncFlags>
1423 bool success =
true;
1427 const std::string &chain_name = c.first;
1429 if ( _chain_map.count ( chain_name ) ) {
1430 _chain_map.at ( chain_name )->
syncFrom ( chain, flags... );
1440 for(
const auto& pair : other.
_ft_map){
1441 auto it = _ft_map.find(pair.first);
1442 if(it != _ft_map.end()){
1443 *(it->second) = *(pair.second);
1446 std::cerr <<
"ERROR in " << __func__ <<
"! Unable to find FT \"" << pair.first <<
" inside this interface!" << std::endl;
1454 for(
const auto& pair : other.
_imu_map){
1455 auto it = _imu_map.find(pair.first);
1456 if(it != _imu_map.end()){
1457 *(it->second) = *(pair.second);
1460 std::cerr <<
"ERROR in " << __func__ <<
"! Unable to find IMU \"" << pair.first <<
" inside this interface!" << std::endl;
1473 #endif // __I_XBOT_INTERFACE_H__
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
bool mapToEigen(const JointNameMap &map, Eigen::VectorXd &vector) const
Converts a state vector for an arbitrary subset of the robot state (specified as a JointNameMap) to i...
Definition: XBotInterface.cpp:1882
std::map< std::string, ForceTorqueSensor::ConstPtr > getForceTorque() const
Getter for the force-torque sensor map pertaining to the whole robot.
Definition: XBotInterface.cpp:1618
Kinematic chain abstraction as a set of joints and sensors.
Definition: KinematicChain.h:49
Definition: ConfigOptions.h:36
bool getJointEffort(Eigen::VectorXd &tau) const
Gets the robot joint efforts as an Eigen vector.
Definition: XBotInterface.cpp:740
std::ostream & operator<<(std::ostream &os, const XBot::Joint &j)
ostream operator << for a Joint object
Definition: Joint.cpp:322
void initLog(MatLogger2::Ptr logger, int buffer_size=-1, int interleave=1, std::string prefix="")
Pre-allocates memory for logging the robot state to a mat file.
Definition: XBotInterface.cpp:2053
bool getEffortReference(Eigen::VectorXd &tau) const
Gets the robot effort references as an Eigen vector.
Definition: XBotInterface.cpp:751
std::vector< std::string > getChainNames() const
Return a vector of available chain names as strings.
Definition: XBotInterface.cpp:1380
bool getMotorPosition(Eigen::VectorXd &q) const
Gets the robot motor positions as an Eigen vector.
Definition: XBotInterface.cpp:786
bool getJointPosition(Eigen::VectorXd &q) const
Gets the robot joint positions as an Eigen vector.
Definition: XBotInterface.cpp:348
Definition: SyncFlags.h:83
bool checkVelocityLimits(const Eigen::VectorXd &qdot, std::vector< std::string > &violating_joints) const
Check the input joint velocity vector against joint limits.
Definition: XBotInterface.cpp:1519
std::map< std::string, XBot::KinematicChain::Ptr > _chain_map
Definition: XBotInterface.h:1382
std::unordered_map< int, double > JointIdMap
std::map with key representing the joint ID (i.e.
Definition: TypedefAndEnums.h:33
bool getMotorVelocity(Eigen::VectorXd &qdot) const
Gets the robot motor velocities as an Eigen vector.
Definition: XBotInterface.cpp:797
Joint::Ptr getJointByNameInternal(const std::string &joint_name) const
Definition: XBotInterface.cpp:1999
const std::vector< int > & getEnabledJointId() const
Returns a vector of enabled joint IDs.
Definition: XBotInterface.cpp:1697
const std::string & getPathToConfig() const
Gets the path to the YAML config file used to build the XBotInterface.
Definition: XBotInterface.cpp:117
bool checkJointLimits(const Eigen::VectorXd &q, std::vector< std::string > &violating_joints) const
Check the input joint position vector against joint limits.
Definition: XBotInterface.cpp:1490
const std::map< std::string, ForceTorqueSensor::Ptr > & getForceTorqueInternal() const
Definition: XBotInterface.cpp:1630
int legs() const
Returns the number of legs defined inside the interface.
Definition: XBotInterface.cpp:279
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
std::map< int, ImuSensor::Ptr > _imu_id_map
Definition: XBotInterface.h:1388
std::map< std::string, ForceTorqueSensor::Ptr > _ft_map
Definition: XBotInterface.h:1385
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
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
bool sync(const XBotInterface &other, SyncFlags... flags)
Synchronize the current XBotInterface with another XBotInterface object: only the common chains will ...
Definition: XBotInterface.h:1421
std::map< std::string, ImuSensor::Ptr > _imu_map
Definition: XBotInterface.h:1387
std::shared_ptr< const ForceTorqueSensor > ConstPtr
Definition: ForceTorqueSensor.h:46
const srdf_advr::Model & getSrdf() const
Getter fot the robot SRDF model corresponding to the SRDF xml file specified in the YAML config file.
Definition: XBotInterface.cpp:1395
void getJointLimits(Eigen::VectorXd &q_min, Eigen::VectorXd &q_max) const
Gets a vector of the robot joint limits, as specified in the URDF file.
Definition: XBotInterface.cpp:1551
virtual bool post_init()
Definition: XBotInterface.h:1372
int getDofIndex(const std::string &joint_name) const
Gets the Eigen ID of the joint with name "joint_name".
Definition: XBotInterface.cpp:252
std::map< int, int > _joint_id_to_eigen_id
Definition: XBotInterface.h:1393
const std::string & getSrdfString() const
Returns the robot SRDF xml as a string.
Definition: XBotInterface.cpp:1400
std::unordered_map< std::string, double > JointNameMap
std::map with key representing the joint human-readable name and value representing a joint state (e....
Definition: TypedefAndEnums.h:51
const std::string & getUrdfPath() const
getUrdfPath Getter for the path to the URDF model
Definition: XBotInterface.cpp:1916
bool getDamping(Eigen::VectorXd &D) const
Gets the robot damping as an Eigen vector.
Definition: XBotInterface.cpp:729
std::map< std::string, Hand::Ptr > _hand_map
Definition: XBotInterface.h:1389
Joint::Ptr getJointByIdInternal(int joint_id) const
Definition: XBotInterface.cpp:2036
bool getVelocityReference(Eigen::VectorXd &qdot) const
Gets the robot velocity references as an Eigen vector.
Definition: XBotInterface.cpp:830
const ConfigOptions & getConfigOptions() const
Gets the configuration struct that has been used to build the XBotInterface.
Definition: XBotInterface.cpp:111
std::shared_ptr< Hand > Ptr
Definition: Hand.h:40
friend std::ostream & operator<<(std::ostream &os, const XBot::XBotInterface &robot)
std::shared_ptr< Joint > Ptr
Definition: Joint.h:53
bool setJointVelocity(const Eigen::VectorXd &qdot)
Sets the XBotInterface internal joint velocities according to the provided vector,...
Definition: XBotInterface.cpp:1064
std::map< int, ForceTorqueSensor::Ptr > _ft_id_map
Definition: XBotInterface.h:1386
int getJointNum() const
Getter for the number of enabled joints.
Definition: XBotInterface.cpp:95
std::vector< Joint::Ptr > _joint_vector
Definition: XBotInterface.h:1384
const std::map< std::string, XBot::KinematicChain::Ptr > & getChainMap() const
Getter for the chain map inside the XBotInterface.
Definition: XBotInterface.cpp:1389
bool checkEffortLimits(const Eigen::VectorXd &tau, std::vector< std::string > &violating_joints) const
Check the input joint effort vector against joint limits.
Definition: XBotInterface.cpp:1461
std::shared_ptr< const Joint > ConstPtr
Definition: Joint.h:54
bool ft_flag() const
Definition: SyncFlags.h:130
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
std::map< std::string, int > _joint_name_to_eigen_id
Definition: XBotInterface.h:1394
std::shared_ptr< const XBotInterface > ConstPtr
Definition: XBotInterface.h:47
void log(MatLogger2::Ptr logger, double timestamp, const std::string &prefix="") const
Logs the current robot state.
Definition: XBotInterface.cpp:2119
bool setJointAcceleration(const Eigen::VectorXd &qddot)
Sets the XBotInterface internal joint accelerations according to the provided vector,...
Definition: XBotInterface.cpp:1078
bool syncFrom(const KinematicChain &other, SyncFlags... flags)
Synchronize the current KinematicChain with another KinematicChain object.
Definition: KinematicChain.h:734
bool enforceJointLimits(JointIdMap &q) const
Modifies the input joint position map by enforcing joint limits.
Definition: XBotInterface.cpp:1973
bool enforceVelocityLimit(Eigen::VectorXd &qdot) const
Modifies the input joint velcoity vector by enforcing joint limits.
Definition: XBotInterface.cpp:1983
int arms() const
Returns the number of arms defined inside the interface.
Definition: XBotInterface.cpp:285
bool getJointVelocity(Eigen::VectorXd &qdot) const
Gets the robot joint velocities as an Eigen vector.
Definition: XBotInterface.cpp:762
void printTracking() const
Print a pretty table about the robot tracking.
Definition: XBotInterface.cpp:1909
bool hasChain(const std::string &chain_name) const
A method for determining if a chain with name "chain_name" is defined inside the interface.
Definition: XBotInterface.cpp:106
Definition: XBotCoreModel.h:40
std::shared_ptr< XBotInterface > Ptr
Definition: XBotInterface.h:46
virtual bool init_internal(const ConfigOptions &config)
Definition: XBotInterface.h:1368
void load_flags(Flags... flags)
Definition: SyncFlags.h:93
std::vector< Joint::Ptr > _ordered_joint_vector
Definition: XBotInterface.h:1383
const std::map< std::string, ImuSensor::Ptr > & getImuInternal() const
Definition: XBotInterface.cpp:1662
bool imu_flag() const
Definition: SyncFlags.h:131
XBotInterface & operator=(const XBotInterface &rhs)
Definition: XBotInterface.cpp:1421
bool setPositionReference(const Eigen::VectorXd &q)
Sets the XBotInterface internal joint position references according to the provided vector,...
Definition: XBotInterface.cpp:1121
bool getRobotState(const std::string &state_name, Eigen::VectorXd &q) const
Gets the robot joints group state configuration as specified in the robot SRDF.
Definition: XBotInterface.cpp:1789
XBotCoreModel _XBotModel
Definition: XBotInterface.h:1380
bool getStiffness(Eigen::VectorXd &K) const
Gets the robot stiffness as an Eigen vector.
Definition: XBotInterface.cpp:808
bool init(const std::string &path_to_cfg)
Definition: XBotInterface.cpp:226
bool setVelocityReference(const Eigen::VectorXd &qdot)
Sets the XBotInterface internal joint velocity references according to the provided vector,...
Definition: XBotInterface.cpp:1163
void getEffortLimits(Eigen::VectorXd &tau_max) const
Gets a vector of the robot joint effort limits, as specified in the URDF file.
Definition: XBotInterface.cpp:1534
const std::vector< std::string > & getEnabledJointNames() const
Returns a vector of enabled joint names.
Definition: XBotInterface.cpp:1588
void print() const
Print a pretty table about the robot state.
Definition: XBotInterface.cpp:1901
virtual ~XBotInterface()
Definition: XBotInterface.cpp:1417
const std::string & getSrdfPath() const
getSrdfPath Getter for the path to the SRDF model
Definition: XBotInterface.cpp:1926
bool getJointAcceleration(Eigen::VectorXd &qddot) const
Gets the robot joint accelerations as an Eigen vector.
Definition: XBotInterface.cpp:773
const urdf::ModelInterface & getUrdf() const
Getter for the robot URDF model corresponding to the URDF xml file specified in the YAML config file.
Definition: XBotInterface.cpp:1405
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
XBot::Joint::ConstPtr getJointByDofIndex(int idx) const
Gets the joint with the required dof index.
Definition: XBotInterface.cpp:318
std::map< std::string, ImuSensor::ConstPtr > getImu()
Getter for the IMU sensor map pertaining to the chain.
Definition: XBotInterface.cpp:1650
std::map< std::string, Hand::Ptr > getHand()
Getter for the hands map pertaining to the whole robot.
Definition: XBotInterface.cpp:1669
bool setMotorVelocity(const Eigen::VectorXd &qdot)
Sets the XBotInterface internal motor velocities according to the provided vector,...
Definition: XBotInterface.cpp:1107
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
XBot::Joint::ConstPtr getJointByName(const std::string &joint_name) const
Gets the joint with name "joint_name" if it is defined as enabled.
Definition: XBotInterface.cpp:302
bool enforceEffortLimit(Eigen::VectorXd &tau) const
Modifies the input joint effort vector by enforcing effort limits.
Definition: XBotInterface.cpp:1936
bool hasJoint(const std::string &joint_name) const
Checks that a joint with name "joint_name" is defined as an enabled joint inside the interface.
Definition: XBotInterface.cpp:291
Definition: IXBotModel.h:20
Joint::Ptr getJointByDofIndexInternal(int dof_index) const
Definition: XBotInterface.cpp:2015
void getVelocityLimits(Eigen::VectorXd &qdot_max) const
Gets a vector of the robot joint velocity limits, as specified in the URDF file.
Definition: XBotInterface.cpp:1569
const std::vector< std::string > & getModelOrderedChainName() const
Definition: XBotInterface.cpp:101
XBotInterface()
Definition: XBotInterface.cpp:26
const std::string & getUrdfString() const
Returns the robot URDF xml as a string.
Definition: XBotInterface.cpp:1410
Definition: XBotInterface.h:41
std::map< int, Hand::Ptr > _hand_id_map
Definition: XBotInterface.h:1390
bool eigenToMap(const Eigen::VectorXd &vector, JointNameMap &name_map) const
Converts a state vector for the whole robot to its JointNameMap representation.
Definition: XBotInterface.cpp:1848
XBot::Joint::ConstPtr getJointByID(int joint_id) const
Gets the joint with ID "joint_id" if it is defined as enabled.
Definition: XBotInterface.cpp:328