Skip to content

Commit 1ae312e

Browse files
committed
[config] Allow inheriting from another robot's plans
Since yaml-cpp does not support, nor intend to support YAML merge anchors, this manually adds this ability to inherit from another robot's plans configuration to avoid duplication See jbeder/yaml-cpp#300
1 parent a53ff50 commit 1ae312e

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

etc/LIPMWalking.in.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ plans:
371371
- pose:
372372
translation: [0.035, 0.09, 0.0]
373373
surface: LeftFootCenter
374-
hrp4j: &hrp4j
374+
hrp4j:
375375
ashibumi: # stepping in place
376376
double_support_duration: 0.5
377377
single_support_duration: 0.8
@@ -476,7 +476,16 @@ plans:
476476
- pose:
477477
translation: [0.035, 0.07, 0.0]
478478
surface: LeftFootCenter
479-
hrp4cr: *hrp4j
479+
hrp4cr:
480+
base: hrp4j
481+
warmup:
482+
com_height: 0.78
483+
ashibumi:
484+
com_height: 0.78
485+
custom_forward:
486+
com_height: 0.78
487+
custom_backward:
488+
com_height: 0.78
480489
hrp2_drc:
481490
ashibumi: # stepping in place
482491
double_support_duration: 0.2

src/Controller.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,60 @@ using Color = mc_rtc::gui::Color;
3636
namespace lipm_walking
3737
{
3838

39+
/**
40+
* @brief Recursively merge plan configurations
41+
* Allows for
42+
* plans:
43+
* hrp4:
44+
* com_height: 0.75
45+
* contacts:
46+
* - ...
47+
* hrp4j:
48+
* base: hrp4
49+
* com_height: 0.78
50+
*
51+
*
52+
* @param plans Configuration object containing all the plans
53+
* @param robot Robot for which the plan should be merged
54+
*
55+
* @return Merged plan for the specified robot
56+
*/
57+
mc_rtc::Configuration mergePlanConfigs(const mc_rtc::Configuration & plans, const std::string & robot)
58+
{
59+
if(plans(robot).has("base"))
60+
{
61+
std::string base = plans(robot)("base");
62+
if(base == robot)
63+
{
64+
mc_rtc::log::error_and_throw<std::runtime_error>(
65+
"[LIPMWalking] Plan \"{}\" cannot inherit from itself (base: \"{}\")", robot, base);
66+
}
67+
else if(!plans.has(base))
68+
{
69+
mc_rtc::log::error_and_throw<std::runtime_error>("[LIPMWalking] Plan \"{}\" has no base \"{}\"", robot, base);
70+
}
71+
else
72+
{
73+
mc_rtc::Configuration robotConf = plans(robot);
74+
robotConf.remove("base");
75+
auto res = mergePlanConfigs(plans, base);
76+
res.load(robotConf);
77+
return res;
78+
}
79+
}
80+
else
81+
{
82+
return plans(robot);
83+
}
84+
}
85+
3986
Controller::Controller(std::shared_ptr<mc_rbdyn::RobotModule> robotModule,
4087
double dt,
4188
const mc_rtc::Configuration & config)
4289
: mc_control::fsm::Controller(robotModule, dt, config), planInterpolator(gui()), halfSitPose(controlRobot().mbc().q)
4390
{
4491
auto robotConfig = config("robot_models")(controlRobot().name());
45-
auto planConfig = config("plans")(controlRobot().name());
92+
auto planConfig = mergePlanConfigs(config("plans"), controlRobot().name());
4693

4794
mc_rtc::log::info("Loading default stabilizer configuration");
4895
defaultStabilizerConfig_ = robot().module().defaultLIPMStabilizerConfiguration();

0 commit comments

Comments
 (0)