Add actuator and sensor delays. Fixes #1004

PiperOrigin-RevId: 866478839
Change-Id: Id21a6da0f98454c8fa39ea5af8a5e213d6eae497
This commit is contained in:
Yuval Tassa
2026-02-06 08:46:45 -08:00
committed by Copybara-Service
parent 84fa527723
commit 6419534bad
48 changed files with 6282 additions and 219 deletions
+36
View File
@@ -6960,6 +6960,17 @@ void mjCActuator::Compile(void) {
throw mjCError(this, "plugin '%s' does not support actuators", pplugin->name);
}
}
// validate delay
if (delay > 0 && nsample <= 0) {
throw mjCError(this, "setting delay > 0 without a history buffer");
}
// nsample is limited to 2^24 because the cursor is stored as an mjtNum, which may be a float
// single-precision floats can represent all integers up to 2^24 exactly
if (nsample > 16777216) {
throw mjCError(this, "at most 2^24 samples in history buffer, got %d", nullptr, nsample);
}
}
@@ -7291,6 +7302,31 @@ void mjCSensor::Compile(void) {
throw mjCError(this, "negative cutoff in sensor");
}
// require non-negative interval
if (interval[0] < 0) {
throw mjCError(this, "negative interval in sensor");
}
// require non-positive phase
if (interval[1] > 0) {
throw mjCError(this, "positive phase in sensor");
}
// require phase > -period (values outside this are equivalent modulo period)
if (interval[0] > 0 && interval[1] <= -interval[0]) {
throw mjCError(this, "phase must be greater than -period in sensor");
}
// require nsample for delay
if (delay > 0 && nsample <= 0) {
throw mjCError(this, "setting delay > 0 without a history buffer");
}
// validate nsample size (max 2^24)
if (nsample > 16777216) {
throw mjCError(this, "at most 2^24 samples in sensor history buffer, got %d", nullptr, nsample);
}
// Find referenced object
ResolveReferences(model);