From 6412c95a373ecef04170ec9592bebee037cf5228 Mon Sep 17 00:00:00 2001 From: Nimrod Gileadi Date: Mon, 27 Nov 2023 10:31:12 -0800 Subject: [PATCH] Remove the use of plugin_state from PID plugin. The plugin was storing a boolean to indicate whether the previous ctrl value was set in `act`. Use d->time == 0 instead. PiperOrigin-RevId: 585692686 Change-Id: I95335cebdb5716bd6fad81f463a4f248406c80ec --- plugin/actuator/README.md | 4 +--- plugin/actuator/pid.cc | 11 ++--------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/plugin/actuator/README.md b/plugin/actuator/README.md index 534bb61e..80676921 100644 --- a/plugin/actuator/README.md +++ b/plugin/actuator/README.md @@ -50,6 +50,4 @@ The available options are: : : : : : : :If a bigger change is requested between two timesteps, it will be clipped to the range `[ctrl - slewmax * dt, ctrl + slewmax * dt]` : : : : : -: : :If specified, one activation variable will be added to `mjData.act` containing the previous value of `ctrl`. One state variable will : -: : :be added to `mjData.plugin_state`, to indicate whether the previous value of `ctrl` should be used (0 on first step, 1 : -: : :otherwise). : +: : :If specified, one activation variable will be added to `mjData.act` containing the previous value of `ctrl`. : diff --git a/plugin/actuator/pid.cc b/plugin/actuator/pid.cc index 6b20c0aa..54260fe0 100644 --- a/plugin/actuator/pid.cc +++ b/plugin/actuator/pid.cc @@ -128,9 +128,6 @@ std::unique_ptr Pid::Create(const mjModel* m, int instance) { void Pid::Reset(mjtNum* plugin_state) { integral_ = 0.0; previous_ctrl_ = 0.0; - if (config_.slew_max.has_value()) { - plugin_state[0] = false; // previous_ctrl_exists - } } mjtNum Pid::GetCtrl(const mjModel* m, const mjData* d, const State& state, @@ -208,15 +205,11 @@ void Pid::Compute(const mjModel* m, mjData* d, int instance) { } void Pid::Advance(const mjModel* m, mjData* d, int instance) const { - if (config_.slew_max.has_value()) { - // previous_ctrl_exists = true - d->plugin_state[m->plugin_stateadr[instance]] = true; - } // act variables already updated by MuJoCo integrating act_dot } int Pid::StateSize(const mjModel* m, int instance) { - return HasSlew(m, instance) ? 1 : 0; + return 0; } int Pid::ActDim(const mjModel* m, int instance, int actuator_id) { @@ -232,7 +225,7 @@ Pid::State Pid::GetState(const mjModel* m, mjData* d, int instance) const { } if (config_.slew_max.has_value()) { state.previous_ctrl = d->act[state_idx++]; - state.previous_ctrl_exists = d->plugin_state[m->plugin_stateadr[instance]]; + state.previous_ctrl_exists = d->time > 0; } return state; }