Skip to content

Commit 8335648

Browse files
ping pong
1 parent 380855c commit 8335648

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { GamepadController } from "./gamepad_controller.js"
88
import { Position } from "./trajectories/position.js"
99
import { Lissajous } from "./trajectories/lissajous.js"
1010
import { SecondOrderLangevin } from "./trajectories/langevin.js"
11+
import { PingPong } from "./trajectories/ping_pong.js"
1112
// import Controller from "./controller.js"
1213

1314
// check url for "file" parameter
@@ -119,7 +120,10 @@ class Policy{
119120
let input = math.matrix([observation_description.split(".").map(x => this.get_observation(state, x)).flat()])
120121
const reference = references[i]
121122
reference.forEach((x, i) => {
122-
input._data[0][i] = input._data[0][i] - x
123+
const value_raw = input._data[0][i] - x;
124+
const clip = (x, min, max) => x < min ? min : (x > max ? max : x);
125+
const value_clip = i < 3 ? clip(value_raw, -1, 1) : clip(value_raw, -2, 2);
126+
input._data[0][i] = value_clip
123127
})
124128
const [output, new_state] = model.evaluate_step(input, this.policy_states[i])
125129
this.policy_states[i] = new_state
@@ -216,7 +220,7 @@ async function main() {
216220
trajectory_offset_value.textContent = trajectory_offset.toFixed(2)
217221
})
218222
const trajectory_select = document.getElementById("reference-trajectory")
219-
const trajectories = { "Position": Position, "Lissajous": Lissajous, "Langevin": SecondOrderLangevin}
223+
const trajectories = { "Position": Position, "Lissajous": Lissajous, "Langevin": SecondOrderLangevin, "Ping Pong": PingPong }
220224
trajectory_select.innerHTML = ""
221225
for (const name in trajectories) {
222226
trajectory_select.innerHTML += `<option value="${name}">${name}</option>`

trajectories/ping_pong.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import { Trajectory } from "./base.js"
3+
export class PingPong extends Trajectory{
4+
constructor(){
5+
super({
6+
"period": {"range": [1, 15], "default": 5},
7+
"scale": {"range": [0, 5], "default": 0.1},
8+
})
9+
}
10+
evaluate(t){
11+
const scale = this.parameter_values.scale
12+
const duration = this.parameter_values.period
13+
const progress = t % duration
14+
const ping = progress < duration / 2
15+
return [ping ? scale : - scale, 0, 0, 0, 0, 0]
16+
}
17+
}

0 commit comments

Comments
 (0)