Skip to content

Commit 401bf43

Browse files
thowellcopybara-github
authored andcommitted
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
1 parent edbdb51 commit 401bf43

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

simulate/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void PhysicsLoop(mj::Simulate& sim) {
381381
sim.speed_changed = false;
382382

383383
// inject noise
384-
sim.InjectNoise();
384+
sim.InjectNoise(sim.key);
385385

386386
// run single step, let next iteration deal with timing
387387
mj_step(m, d);
@@ -412,7 +412,7 @@ void PhysicsLoop(mj::Simulate& sim) {
412412
}
413413

414414
// inject noise
415-
sim.InjectNoise();
415+
sim.InjectNoise(sim.key);
416416

417417
// call mj_step
418418
mj_step(m, d);

simulate/simulate.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2917,7 +2917,7 @@ void Simulate::AddToHistory() {
29172917
}
29182918

29192919
// inject Brownian noise
2920-
void Simulate::InjectNoise() {
2920+
void Simulate::InjectNoise(int key) {
29212921
// no noise, return
29222922
if (ctrl_noise_std <= 0) {
29232923
return;
@@ -2936,6 +2936,11 @@ void Simulate::InjectNoise() {
29362936
halfrange = 0.5 * (top - bottom); // scales noise
29372937
}
29382938

2939+
// overwrite midpoint with keyframe, if given
2940+
if (key >= 0) {
2941+
midpoint = m_->key_ctrl[key*m_->nu+i];
2942+
}
2943+
29392944
// exponential convergence to midpoint at ctrl_noise_rate
29402945
d_->ctrl[i] = rate * d_->ctrl[i] + (1-rate) * midpoint;
29412946

simulate/simulate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Simulate {
8989
void AddToHistory();
9090

9191
// inject control noise
92-
void InjectNoise();
92+
void InjectNoise(int key);
9393

9494
// constants
9595
static constexpr int kMaxFilenameLength = 1000;
@@ -199,7 +199,7 @@ class Simulate {
199199
int busywait = 0;
200200

201201
// keyframe index
202-
int key = 0;
202+
int key = -1;
203203

204204
// index of history-scrubber slider
205205
int scrub_index = 0;

0 commit comments

Comments
 (0)