Skip to content

Commit f207cb6

Browse files
authored
Merge pull request #423 from antodld/topic/RobotFromControllerYAML
[MCControler] Update main robot name
2 parents a7b5322 + 69d13bb commit f207cb6

File tree

17 files changed

+251
-104
lines changed

17 files changed

+251
-104
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ repos:
4141
src/mc_control/samples/ExternalForces/etc/ExternalForces.in.yaml|
4242
src/mc_control/samples/LIPMStabilizer/etc/LIPMStabilizer.in.yaml|
4343
src/mc_control/fsm/states/data/StabilizerStanding.yaml|
44-
tests/controllers/TestPythonState.in.yaml
44+
tests/controllers/TestPythonState.in.yaml|
45+
tests/global_controller_configuration/mc_rtc.in.yaml
4546
)$
4647
- id: debug-statements
4748
- id: destroyed-symlinks

doc/_i18n/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,4 @@ tutorials:
178178
title: Supporting MC_RTC_BUILD_STATIC in your code
179179
debug-lssol-output-6:
180180
title: Debugging LSSOL output 6
181+
or: or

doc/_i18n/en/tutorials/introduction/configuration.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
</th>
3131
<td colspan="2">These entries cover most needs you might have</td>
3232
</tr>
33-
{% include mc_rtc_configuration_row.html entry="MainRobot" desc="This entry dictates the main robot used by all controllers. Most interface cannot infer the correct module to use based on the simulation environment so this is the user's responsibility to make sure the two match." example="MainRobot: JVRC1" %}
33+
{% capture MainRobot_example2 %}
34+
# Support renaming the robot
35+
MainRobot:
36+
name: MyRobot
37+
module: JVRC1
38+
{% endcapture %}
39+
{% include mc_rtc_configuration_row.html entry="MainRobot" desc="This entry dictates the main robot used by all controllers. Most interface cannot infer the correct module to use based on the simulation environment so this is the user's responsibility to make sure the two match." example="MainRobot: JVRC1" example2=MainRobot_example2%}
3440
<tr>
3541
<th scope="row">Enabled</th>
3642
<td>Provides a list of enabled controllers. See the <a href="{{site.baseurl}}/tutorials/samples/list-of-samples.html">list of all available sample controllers</a>.</td>

doc/_i18n/jp.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,4 @@ tutorials:
179179
title: MC_RTC_BUILD_STATICをプログラムでサポートする方法
180180
debug-lssol-output-6:
181181
title: LSSOL output 6のデバッグ
182+
or: または

doc/_i18n/jp/tutorials/introduction/configuration.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
</th>
3131
<td colspan="2">このエントリは、通常考えられるほとんどのニーズをカバーします。</td>
3232
</tr>
33-
{% include mc_rtc_configuration_row.html entry="MainRobot" desc="このエントリは、すべてのコントローラーで使用されるメインロボットを指定します。ほとんどのインターフェイスは、どのモジュールを使用すべきかをシミュレーション環境に基づいて推測することはできません。そのため、シミュレーション環境に応じてユーザーがモジュールを指定する必要があります。" example="MainRobot: JVRC1" %}
33+
{% capture MainRobot_example2 %}
34+
# ロボット名の変更をサポート
35+
MainRobot:
36+
name: MyRobot
37+
module: JVRC1
38+
{% endcapture %}
39+
{% include mc_rtc_configuration_row.html entry="MainRobot" desc="このエントリは、すべてのコントローラーで使用されるメインロボットを指定します。ほとんどのインターフェイスは、どのモジュールを使用すべきかをシミュレーション環境に基づいて推測することはできません。そのため、シミュレーション環境に応じてユーザーがモジュールを指定する必要があります。" example="MainRobot: JVRC1" example2=MainRobot_example2 %}
3440
<tr>
3541
<th scope="row">Enabled</th>
3642
<td>有効なコントローラーのリストを提供します。<a href="{{site.baseurl}}/tutorials/samples/list-of-samples.html">利用可能なサンプルコントローラーのリスト</a>を参照してください。</a>.</td>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<tr>
22
<th scope="row">{{include.entry}}</th>
33
<td>{{include.desc}}</td>
4-
<td>{% highlight yaml %}{{include.example}}{% endhighlight %}</td>
4+
<td>
5+
{% highlight yaml %}{{include.example}}{% endhighlight %}
6+
{% if include.example2 %}
7+
<p>{% t or %}</p>
8+
{% highlight yaml %}{{include.example2}}{% endhighlight %}
9+
{% endif %}
10+
</td>
511
</tr>

