Modify Simulate::InjectNoise to set target of exponential decay to value from key_ctrl if a valid key is provided as input.

PiperOrigin-RevId: 813819040
Change-Id: I79508039b17fb3484b71ae0d19614c32adacfa10
This commit is contained in:
Taylor Howell
2025-10-01 10:45:26 -07:00
committed by Copybara-Service
parent edbdb5195c
commit 401bf431b8
3 changed files with 10 additions and 5 deletions
+2 -2
View File
@@ -381,7 +381,7 @@ void PhysicsLoop(mj::Simulate& sim) {
sim.speed_changed = false; sim.speed_changed = false;
// inject noise // inject noise
sim.InjectNoise(); sim.InjectNoise(sim.key);
// run single step, let next iteration deal with timing // run single step, let next iteration deal with timing
mj_step(m, d); mj_step(m, d);
@@ -412,7 +412,7 @@ void PhysicsLoop(mj::Simulate& sim) {
} }
// inject noise // inject noise
sim.InjectNoise(); sim.InjectNoise(sim.key);
// call mj_step // call mj_step
mj_step(m, d); mj_step(m, d);
+6 -1
View File
@@ -2917,7 +2917,7 @@ void Simulate::AddToHistory() {
} }
// inject Brownian noise // inject Brownian noise
void Simulate::InjectNoise() { void Simulate::InjectNoise(int key) {
// no noise, return // no noise, return
if (ctrl_noise_std <= 0) { if (ctrl_noise_std <= 0) {
return; return;
@@ -2936,6 +2936,11 @@ void Simulate::InjectNoise() {
halfrange = 0.5 * (top - bottom); // scales noise halfrange = 0.5 * (top - bottom); // scales noise
} }
// overwrite midpoint with keyframe, if given
if (key >= 0) {
midpoint = m_->key_ctrl[key*m_->nu+i];
}
// exponential convergence to midpoint at ctrl_noise_rate // exponential convergence to midpoint at ctrl_noise_rate
d_->ctrl[i] = rate * d_->ctrl[i] + (1-rate) * midpoint; d_->ctrl[i] = rate * d_->ctrl[i] + (1-rate) * midpoint;
+2 -2
View File
@@ -89,7 +89,7 @@ class Simulate {
void AddToHistory(); void AddToHistory();
// inject control noise // inject control noise
void InjectNoise(); void InjectNoise(int key);
// constants // constants
static constexpr int kMaxFilenameLength = 1000; static constexpr int kMaxFilenameLength = 1000;
@@ -199,7 +199,7 @@ class Simulate {
int busywait = 0; int busywait = 0;
// keyframe index // keyframe index
int key = 0; int key = -1;
// index of history-scrubber slider // index of history-scrubber slider
int scrub_index = 0; int scrub_index = 0;