Explicitly specify actdim on PID plugin actuators, to allow them to be used with keyframes.
Support actdim attribute on plugin actuators. Remove the actuator_actdim callback. This callback leads to crashes when loading keyframes for models that have a stateful plugin. PiperOrigin-RevId: 650649505 Change-Id: I40d1994d02ae4e20ce631b2702a984766cf2628e
This commit is contained in:
committed by
Copybara-Service
parent
e0d33eb1d0
commit
393895bb29
+17
-2
@@ -117,6 +117,23 @@ std::unique_ptr<Pid> Pid::Create(const mjModel* m, int instance) {
|
||||
mju_warning("actuator not found for plugin instance %d", instance);
|
||||
return nullptr;
|
||||
}
|
||||
// Validate actnum values for all actuators:
|
||||
for (int actuator_id : actuators) {
|
||||
int actnum = m->actuator_actnum[actuator_id];
|
||||
int expected_actnum = Pid::ActDim(m, instance, actuator_id);
|
||||
int dyntype = m->actuator_dyntype[actuator_id];
|
||||
if (dyntype == mjDYN_FILTER || dyntype == mjDYN_FILTEREXACT ||
|
||||
dyntype == mjDYN_INTEGRATOR) {
|
||||
expected_actnum++;
|
||||
}
|
||||
if (actnum != expected_actnum) {
|
||||
mju_warning(
|
||||
"actuator %d has actdim %d, expected %d. Add actdim=\"%d\" to the "
|
||||
"actuator plugin element.",
|
||||
actuator_id, actnum, expected_actnum, expected_actnum);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return std::unique_ptr<Pid>(new Pid(config, std::move(actuators)));
|
||||
}
|
||||
|
||||
@@ -240,8 +257,6 @@ void Pid::RegisterPlugin() {
|
||||
kAttrIMax, kAttrSlewMax};
|
||||
plugin.nattribute = attributes.size();
|
||||
plugin.attributes = attributes.data();
|
||||
|
||||
plugin.actuator_actdim = Pid::ActDim;
|
||||
plugin.nstate = Pid::StateSize;
|
||||
|
||||
plugin.init = +[](const mjModel* m, mjData* d, int instance) {
|
||||
|
||||
@@ -52,9 +52,6 @@ class Pid {
|
||||
// Returns the number of state variables for the plugin instance
|
||||
static int StateSize(const mjModel* m, int instance);
|
||||
|
||||
// Returns the number of activation variables for the plugin instance
|
||||
static int ActDim(const mjModel* m, int instance, int actuator_id);
|
||||
|
||||
// Resets the C++ Pid instance's state.
|
||||
// plugin_state is a C array pointer into mjData->plugin_state, with a size
|
||||
// equal to the value returned from StateSize.
|
||||
@@ -76,6 +73,9 @@ class Pid {
|
||||
private:
|
||||
Pid(PidConfig config, std::vector<int> actuators);
|
||||
|
||||
// Returns the expected number of activation variables for the instance.
|
||||
static int ActDim(const mjModel* m, int instance, int actuator_id);
|
||||
|
||||
struct State {
|
||||
mjtNum previous_ctrl = 0;
|
||||
// if using slew rate limits, mjData.act will contain an activation variable
|
||||
|
||||
Reference in New Issue
Block a user