include/mc_control/mc_global_controller.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include <mc_rtc/log/Logger.h>
1616

1717
#include <array>
18-
#include <fstream>
19-
#include <sstream>
20-
#include <thread>
2118

2219
namespace mc_control
2320
{
@@ -878,7 +875,6 @@ struct MC_CONTROL_DLLAPI MCGlobalController
878875
*/
879876
bool running = false;
880877

881-
public:
882878
/*! \brief Store the controller configuration */
883879
struct MC_CONTROL_DLLAPI GlobalConfiguration
884880
{
@@ -887,29 +883,33 @@ struct MC_CONTROL_DLLAPI MCGlobalController
887883
* \param conf Configuration file that should be loaded
888884
*
889885
* \param Main robot module, if null use the MainRobot entry in conf to initialize it
886+
*
887+
* \param conf_only If true, only load the specified configuration file
890888
*/
891-
GlobalConfiguration(const std::string & conf, std::shared_ptr<mc_rbdyn::RobotModule> rm = nullptr);
889+
GlobalConfiguration(const std::string & conf,
890+
std::shared_ptr<mc_rbdyn::RobotModule> rm = nullptr,
891+
bool conf_only = false);
892892

893893
inline bool enabled(const std::string & ctrl);
894894

895895
bool verbose_loader = true;
896896

897897
bool init_attitude_from_sensor = false;
898-
std::string init_attitude_sensor = "";
898+
std::string init_attitude_sensor;
899899

900-
std::vector<std::string> robot_module_paths = {};
900+
std::vector<std::string> robot_module_paths;
901901
std::shared_ptr<mc_rbdyn::RobotModule> main_robot_module;
902902

903-
std::vector<std::string> observer_module_paths = {};
903+
std::vector<std::string> observer_module_paths;
904904

905-
std::vector<std::string> global_plugin_paths = {};
906-
std::vector<std::string> global_plugins = {};
907-
std::vector<std::string> global_plugins_autoload = {};
905+
std::vector<std::string> global_plugin_paths;
906+
std::vector<std::string> global_plugins;
907+
std::vector<std::string> global_plugins_autoload;
908908
std::unordered_map<std::string, mc_rtc::Configuration> global_plugin_configs;
909909

910-
std::vector<std::string> controller_module_paths = {};
911-
std::vector<std::string> enabled_controllers = {};
912-
std::string initial_controller = "";
910+
std::vector<std::string> controller_module_paths;
911+
std::vector<std::string> enabled_controllers;
912+
std::string initial_controller;
913913
std::unordered_map<std::string, mc_rtc::Configuration> controllers_configs;
914914
double timestep = 0.002;
915915
bool include_halfsit_controller = true;
@@ -921,8 +921,8 @@ struct MC_CONTROL_DLLAPI MCGlobalController
921921

922922
bool enable_gui_server = true;
923923
double gui_timestep = 0.05;
924-
std::vector<std::string> gui_server_pub_uris{};
925-
std::vector<std::string> gui_server_rep_uris{};
924+
std::vector<std::string> gui_server_pub_uris;
925+
std::vector<std::string> gui_server_rep_uris;
926926

927927
Configuration config;
928928

@@ -936,16 +936,16 @@ struct MC_CONTROL_DLLAPI MCGlobalController
936936
private:
937937
using duration_ms = std::chrono::duration<double, std::milli>;
938938
GlobalConfiguration config;
939-
std::string current_ctrl = "";
940-
std::string next_ctrl = "";
939+
std::string current_ctrl;
940+
std::string next_ctrl;
941941
MCController * controller_ = nullptr;
942942
MCController * next_controller_ = nullptr;
943943
std::unique_ptr<mc_rtc::ObjectLoader<MCController>> controller_loader_;
944944
std::map<std::string, std::shared_ptr<mc_control::MCController>> controllers;
945945
std::vector<mc_observers::ObserverPtr> observers_;
946946
std::map<std::string, mc_observers::ObserverPtr> observersByName_;
947947

948-
std::unique_ptr<mc_control::ControllerServer> server_ = nullptr;
948+
std::unique_ptr<mc_control::ControllerServer> server_;
949949

950950
std::unique_ptr<mc_rtc::ObjectLoader<GlobalPlugin>> plugin_loader_;
951951
struct PluginHandle
@@ -981,7 +981,7 @@ struct MC_CONTROL_DLLAPI MCGlobalController
981981
void start_log();
982982
void setup_log();
983983
void setup_plugin_log();
984-
std::map<std::string, bool> setup_logger_ = {};
984+
std::map<std::string, bool> setup_logger_;
985985

986986
/** Timers and performance measure */
987987
duration_ms global_run_dt{0};

include/mc_rbdyn/RobotLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct MC_RBDYN_DLLAPI RobotLoader
132132
std::lock_guard<std::mutex> guard{mtx};
133133
init(true);
134134
robot_loader->clear();
135+
aliases.clear();
135136
}
136137

137138
/** Check if a robot is available

src/mc_control/MCController.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static inline std::shared_ptr<mc_solver::QPSolver> make_solver(double dt, MCCont
115115
}
116116
}
117117

118-
MCController::MCController(const std::vector<std::shared_ptr<mc_rbdyn::RobotModule>> & robots_modules,
118+
MCController::MCController(const std::vector<std::shared_ptr<mc_rbdyn::RobotModule>> & robot_modules,
119119
double dt,
120120
const mc_rtc::Configuration & config,
121121
ControllerParameters params)
@@ -129,7 +129,14 @@ MCController::MCController(const std::vector<std::shared_ptr<mc_rbdyn::RobotModu
129129
qpsolver->logger(logger_);
130130
qpsolver->gui(gui_);
131131
qpsolver->controller(this);
132-
for(auto rm : robots_modules) { loadRobot(rm, rm->name); }
132+
133+
std::string main_robot_name = config.find<std::string>("MainRobot", "name").value_or(robot_modules[0]->name);
134+
loadRobot(robot_modules[0], main_robot_name);
135+
for(auto it = std::next(robot_modules.cbegin()); it != robot_modules.end(); ++it)
136+
{
137+
const auto & rm = *it;
138+
loadRobot(rm, rm->name);
139+
}
133140
/* Load robot-specific configuration depending on parameters */
134141
auto load_robot_config_into = config;
135142
if(params.load_robot_config_)
@@ -192,7 +199,7 @@ MCController::MCController(const std::vector<std::shared_ptr<mc_rbdyn::RobotModu
192199
dynamicsConstraint.reset(new mc_solver::DynamicsConstraint(robots(), 0, dt, damper, 0.5));
193200
kinematicsConstraint.reset(new mc_solver::KinematicsConstraint(robots(), 0, dt, damper, 0.5));
194201
selfCollisionConstraint.reset(new mc_solver::CollisionsConstraint(robots(), 0, 0, dt));
195-
selfCollisionConstraint->addCollisions(solver(), robots_modules[0]->minimalSelfCollisions());
202+
selfCollisionConstraint->addCollisions(solver(), robot_modules[0]->minimalSelfCollisions());
196203
compoundJointConstraint.reset(new mc_solver::CompoundJointConstraint(robots(), 0, timeStep));
197204
postureTask = std::make_shared<mc_tasks::PostureTask>(solver(), 0, 10.0, 5.0);
198205
/** Load additional robots from the configuration */
@@ -247,19 +254,15 @@ MCController::MCController(const std::vector<std::shared_ptr<mc_rbdyn::RobotModu
247254
}
248255
else
249256
{
250-
std::string module = rconfig("module");
251-
auto params = rconfig("params", std::vector<std::string>{});
252-
mc_rbdyn::RobotModulePtr rm = nullptr;
253-
if(params.size() == 0) { rm = mc_rbdyn::RobotLoader::get_robot_module(module); }
254-
else if(params.size() == 1) { rm = mc_rbdyn::RobotLoader::get_robot_module(module, params.at(0)); }
255-
else if(params.size() == 2)
257+
auto params = [&]() -> std::vector<std::string>
256258
{
257-
rm = mc_rbdyn::RobotLoader::get_robot_module(module, params.at(0), params.at(1));
258-
}
259-
else
260-
{
261-
mc_rtc::log::error_and_throw("Controller only handles robot modules that require two parameters at most");
262-
}
259+
auto module = rconfig("module");
260+
if(module.isArray()) { return module.operator std::vector<std::string>(); }
261+
std::vector<std::string> params = rconfig("params", std::vector<std::string>{});
262+
params.insert(params.begin(), module.operator std::string());
263+
return params;
264+
}();
265+
auto rm = mc_rbdyn::RobotLoader::get_robot_module(params);
263266
if(!rm) { mc_rtc::log::error_and_throw("Failed to load {} as specified in configuration", rname); }
264267
auto & robot = loadRobot(rm, rname);
265268
load_robot_config(robot);

src/mc_control/Ticker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <mc_control/Ticker.h>
66

7+
#include <thread>
8+
79
#include <boost/filesystem.hpp>
810
namespace bfs = boost::filesystem;
911

0 commit comments

Comments
 (0)