72 MCGlobalController(
const std::string & conf =
"", std::shared_ptr<mc_rbdyn::RobotModule> rm =
nullptr);
81 std::vector<std::string> enabled_controllers()
const;
86 std::vector<std::string> loaded_controllers()
const;
91 std::vector<std::string> loaded_robots()
const;
94 std::shared_ptr<mc_rbdyn::RobotModule> get_robot_module();
97 std::string current_controller()
const;
118 void init(
const std::vector<double> & initq);
127 void init(
const std::vector<double> & initq,
const std::array<double, 7> & initAttitude);
135 void init(
const std::vector<double> & initq,
const sva::PTransformd & initAttitude);
149 void init(
const std::map<std::string, std::vector<double>> & initqs = {},
150 const std::map<std::string, sva::PTransformd> & initAttitudes = {});
166 void reset(
const std::map<std::string, std::vector<double>> & resetqs = {},
167 const std::map<std::string, sva::PTransformd> & resetAttitudes = {});
182 void setSensorPosition(
const Eigen::Vector3d & pos);
194 void setSensorPosition(
const std::string & robotName,
const Eigen::Vector3d & pos);
201 void setSensorPositions(
const std::map<std::string, Eigen::Vector3d> & poses);
211 void setSensorPositions(
const std::string & robotName,
const std::map<std::string, Eigen::Vector3d> & poses);
222 void setSensorOrientation(
const Eigen::Quaterniond & ori);
233 void setSensorOrientation(
const std::string & robotName,
const Eigen::Quaterniond & ori);
242 void setSensorOrientations(
const QuaternionMap & oris);
253 void setSensorOrientations(
const std::string & robotName,
const QuaternionMap & oris);
260 void setSensorLinearVelocity(
const Eigen::Vector3d & vel);
270 void setSensorLinearVelocity(
const std::string & robotName,
const Eigen::Vector3d & vel);
277 void setSensorLinearVelocities(
const std::map<std::string, Eigen::Vector3d> & linearVels);
289 void setSensorLinearVelocities(
const std::string & robotName,
290 const std::map<std::string, Eigen::Vector3d> & linearVels);
298 void setSensorAngularVelocity(
const Eigen::Vector3d & vel);
309 void setSensorAngularVelocity(
const std::string & robotName,
const Eigen::Vector3d & vel);
316 void setSensorAngularVelocities(
const std::map<std::string, Eigen::Vector3d> & angularVels);
327 void setSensorAngularVelocities(
const std::string & robotName,
328 const std::map<std::string, Eigen::Vector3d> & angularVels);
334 MC_RTC_DEPRECATED
void setSensorAcceleration(
const Eigen::Vector3d & acc);
338 MC_RTC_DEPRECATED
void setSensorAccelerations(
const std::map<std::string, Eigen::Vector3d> & accels);
344 void setSensorLinearAcceleration(
const Eigen::Vector3d & acc);
354 void setSensorLinearAcceleration(
const std::string & robotName,
const Eigen::Vector3d & acc);
361 void setSensorLinearAccelerations(
const std::map<std::string, Eigen::Vector3d> & accels);
372 void setSensorLinearAccelerations(
const std::string & robotName,
373 const std::map<std::string, Eigen::Vector3d> & accels);
381 void setSensorAngularAcceleration(
const Eigen::Vector3d & acc);
392 void setSensorAngularAcceleration(
const std::string & robotName,
const Eigen::Vector3d & acc);
399 void setSensorAngularAccelerations(
const std::map<std::string, Eigen::Vector3d> & accels);
410 void setSensorAngularAccelerations(
const std::string & robotName,
411 const std::map<std::string, Eigen::Vector3d> & accels);
420 void setEncoderValues(
const std::vector<double> & eValues);
430 void setEncoderValues(
const std::string & robotName,
const std::vector<double> & eValues);
441 void setEncoderVelocities(
const std::vector<double> & eVelocities);
451 void setEncoderVelocities(
const std::string & robotName,
const std::vector<double> & eVelocities);
460 void setJointTorques(
const std::vector<double> & tValues);
469 void setJointTorques(
const std::string & robotName,
const std::vector<double> & tValues);
476 void setWrenches(
const std::map<std::string, sva::ForceVecd> & wrenches);
487 void setWrenches(
const std::string & robotName,
const std::map<std::string, sva::ForceVecd> & wrenches);
491 MC_RTC_DEPRECATED
void setWrenches(
unsigned int robotIndex,
const std::map<std::string, sva::ForceVecd> & wrenches);
499 void setJointMotorTemperature(
const std::string & joint,
double temperature);
510 void setJointMotorTemperature(
const std::string & robotName,
const std::string & joint,
double temperature);
517 void setJointMotorTemperatures(
const std::map<std::string, double> & temperatures);
527 void setJointMotorTemperatures(
const std::string & robotName,
const std::map<std::string, double> & temperatures);
535 void setJointDriverTemperature(
const std::string & joint,
double temperature);
546 void setJointDriverTemperature(
const std::string & robotName,
const std::string & joint,
double temperature);
553 void setJointDriverTemperatures(
const std::map<std::string, double> & temperatures);
563 void setJointDriverTemperatures(
const std::string & robotName,
const std::map<std::string, double> & temperatures);
571 void setJointMotorCurrent(
const std::string & joint,
double current);
582 void setJointMotorCurrent(
const std::string & robotName,
const std::string & joint,
double current);
589 void setJointMotorCurrents(
const std::map<std::string, double> & currents);
599 void setJointMotorCurrents(
const std::string & robotName,
const std::map<std::string, double> & currents);
607 void setJointMotorStatus(
const std::string & joint,
bool status);
618 void setJointMotorStatus(
const std::string & robotName,
const std::string & joint,
bool status);
625 void setJointMotorStatuses(
const std::map<std::string, bool> & statuses);
635 void setJointMotorStatuses(
const std::string & robotName,
const std::map<std::string, bool> & statuses);
649 void setSensorPositions(
mc_rbdyn::Robot & robot,
const std::map<std::string, Eigen::Vector3d> & poses);
651 void setSensorAngularAccelerations(
mc_rbdyn::Robot & robot,
const std::map<std::string, Eigen::Vector3d> & accels);
653 void setSensorLinearAccelerations(
mc_rbdyn::Robot & robot,
const std::map<std::string, Eigen::Vector3d> & accels);
660 const std::map<std::string, Eigen::Vector3d> & accels);
662 void setSensorOrientations(
mc_rbdyn::Robot & robot,
const QuaternionMap & oris);
664 void setSensorLinearVelocities(
mc_rbdyn::Robot & robot,
const std::map<std::string, Eigen::Vector3d> & linearVels);
666 void setSensorAngularVelocities(
mc_rbdyn::Robot & robot,
const std::map<std::string, Eigen::Vector3d> & angularVels);
677 ControllerServer & server();
682 assert(controller_ !=
nullptr);
689 assert(controller_ !=
nullptr);
703 #define MAKE_ROBOTS_ACCESSOR(NAME, PTR) \
704 inline mc_rbdyn::Robots & NAME##s() noexcept { return *controller().PTR##s_; } \
705 inline const mc_rbdyn::Robots & NAME##s() const noexcept { return *controller().PTR##s_; } \
706 inline mc_rbdyn::Robot & NAME() noexcept { return NAME##s().robot(); } \
707 inline const mc_rbdyn::Robot & NAME() const noexcept { return NAME##s().robot(); } \
708 inline mc_rbdyn::Robot & NAME(const std::string & name) { return NAME##s().robot(name); } \
709 inline const mc_rbdyn::Robot & NAME(const std::string & name) const { return NAME##s().robot(name); }
714 #undef MAKE_ROBOTS_ACCESSOR
719 double timestep()
const;
726 const std::vector<std::string> & ref_joint_order();
729 const GlobalConfiguration & configuration()
const;
741 void add_controller_module_paths(
const std::vector<std::string> & paths);
752 bool AddController(
const std::string & name);
767 bool AddController(
const std::string & name, std::shared_ptr<mc_control::MCController> controller);
777 bool EnableController(
const std::string & name);
792 void setGripperTargetQ(
const std::string & robot,
const std::string & name,
const std::vector<double> & q);
798 void setGripperOpenPercent(
const std::string & robot,
double pOpen);
805 void setGripperOpenPercent(
const std::string & robot,
const std::string & name,
double pOpen);
823 bool GoToHalfSitPose_service();
825 bool GoToHalfSitPose();
840 void init(
const std::map<std::string, std::vector<double>> & initqs,
841 const std::map<std::string, sva::PTransformd> & initAttitudes,
851 void initEncoders(
mc_rbdyn::Robot & robot,
const std::vector<double> & initq);
867 void initController(
bool reset =
false);
876 bool running =
false;
890 std::shared_ptr<mc_rbdyn::RobotModule> rm =
nullptr,
891 bool conf_only =
false);
893 inline bool enabled(
const std::string & ctrl);
895 bool verbose_loader =
true;
897 bool init_attitude_from_sensor =
false;
914 double timestep = 0.002;
915 bool include_halfsit_controller =
true;
917 bool enable_log =
true;
920 std::string log_template =
"mc-control";
922 bool enable_gui_server =
true;
927 void load_controllers_configs();
929 void load_plugin_configs();
931 void load_controller_plugin_configs(
const std::string & controller,
const std::vector<std::string> & plugins);
935 using duration_ms = std::chrono::duration<double, std::milli>;
937 std::string current_ctrl;
938 std::string next_ctrl;
941 std::unique_ptr<mc_rtc::ObjectLoader<MCController>> controller_loader_;
942 std::map<std::string, std::shared_ptr<mc_control::MCController>> controllers;
943 std::vector<mc_observers::ObserverPtr> observers_;
944 std::map<std::string, mc_observers::ObserverPtr> observersByName_;
946 std::unique_ptr<mc_control::ControllerServer> server_;
948 std::unique_ptr<mc_rtc::ObjectLoader<GlobalPlugin>> plugin_loader_;
951 PluginHandle(
const std::string & name,
GlobalPluginPtr plugin) : name(name), plugin(
std::move(plugin)) {}
952 PluginHandle(
const PluginHandle &) =
delete;
953 PluginHandle & operator=(
const PluginHandle &) =
delete;
954 PluginHandle(PluginHandle &&) =
default;
955 PluginHandle & operator=(PluginHandle &&) =
default;
960 std::vector<PluginHandle> plugins_;
961 std::vector<PluginHandle> controller_plugins_;
964 GlobalPlugin * plugin;
967 std::vector<PluginBefore> plugins_before_;
968 std::vector<GlobalPlugin *> plugins_before_always_;
971 GlobalPlugin * plugin;
974 std::vector<PluginAfter> plugins_after_;
975 std::vector<GlobalPlugin *> plugins_after_always_;
981 void setup_plugin_log();
982 std::map<std::string, bool> setup_logger_;
990 double solver_build_and_solve_t = 0;
991 double solver_solve_t = 0;
992 double framework_cost = 0;
999 void resetControllerPlugins();
1007 GlobalPlugin * loadPlugin(
const std::string & name,
const char * requiredBy);