72 MCGlobalController(
const std::string & conf =
"", std::shared_ptr<mc_rbdyn::RobotModule> rm =
nullptr);
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 = {});
211 void setSensorPositions(
const std::string & robotName,
const std::map<std::string, Eigen::Vector3d> & poses);
290 const std::map<std::string, Eigen::Vector3d> & linearVels);
328 const std::map<std::string, Eigen::Vector3d> & angularVels);
373 const std::map<std::string, Eigen::Vector3d> & accels);
411 const std::map<std::string, Eigen::Vector3d> & accels);
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);
660 const std::map<std::string, Eigen::Vector3d> & accels);
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
767 bool AddController(
const std::string & name, std::shared_ptr<mc_control::MCController> controller);
792 void setGripperTargetQ(
const std::string & robot,
const std::string & name,
const std::vector<double> & q);
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;
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);
#define MC_CONTROL_DLLAPI
Definition: api.h:50
ltdl wrapper for mc_rtc purpose
#define MAKE_ROBOTS_ACCESSOR(NAME, PTR)
Definition: mc_global_controller.h:703
Definition: CompletionCriteria.h:11
std::unique_ptr< GlobalPlugin, mc_rtc::ObjectLoader< GlobalPlugin >::ObjectDeleter > GlobalPluginPtr
Definition: GlobalPlugin_fwd.h:15
std::chrono::duration< double, std::milli > duration_ms
Definition: clock.h:13
Definition: ControllerServerConfiguration.h:41
Definition: ControllerServer.h:26
MCController is the base class to implement all controllers. It assumes that at least two robots are ...
Definition: MCController.h:99
Store the controller configuration.
Definition: mc_global_controller.h:880
std::shared_ptr< mc_rbdyn::RobotModule > main_robot_module
Definition: mc_global_controller.h:901
std::string initial_controller
Definition: mc_global_controller.h:912
void load_controllers_configs()
std::vector< std::string > global_plugins_autoload
Definition: mc_global_controller.h:907
void load_plugin_configs()
std::unordered_map< std::string, mc_rtc::Configuration > controllers_configs
Definition: mc_global_controller.h:913
std::vector< std::string > global_plugin_paths
Definition: mc_global_controller.h:905
std::vector< std::string > enabled_controllers
Definition: mc_global_controller.h:911
std::unordered_map< std::string, mc_rtc::Configuration > global_plugin_configs
Definition: mc_global_controller.h:908
ControllerServerConfiguration gui_server_configuration
Definition: mc_global_controller.h:923
std::string log_directory
Definition: mc_global_controller.h:919
std::vector< std::string > global_plugins
Definition: mc_global_controller.h:906
Configuration config
Definition: mc_global_controller.h:925
std::vector< std::string > observer_module_paths
Definition: mc_global_controller.h:903
void load_controller_plugin_configs(const std::string &controller, const std::vector< std::string > &plugins)
std::string init_attitude_sensor
Definition: mc_global_controller.h:898
std::vector< std::string > robot_module_paths
Definition: mc_global_controller.h:900
bool enabled(const std::string &ctrl)
GlobalConfiguration(const std::string &conf, std::shared_ptr< mc_rbdyn::RobotModule > rm=nullptr, bool conf_only=false)
std::vector< std::string > controller_module_paths
Definition: mc_global_controller.h:910
Definition: mc_global_controller.h:23
~MCGlobalController()
Destructor.
void setJointDriverTemperatures(const std::map< std::string, double > &temperatures)
Driver temperature readings provided by multiple JointSensors for the main robot (sets control+real)
void setSensorAngularVelocity(const std::string &robotName, const Eigen::Vector3d &vel)
Sets the specified robot angular velocity sensor (control+real)
void refreshLog()
Create a new log file for the current controller.
void setEncoderVelocities(const std::vector< double > &eVelocities)
Sets the main robot's actual joint velocities (control+real)
const GlobalConfiguration & configuration() const
Access the global controller configuration.
void setEncoderVelocities(const std::string &robotName, const std::vector< double > &eVelocities)
Sets the main robot position sensor (control+real)
void setSensorOrientations(const QuaternionMap &oris)
Set multiple body sensors' orientation for the main robot (control+real)
void setSensorAngularAccelerations(const std::string &robotName, const std::map< std::string, Eigen::Vector3d > &accels)
Set multiple body sensors' angular acceleration for the specifiedrobot (control+real)
bool run()
Runs one step of the controller.
void setSensorAngularVelocity(const Eigen::Vector3d &vel)
Sets the main robot angular velocity sensor (control+real)
void setSensorPositions(const std::map< std::string, Eigen::Vector3d > &poses)
Set multiple body sensors' position for the main robot (control+real)
void setSensorOrientation(const std::string &robotName, const Eigen::Quaterniond &ori)
Sets the main robot orientation sensor (control + real)
void setSensorLinearAcceleration(const std::string &robotName, const Eigen::Vector3d &acc)
Sets the specified robot linear acceleration (control+real)
void setEncoderValues(const std::vector< double > &eValues)
Sets the main robot actual joints' values (control+real)
std::shared_ptr< mc_rbdyn::RobotModule > get_robot_module()
Returns the main robot module.
bool GoToHalfSitPose_service()
Returns to half-sit pose after an experiment.
MC_RTC_DEPRECATED void setSensorAcceleration(const Eigen::Vector3d &acc)
Sets the main robot acceleration (control+real)
void setJointMotorStatuses(const std::string &robotName, const std::map< std::string, bool > &statuses)
Motor status provided by multiple JointSensors for the specified robot (sets control+real)
void setSensorLinearVelocities(const std::map< std::string, Eigen::Vector3d > &linearVels)
Set multiple body sensor's linear velocities for the main robot (control+real)
void setSensorLinearVelocity(const Eigen::Vector3d &vel)
Sets the main robot linear velocity sensor (control+real)
void setSensorAngularAcceleration(const std::string &robotName, const Eigen::Vector3d &acc)
Sets the specified robot angular acceleration (control+real)
bool EnableController(const std::string &name)
Switch to the requested controller.
std::vector< std::string > loaded_robots() const
Returns a list of all the loaded robots, whether they are enabled or not.
void setSensorLinearVelocities(mc_rbdyn::Robot &robot, const std::map< std::string, Eigen::Vector3d > &linearVels)
Set multiple body sensor's linear velocities for a given robot.
void setWrenches(const std::map< std::string, sva::ForceVecd > &wrenches)
Force sensors' readings provided by the sensors (sets control+real)
void setJointMotorStatus(const std::string &joint, bool status)
Motor status provided by the JointSensor for the main robot (sets control+real)
void init(const std::map< std::string, std::vector< double >> &initqs={}, const std::map< std::string, sva::PTransformd > &initAttitudes={})
Initialize multiple robots to the given configuration and attitude.
void setGripperOpenPercent(const std::string &robot, const std::string &name, double pOpen)
Set the gripper opening percentage for a given robot/gripper.
std::string current_controller() const
Returns the name of the current controller.
void setGripperOpenPercent(const std::string &robot, double pOpen)
Set the gripper opening percentage for all grippers in a robot.
void setSensorAngularAccelerations(const std::map< std::string, Eigen::Vector3d > &accels)
Set multiple body sensors' angular acceleration for a given robot for the main robot (control+real)
void setSensorAngularVelocities(mc_rbdyn::Robot &robot, const std::map< std::string, Eigen::Vector3d > &angularVels)
Set multiple body sensor's angular velocities for a given robot.
void setJointMotorTemperatures(const std::string &robotName, const std::map< std::string, double > &temperatures)
Motor temperature readings provided by multiple JointSensors for the specified robot (sets control+re...
void setJointMotorTemperature(const std::string &robotName, const std::string &joint, double temperature)
Motor temperature reading provided by the JointSensor for the specified robot (sets control+real)
void setSensorLinearVelocity(const std::string &robotName, const Eigen::Vector3d &vel)
Sets the specified robot linear velocity sensor (control+real)
bool AddController(const std::string &name)
Add a controller to the enabled list.
ControllerServer & server()
Access the server.
void setWrenches(const std::string &robotName, const std::map< std::string, sva::ForceVecd > &wrenches)
Force sensors' readings for the specified robot (control + real)
void setJointDriverTemperatures(const std::string &robotName, const std::map< std::string, double > &temperatures)
Driver temperature readings provided by multiple JointSensors for the specified robot (sets control+r...
const std::vector< std::string > & ref_joint_order()
Access the reference joint order.
void setJointDriverTemperature(const std::string &robotName, const std::string &joint, double temperature)
Driver temperature reading provided by the JointSensor for the specified robot (sets control+real)
void setSensorAngularAcceleration(const Eigen::Vector3d &acc)
Sets the main robot angular acceleration (control+real)
double timestep() const
Get the controller timestep.
Eigen::aligned_allocator< std::pair< const std::string, Eigen::Quaterniond > > QuaternionMapAllocator
Definition: mc_global_controller.h:27
void setJointTorques(const std::vector< double > &tValues)
Sets the main robot's actual joint torques (control+real)
MC_RTC_DEPRECATED void setSensorAccelerations(mc_rbdyn::Robot &robot, const std::map< std::string, Eigen::Vector3d > &accels)
void setSensorLinearAccelerations(const std::string &robotName, const std::map< std::string, Eigen::Vector3d > &accels)
Set multiple body sensors' linear acceleration for a given robot for the specified robot (control+rea...
const MCController & controller() const noexcept
Const access to current controller.
Definition: mc_global_controller.h:687
void setSensorLinearAccelerations(mc_rbdyn::Robot &robot, const std::map< std::string, Eigen::Vector3d > &accels)
Set multiple body sensors' linear acceleration for a given robot.
void setSensorLinearVelocities(const std::string &robotName, const std::map< std::string, Eigen::Vector3d > &linearVels)
Set multiple body sensor's linear velocities for the specified robot (control+real)
void setEncoderValues(const std::string &robotName, const std::vector< double > &eValues)
void setSensorLinearAccelerations(const std::map< std::string, Eigen::Vector3d > &accels)
Set multiple body sensors' linear acceleration for a given robot for the main robot (control+real)
std::map< std::string, Eigen::Quaterniond, std::less< std::string >, QuaternionMapAllocator > QuaternionMap
Definition: mc_global_controller.h:28
MC_RTC_DEPRECATED void setWrenches(unsigned int robotIndex, const std::map< std::string, sva::ForceVecd > &wrenches)
void setSensorOrientations(mc_rbdyn::Robot &robot, const QuaternionMap &oris)
Set multiple body sensors' orientation for a given robot.
void setSensorPosition(const std::string &robotName, const Eigen::Vector3d &pos)
Sets a robot's position sensor (control+real)
std::vector< std::string > enabled_controllers() const
Returns a list of enabled controllers.
void setSensorPositions(const std::string &robotName, const std::map< std::string, Eigen::Vector3d > &poses)
Set multiple body sensors' position for the specified robot (control+real)
void setJointMotorStatuses(const std::map< std::string, bool > &statuses)
Motor status provided by multiple JointSensors for the main robot (sets control+real)
void setJointMotorCurrents(const std::map< std::string, double > ¤ts)
Motor current readings provided by multiple JointSensors for the main robot (sets control+real)
bool GoToHalfSitPose()
See mc_rtc::MCGlobalController::GoToHalfSitPose_service.
void setJointMotorCurrent(const std::string &joint, double current)
Motor current reading provided by the JointSensor for the main robot (sets control+real)
void setSensorPositions(mc_rbdyn::Robot &robot, const std::map< std::string, Eigen::Vector3d > &poses)
Set multiple body sensors' position for a given robot.
MCController & controller() noexcept
Access the current controller.
Definition: mc_global_controller.h:680
void setSensorPosition(const Eigen::Vector3d &pos)
Sets the main robot position sensor (control+real)
void setSensorOrientations(const std::string &robotName, const QuaternionMap &oris)
Set multiple body sensors' orientation for the specified robot (control+real)
void setJointMotorStatus(const std::string &robotName, const std::string &joint, bool status)
Motor status provided by the JointSensor for the specified robot (sets control+real)
MC_RTC_DEPRECATED void setSensorAccelerations(const std::map< std::string, Eigen::Vector3d > &accels)
void init(const std::vector< double > &initq)
Initialize the default controller with the given configuration.
void setJointDriverTemperature(const std::string &joint, double temperature)
Driver temperature reading provided by the JointSensor for the main robot (sets control+real)
void init(const std::vector< double > &initq, const std::array< double, 7 > &initAttitude)
Initialize robot attitude from encoders and the floating base attitude.
void setSensorAngularAccelerations(mc_rbdyn::Robot &robot, const std::map< std::string, Eigen::Vector3d > &accels)
Set multiple body sensors' angular acceleration for a given robot.
void setSensorOrientation(const Eigen::Quaterniond &ori)
Sets the main robot orientation sensor (control + real)
MCGlobalController(const std::string &conf="", std::shared_ptr< mc_rbdyn::RobotModule > rm=nullptr)
Create the global controller.
std::vector< std::string > loaded_controllers() const
Returns a list of all the loaded controllers, whether they are enabled or not.
void reset(const std::map< std::string, std::vector< double >> &resetqs={}, const std::map< std::string, sva::PTransformd > &resetAttitudes={})
Fully reset the current controller to the given initial state.
void add_controller_module_paths(const std::vector< std::string > &paths)
Add the given directories to the controller search path.
bool AddController(const std::string &name, std::shared_ptr< mc_control::MCController > controller)
Add an already created controller to the enabled list.
void setSensorLinearAcceleration(const Eigen::Vector3d &acc)
Sets the main robot linear acceleration (control+real)
void setSensorAngularVelocities(const std::map< std::string, Eigen::Vector3d > &angularVels)
Set multiple body sensor's angular velocities for the main robot (control + real)
void setJointMotorTemperatures(const std::map< std::string, double > &temperatures)
Motor temperature readings provided by multiple JointSensors for the main robot (sets control+real)
void setGripperTargetQ(const std::string &robot, const std::string &name, const std::vector< double > &q)
Set the opening target(s) for a given robot/gripper.
void setJointMotorCurrent(const std::string &robotName, const std::string &joint, double current)
Motor current reading provided by the JointSensor for the specified robot (sets control+real)
MCGlobalController(const GlobalConfiguration &conf)
Create the global controller with an existing GlobalConfiguration instance.
void setJointMotorCurrents(const std::string &robotName, const std::map< std::string, double > ¤ts)
Motor current readings provided by multiple JointSensors for the specified robot (sets control+real)
void setSensorAngularVelocities(const std::string &robotName, const std::map< std::string, Eigen::Vector3d > &angularVels)
Set multiple body sensor's angular velocities for the specified robot (control + real)
void init(const std::vector< double > &initq, const sva::PTransformd &initAttitude)
Initialize robot attitude from encoders and the floating base attitude.
void setJointTorques(const std::string &robotName, const std::vector< double > &tValues)
void setJointMotorTemperature(const std::string &joint, double temperature)
Motor temperature reading provided by the JointSensor for the main robot (sets control+real)
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
Policy
Defines available policies for the logger.
Definition: Logger.h:43
@ NON_THREADED
Non-threaded policy.