16 #include <RBDyn/MultiBody.h>
17 #include <RBDyn/MultiBodyConfig.h>
18 #include <RBDyn/MultiBodyGraph.h>
22 #include <unordered_map>
38 std::optional<sva::PTransformd> base_tf_ = std::nullopt;
40 std::optional<std::string> base_ = std::nullopt;
42 bool warn_on_missing_files_ =
false;
47 #define MAKE_LOAD_ROBOT_PARAMETER_SETTER(T, NAME) \
48 inline LoadRobotParameters & NAME(T value) noexcept \
59 #undef MAKE_LOAD_ROBOT_PARAMETER_SETTER
64 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
81 const std::string & name()
const;
100 void addBodySensor(
const BodySensor & sensor);
109 return data_->bodySensorsIndex.count(name) != 0;
119 return data_->bodyBodySensors.count(body) != 0;
129 const BodySensor & bodySensor(
const std::string & name)
const;
138 const BodySensor & bodyBodySensor(
const std::string & name)
const;
153 return data()->jointJointSensors.count(joint) != 0;
163 const JointSensor & jointJointSensor(
const std::string & joint)
const;
166 inline const std::vector<JointSensor> &
jointSensors() const noexcept {
return data_->jointSensors; }
172 bool hasJoint(
const std::string & name)
const;
175 bool hasBody(
const std::string & name)
const;
178 inline bool hasFrame(
const std::string & name)
const noexcept {
return frames_.count(name) != 0; }
186 auto it = frames_.find(name);
187 if(it != frames_.end()) {
return *it->second; }
197 return const_cast<RobotFrame &
>(
static_cast<const Robot *
>(
this)->frame(name));
201 std::vector<std::string> frames()
const;
217 RobotFrame & makeFrame(
const std::string & name,
RobotFrame & parent, sva::PTransformd X_p_f,
bool baked =
false);
239 sva::PTransformd X_p_f,
240 bool baked =
false)
const;
249 void makeFrames(std::vector<mc_rbdyn::RobotModule::FrameDescription> frames);
255 unsigned int jointIndexByName(
const std::string & name)
const;
269 int jointIndexInMBC(
size_t jointIndex)
const;
275 unsigned int bodyIndexByName(
const std::string & name)
const;
278 rbd::MultiBody & mb();
280 const rbd::MultiBody & mb()
const;
283 rbd::MultiBodyConfig & mbc();
285 const rbd::MultiBodyConfig & mbc()
const;
288 rbd::MultiBodyGraph & mbg();
290 const rbd::MultiBodyGraph & mbg()
const;
293 const std::vector<std::vector<double>> & q()
const;
295 const std::vector<std::vector<double>> & alpha()
const;
297 const std::vector<std::vector<double>> & alphaD()
const;
299 const std::vector<std::vector<double>> & jointTorque()
const;
301 inline const std::vector<std::vector<double>> &
controlTorque() const noexcept {
return jointTorque(); }
303 const std::vector<sva::PTransformd> & bodyPosW()
const;
305 const std::vector<sva::MotionVecd> & bodyVelW()
const;
307 const std::vector<sva::MotionVecd> & bodyVelB()
const;
309 const std::vector<sva::MotionVecd> & bodyAccB()
const;
311 std::vector<std::vector<double>> & q();
313 std::vector<std::vector<double>> & alpha();
315 std::vector<std::vector<double>> & alphaD();
317 std::vector<std::vector<double>> & jointTorque();
319 inline std::vector<std::vector<double>> &
controlTorque() noexcept {
return jointTorque(); }
321 std::vector<sva::PTransformd> & bodyPosW();
323 std::vector<sva::MotionVecd> & bodyVelW();
325 std::vector<sva::MotionVecd> & bodyVelB();
327 std::vector<sva::MotionVecd> & bodyAccB();
333 const sva::PTransformd & bodyPosW(
const std::string & name)
const;
341 sva::PTransformd X_b1_b2(
const std::string & b1,
const std::string & b2)
const;
347 const sva::MotionVecd & bodyVelW(
const std::string & name)
const;
353 const sva::MotionVecd & bodyVelB(
const std::string & name)
const;
359 const sva::MotionVecd & bodyAccB(
const std::string & name)
const;
362 Eigen::Vector3d com()
const;
364 Eigen::Vector3d comVelocity()
const;
366 Eigen::Vector3d comAcceleration()
const;
381 sva::ForceVecd surfaceWrench(
const std::string & surfaceName)
const;
396 sva::ForceVecd bodyWrench(
const std::string & bodyName)
const;
409 Eigen::Vector2d cop(
const std::string & frame,
double min_pressure = 0.5)
const;
422 Eigen::Vector3d copW(
const std::string & frame,
double min_pressure = 0.5)
const;
431 sva::ForceVecd netWrench(
const std::vector<std::string> & sensorNames)
const;
453 Eigen::Vector3d
zmp(
const sva::ForceVecd & netTotalWrench,
454 const Eigen::Vector3d & plane_p,
455 const Eigen::Vector3d & plane_n,
456 double minimalNetNormalForce = 1.)
const;
473 bool zmp(Eigen::Vector3d & zmpOut,
474 const sva::ForceVecd & netTotalWrench,
475 const Eigen::Vector3d & plane_p,
476 const Eigen::Vector3d & plane_n,
477 double minimalNetNormalForce = 1.) const noexcept;
494 Eigen::Vector3d
zmp(const sva::ForceVecd & netTotalWrench,
495 const sva::PTransformd & zmpFrame,
496 double minimalNetNormalForce = 1.) const;
514 bool zmp(Eigen::Vector3d & zmpOut,
515 const sva::ForceVecd & netTotalWrench,
516 const sva::PTransformd & zmpFrame,
517 double minimalNetNormalForce = 1.) const noexcept;
525 Eigen::Vector3d
zmp(const
std::vector<
std::
string> & sensorNames,
526 const Eigen::Vector3d & plane_p,
527 const Eigen::Vector3d & plane_n,
528 double minimalNetNormalForce = 1.) const;
536 bool zmp(Eigen::Vector3d & zmpOut,
537 const
std::vector<
std::
string> & sensorNames,
538 const Eigen::Vector3d & plane_p,
539 const Eigen::Vector3d & plane_n,
540 double minimalNetNormalForce = 1.) const noexcept;
549 Eigen::Vector3d
zmp(const
std::vector<
std::
string> & sensorNames,
550 const sva::PTransformd & zmpFrame,
551 double minimalNetNormalForce = 1.) const;
560 bool zmp(Eigen::Vector3d & zmpOut,
561 const
std::vector<
std::
string> & sensorNames,
562 const sva::PTransformd & zmpFrame,
563 double minimalNetNormalForce = 1.) const noexcept;
566 const
std::vector<
std::vector<
double>> & ql() const;
568 const
std::vector<
std::vector<
double>> & qu() const;
570 const
std::vector<
std::vector<
double>> & vl() const;
572 const
std::vector<
std::vector<
double>> & vu() const;
574 const
std::vector<
std::vector<
double>> & al() const;
576 const
std::vector<
std::vector<
double>> & au() const;
578 const
std::vector<
std::vector<
double>> & jl() const;
580 const
std::vector<
std::vector<
double>> & ju() const;
582 const
std::vector<
std::vector<
double>> & tl() const;
584 const
std::vector<
std::vector<
double>> & tu() const;
586 const
std::vector<
std::vector<
double>> & tdl() const;
588 const
std::vector<
std::vector<
double>> & tdu() const;
590 std::vector<
std::vector<
double>> & ql();
592 std::vector<
std::vector<
double>> & qu();
594 std::vector<
std::vector<
double>> & vl();
596 std::vector<
std::vector<
double>> & vu();
598 std::vector<
std::vector<
double>> & al();
600 std::vector<
std::vector<
double>> & au();
602 std::vector<
std::vector<
double>> & jl();
604 std::vector<
std::vector<
double>> & ju();
606 std::vector<
std::vector<
double>> & tl();
608 std::vector<
std::vector<
double>> & tu();
610 std::vector<
std::vector<
double>> & tdl();
612 std::vector<
std::vector<
double>> & tdu();
626 void zmpTarget(const Eigen::Vector3d &
zmp);
632 const Eigen::Vector3d & zmpTarget() const;
635 inline
double mass() const noexcept {
return mass_; }
645 inline const std::vector<double> &
encoderValues() const noexcept {
return data_->encoderValues; }
648 inline const std::vector<double> &
encoderVelocities() const noexcept {
return data_->encoderVelocities; }
651 inline const std::vector<double> &
jointTorques() const noexcept {
return data_->jointTorques; }
654 inline const std::vector<std::string> &
refJointOrder()
const {
return data_->refJointOrder; }
687 return data_->forceSensorsIndex.count(name) != 0;
702 return data_->bodyForceSensors_.count(body) != 0;
720 return bodyHasForceSensor(this->surface(surface).bodyName());
734 return bodyHasForceSensor(body) || findIndirectForceSensorBodyName(body).empty();
747 return bodyHasIndirectForceSensor(this->surface(surface).bodyName());
759 const ForceSensor & forceSensor(
const std::string & name)
const;
772 const ForceSensor & bodyForceSensor(
const std::string & body)
const;
778 const ForceSensor * findBodyForceSensor(
const std::string & body)
const;
791 const ForceSensor & surfaceForceSensor(
const std::string & surfaceName)
const;
803 const ForceSensor & indirectBodyForceSensor(
const std::string & body)
const;
817 const ForceSensor & indirectSurfaceForceSensor(
const std::string & surface)
const;
820 inline const std::vector<ForceSensor> &
forceSensors() const noexcept {
return data_->forceSensors; }
840 bool hasDevice(
const std::string & name)
const noexcept;
844 inline bool hasSensor(
const std::string & name)
const noexcept
846 return hasDevice<T>(name);
861 const T & device(
const std::string & name)
const;
867 return const_cast<T &
>(
const_cast<const Robot *
>(
this)->device<T>(name));
875 inline const T &
sensor(
const std::string & name)
const
877 return device<T>(name);
882 inline T &
sensor(
const std::string & name)
884 return device<T>(name);
900 bool hasSurface(
const std::string & surface)
const;
912 sva::PTransformd surfacePose(
const std::string & sName)
const;
915 mc_rbdyn::Surface & copySurface(
const std::string & sName,
const std::string & name);
921 const std::map<std::string, mc_rbdyn::SurfacePtr> & surfaces()
const;
924 std::vector<std::string> availableSurfaces()
const;
930 bool hasConvex(
const std::string & name)
const;
937 convex_pair_t & convex(
const std::string & cName);
939 const convex_pair_t & convex(
const std::string & cName)
const;
945 const std::map<std::string, convex_pair_t> & convexes()
const;
960 void addConvex(
const std::string & name,
961 const std::string & body,
963 const sva::PTransformd & X_b_c = sva::PTransformd::Identity());
975 void removeConvex(
const std::string & name);
983 const sva::PTransformd & bodyTransform(
const std::string & bName)
const;
986 const sva::PTransformd & bodyTransform(
int bodyIndex)
const;
989 const std::vector<sva::PTransformd> & bodyTransforms()
const;
992 const sva::PTransformd & collisionTransform(
const std::string & cName)
const;
995 void loadRSDFFromDir(
const std::string & surfaceDir);
998 std::map<std::string, std::vector<double>> stance()
const;
1007 unsigned int robotIndex()
const;
1010 void forwardKinematics();
1012 void forwardKinematics(rbd::MultiBodyConfig & mbc)
const;
1015 void forwardVelocity();
1017 void forwardVelocity(rbd::MultiBodyConfig & mbc)
const;
1020 void forwardAcceleration(
const sva::MotionVecd & A_0 = sva::MotionVecd(Eigen::Vector6d::Zero()));
1022 void forwardAcceleration(rbd::MultiBodyConfig & mbc,
1023 const sva::MotionVecd & A_0 = sva::MotionVecd(Eigen::Vector6d::Zero()))
const;
1026 void eulerIntegration(
double step);
1028 void eulerIntegration(rbd::MultiBodyConfig & mbc,
double step)
const;
1031 const sva::PTransformd & posW()
const;
1043 void posW(
const sva::PTransformd & pt);
1051 void velW(
const sva::MotionVecd & vel);
1054 const sva::MotionVecd & velW()
const;
1062 void accW(
const sva::MotionVecd & acc);
1067 const sva::MotionVecd accW()
const;
1086 bool hasGripper(
const std::string & gripper)
const;
1088 inline const std::unordered_map<std::string, mc_control::GripperPtr> &
grippersByName() const noexcept
1090 return data_->grippers;
1094 inline const std::vector<mc_control::GripperRef> &
grippers() const noexcept {
return data_->grippersRef; }
1119 unsigned int robots_idx_;
1121 Eigen::Vector3d zmp_;
1122 std::vector<sva::PTransformd> bodyTransforms_;
1123 std::vector<std::vector<double>> ql_;
1124 std::vector<std::vector<double>> qu_;
1125 std::vector<std::vector<double>> vl_;
1126 std::vector<std::vector<double>> vu_;
1127 std::vector<std::vector<double>> al_;
1128 std::vector<std::vector<double>> au_;
1129 std::vector<std::vector<double>> jl_;
1130 std::vector<std::vector<double>> ju_;
1131 std::vector<std::vector<double>> tl_;
1132 std::vector<std::vector<double>> tu_;
1133 std::vector<std::vector<double>> tdl_;
1134 std::vector<std::vector<double>> tdu_;
1135 std::map<std::string, convex_pair_t> convexes_;
1136 std::map<std::string, sva::PTransformd> collisionTransforms_;
1137 std::map<std::string, mc_rbdyn::SurfacePtr> surfaces_;
1138 std::map<std::string, std::vector<double>> stance_;
1143 std::vector<int> refJointIndexToMBCIndex_;
1147 std::vector<Flexibility> flexibility_;
1149 std::unordered_map<std::string, RobotFramePtr> frames_;
1166 const std::string & name,
1168 unsigned int robots_idx,
1174 void copyLoadedData(
Robot & destination)
const;
1191 void fixSurface(
Surface & surface);
1194 void fixCollisionTransforms();
1204 std::string findIndirectForceSensorBodyName(
const std::string & bodyName)
const;
1214 mutable std::map<std::string, mc_tvm::ConvexPtr> tvm_convexes_;
1221 void name(
const std::string & n);
1262 const std::string & prefix,
1263 bool required =
false,
1264 const std::string & robotIndexKey =
"robotIndex",
1265 const std::string & robotNameKey =
"robot",
1266 const std::string & defaultRobotName =
"");
1276 const std::string & prefix =
"",
1277 bool required =
false,
1278 const std::string & robotIndexKey =
"robotIndex",
1279 const std::string & robotNameKey =
"robot",
1280 const std::string & defaultRobotName =
"");
1294 const std::string & prefix =
"",
1295 bool required =
false,
1296 const std::string & robotIndexKey =
"robotIndex",
1297 const std::string & robotNameKey =
"robot",
1298 const std::string & defaultRobotName =
"");
1308 #include <mc_rbdyn/Robot.hpp>