Skip to content

Commit 80a7ed0

Browse files
authored
Hotfix viser traces (#107)
* Fixed viser and mujoco vis API issuse * Added changes to changelog * Added pycparser to deps * Updated pixi lock * Added John's more general changes to handle multi-colored splines * Updated changelog and new package version * Fixing the pixi lock file to be compatible with judo 0.0.6
1 parent f25051a commit 80a7ed0

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# v0.0.6
2+
3+
## Added
4+
* New copyrights
5+
6+
## Fixed
7+
* Fixed bug that caused Viser and Mujoco to crash on visualization due to different API
8+
* Added pycparser deps
9+
* Fixed a new mujoco API compatibility
10+
111
# v0.0.5
212

313
## Added

judo/visualizers/model.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,17 @@ def add_traces(
211211
rgb=DEFAULT_BEST_SPLINE_COLOR,
212212
)
213213
)
214-
self._traces[0].colors = np.tile(self._traces[0].colors[0, :, :], (all_traces_rollout_size, 1, 1))
214+
215+
# In viser 1.0.16+, colors can be shape (3,) if a single color was passed, or (N, 2, 3) if array was passed
216+
# We need to handle both cases
217+
if all_traces_rollout_size > 0:
218+
if self._traces[0].colors.ndim == 1:
219+
# Single color was stored, expand to (N, 2, 3) shape
220+
self._traces[0].colors = np.tile(self._traces[0].colors, (all_traces_rollout_size, 2, 1))
221+
else:
222+
# Already (N, 2, 3), just tile the first segment
223+
self._traces[0].colors = np.tile(self._traces[0].colors[:1, :, :], (all_traces_rollout_size, 1, 1))
224+
215225
if (rest_trace_size := num_traces - all_traces_rollout_size) > 0:
216226
self._traces.append(
217227
add_segments(
@@ -221,7 +231,12 @@ def add_traces(
221231
rgb=DEFAULT_SPLINE_COLOR,
222232
)
223233
)
224-
self._traces[1].colors = np.tile(self._traces[1].colors[0, :, :], (rest_trace_size, 1, 1))
234+
if self._traces[1].colors.ndim == 1:
235+
# Single color was stored, expand to (N, 2, 3) shape
236+
self._traces[1].colors = np.tile(self._traces[1].colors, (rest_trace_size, 2, 1))
237+
else:
238+
# Already (N, 2, 3), just tile the first segment
239+
self._traces[1].colors = np.tile(self._traces[1].colors[:1, :, :], (rest_trace_size, 1, 1))
225240

226241
def remove_traces(self) -> None:
227242
"""Remove traces."""
@@ -236,7 +251,7 @@ def set_data(self, data: MjData) -> None:
236251
# Use atomic to update both position/orientation synchronously.
237252
with self._target.atomic():
238253
# Line up order of bodies in spec with order of bodies in model.
239-
data_idx = self._spec.bodies[i].id
254+
data_idx = self._model.body(self._spec.bodies[i].name).id
240255
self._bodies[i].position = tuple(data.xpos[data_idx])
241256
self._bodies[i].wxyz = tuple(data.xquat[data_idx])
242257

pixi.lock

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
55
[project]
66
name = "judo-rai"
77
description = "Judo: a hackable sampling-based MPC toolbox"
8-
version = "0.0.5"
8+
version = "0.0.6"
99
readme = "README.md"
1010
license = { file = "LICENSE" }
1111
authors = [
@@ -33,6 +33,7 @@ dependencies = [
3333
"mujoco",
3434
"numpy",
3535
"pillow", # for displaying app logo
36+
"pycparser",
3637
"requests", # for sharing GUI link
3738
"rich", # for displaying tables in benchmarking
3839
"scipy",

0 commit comments

Comments
 (0)