Skip to content

Commit

Permalink
[mc_rtc] Load calibration from the replay plugin
Browse files Browse the repository at this point in the history
This allows us to test the loading of the calibration files from the
replay
  • Loading branch information
gergondet committed Oct 6, 2023
1 parent c1fc6d6 commit 9d413a7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
15 changes: 15 additions & 0 deletions plugins/Replay/src/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ void Replay::reset(mc_control::MCGlobalController & gc)
iters_ = std::max<size_t>(std::min<size_t>(iter, log_->size() - 1), 0);
},
0.0, static_cast<double>(log_->size()) * gc.timestep()));
// Use calibration from the replay
if(with_inputs_ && log_->meta())
{
const auto & calibs = log_->meta()->calibs;
for(const auto & [r, fs_calibs] : calibs)
{
if(!gc.robots().hasRobot(r)) { continue; }
auto & robot = gc.robots().robot(r);
for(const auto & [fs_name, calib] : fs_calibs)
{
auto & fs = const_cast<mc_rbdyn::ForceSensor &>(robot.forceSensor(fs_name));
fs.loadCalibrator(mc_rbdyn::detail::ForceSensorCalibData::fromConfiguration(calib));
}
}
}
// Run once to fill the initial sensors
before(gc);
iters_ = 0;
Expand Down
13 changes: 0 additions & 13 deletions src/mc_control/Ticker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,6 @@ Ticker::Ticker(const Configuration & config) : config_(config), gc_(get_gc_confi
}
// Do the initialization
auto [encoders, attitudes] = get_initial_state(*log_, gc_.robots(), gc_.controller().robot().name());
if(log_->meta())
{
const auto & calibs = log_->meta()->calibs;
for(const auto & [r, fs_calibs] : calibs)
{
auto & robot = gc_.robots().robot(r);
for(const auto & [fs_name, calib] : fs_calibs)
{
auto & fs = const_cast<mc_rbdyn::ForceSensor &>(robot.forceSensor(fs_name));
fs.loadCalibrator(mc_rbdyn::detail::ForceSensorCalibData::fromConfiguration(calib));
}
}
}
gc_.init(encoders, attitudes);
}
else { gc_.init(); }
Expand Down
3 changes: 3 additions & 0 deletions tests/controllers/replay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ set_target_properties(
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/TestReplayController
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/TestReplayController
)
target_include_directories(TestReplayController PRIVATE ${CMAKE_SOURCE_DIR}/tests)
set(CONFIG_HEADER_INCLUDE_DIR "${CMAKE_BINARY_DIR}/tests/include/$<CONFIG>")
target_include_directories(TestReplayController PRIVATE ${CONFIG_HEADER_INCLUDE_DIR})

add_global_controller_test_run(
TestReplayController_Record ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/mc_rtc.yaml 50
Expand Down
18 changes: 18 additions & 0 deletions tests/controllers/replay/TestReplayController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@

#include <boost/test/unit_test.hpp>

#include <utils.h>

namespace mc_control
{

static std::string REPLAY_PATH = "";

static auto calib = []()
{
mc_rbdyn::detail::ForceSensorCalibData calib;
calib.mass = 42.42;
calib.worldForce = random_fv();
calib.X_f_ds = random_pt();
calib.X_p_vb = random_pt();
calib.offset = random_fv();
return calib;
}();

template<bool Play>
struct MC_CONTROL_DLLAPI TestReplayController : public MCController
{
Expand All @@ -30,12 +43,17 @@ struct MC_CONTROL_DLLAPI TestReplayController : public MCController
solver().addConstraintSet(compoundJointConstraint);
postureTask->stiffness(200.0);
qpsolver->setContacts({});
if constexpr(!Play)
{
const_cast<mc_rbdyn::ForceSensor &>(robot().forceSensor("LeftFootForceSensor")).loadCalibrator(calib);
}
}

bool run() override
{
if constexpr(Play)
{
BOOST_REQUIRE(robot().forceSensor("LeftFootForceSensor").calib() == calib);
BOOST_REQUIRE(datastore().has("Replay::Log"));
BOOST_REQUIRE(!datastore().has("NOT_IN_DATASTORE"));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/controllers/replay/TestReplayController_Play.in.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Plugins: [Replay]
Replay:
with-inputs: false
with-inputs: true
with-gui-inputs: false
with-outputs: false
with-datastore-config: "@CMAKE_CURRENT_SOURCE_DIR@/datastore-replay.yaml"

0 comments on commit 9d413a7

Please sign in to comment.