|
511 | 511 | " point2[0], point2[1], point2[2])\n", |
512 | 512 | "\n", |
513 | 513 | " # traces of time, position and speed\n", |
514 | | - "time = []\n", |
515 | | - "position = []\n", |
516 | | - "speed = []\n", |
| 514 | + "times = []\n", |
| 515 | + "positions = []\n", |
| 516 | + "speeds = []\n", |
517 | 517 | "offset = physics.model.jnt_axis[0]/8 # offset along the joint axis\n", |
518 | 518 | "\n", |
519 | 519 | "def scene_callback(physics, scn):\n", |
520 | 520 | " \"\"\"Draw position trace, speed modifies width and colours.\"\"\"\n", |
521 | | - " if len(position) \u003e 1:\n", |
522 | | - " for i in range(len(position)-1):\n", |
523 | | - " rgba=np.array((np.clip(speed[i]/10, 0, 1),\n", |
524 | | - " np.clip(1-speed[i]/10, 0, 1),\n", |
| 521 | + " if len(positions) \u003e 1:\n", |
| 522 | + " for i in range(len(positions)-1):\n", |
| 523 | + " rgba=np.array((np.clip(speeds[i]/10, 0, 1),\n", |
| 524 | + " np.clip(1-speeds[i]/10, 0, 1),\n", |
525 | 525 | " .5, 1.))\n", |
526 | | - " radius=.003*(1+speed[i])\n", |
527 | | - " point1 = position[i] + offset*time[i]\n", |
528 | | - " point2 = position[i+1] + offset*time[i+1]\n", |
| 526 | + " radius=.003*(1+speeds[i])\n", |
| 527 | + " point1 = positions[i] + offset*times[i]\n", |
| 528 | + " point2 = positions[i+1] + offset*times[i+1]\n", |
529 | 529 | " add_visual_capsule(scn, point1, point2, radius, rgba)\n", |
530 | 530 | "\n", |
531 | 531 | "duration = 6 # (seconds)\n", |
|
536 | 536 | "physics.reset() # Reset state and time\n", |
537 | 537 | "while physics.data.time \u003c duration:\n", |
538 | 538 | " # append data to the traces\n", |
539 | | - " position.append(physics.named.data.geom_xpos[\"green_sphere\"].copy())\n", |
540 | | - " time.append(physics.data.time)\n", |
541 | | - " speed.append(get_geom_speed(physics, \"green_sphere\"))\n", |
| 539 | + " positions.append(physics.named.data.geom_xpos[\"green_sphere\"].copy())\n", |
| 540 | + " times.append(physics.data.time)\n", |
| 541 | + " speeds.append(get_geom_speed(physics, \"green_sphere\"))\n", |
542 | 542 | " physics.step()\n", |
543 | 543 | " if len(frames) \u003c physics.data.time * framerate:\n", |
544 | 544 | " camera = mujoco.Camera(physics, max_geom=10000,\n", |
|
0 commit comments