Skip to content

Fix meshcat examples #2503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix mjcf parsing of armature and of the default tag in models ([#2477](https://github.com/stack-of-tasks/pinocchio/pull/2477))
- Fix undefined behavior when using the site attribute in mjcf ([#2477](https://github.com/stack-of-tasks/pinocchio/pull/2477))
- Fix the type of image paths when loading textures in the meshcat visualizer ([#2478](https://github.com/stack-of-tasks/pinocchio/pull/2478))
- Fix meshcat examples ([#2503])[https://github.com/stack-of-tasks/pinocchio/pull/2503]

### Changed
- On GNU/Linux and macOS, hide all symbols by default ([#2469](https://github.com/stack-of-tasks/pinocchio/pull/2469))
Expand Down
2 changes: 2 additions & 0 deletions examples/append-urdf-model-with-another-model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import sys
import time
from pathlib import Path

import hppfcl as fcl
Expand Down Expand Up @@ -91,3 +92,4 @@
model.upperPositionLimit.fill(+math.pi / 2)
q = pin.randomConfiguration(model)
viz.display(q)
time.sleep(1.0)
2 changes: 2 additions & 0 deletions examples/collision-with-point-clouds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# pip install --user meshcat

import sys
import time
from pathlib import Path

import hppfcl as fcl
Expand Down Expand Up @@ -123,3 +124,4 @@

print("Found a configuration in collision:", q)
viz.display(q)
time.sleep(1.0)
3 changes: 2 additions & 1 deletion examples/meshcat-viewer-octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# pip install --user meshcat

import sys
import time

import hppfcl as fcl
import numpy as np
Expand Down Expand Up @@ -47,4 +48,4 @@
sys.exit(0)

viz.loadViewerModel()
viz.clearDefaultLights()
time.sleep(1.0)
27 changes: 21 additions & 6 deletions examples/meshcat-viewer-solo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
hppfcl.HeightField.
"""

import time
from pathlib import Path

import numpy as np
import pinocchio as pin
from example_robot_data import load
from pinocchio.visualize import MeshcatVisualizer

robot = load("solo12")
# Load the URDF model.
# Conversion with str seems to be necessary when executing this file with ipython
pinocchio_model_dir = Path(__file__).parent.parent / "models"

model_path = pinocchio_model_dir / "example-robot-data/robots"
mesh_dir = pinocchio_model_dir
urdf_filename = "solo12.urdf"
urdf_model_path = model_path / "solo_description/robots" / urdf_filename

model, collision_model, visual_model = pin.buildModelsFromUrdf(
urdf_model_path, mesh_dir, pin.JointModelFreeFlyer()
)

q_ref = np.array(
[
Expand All @@ -35,9 +48,8 @@
)


model = robot.model
vizer = MeshcatVisualizer(model, robot.collision_model, robot.visual_model)
vizer.initViewer(loadModel=True)
vizer = MeshcatVisualizer(model, collision_model, visual_model)
vizer.initViewer(open=True)


def ground(xy):
Expand Down Expand Up @@ -66,11 +78,14 @@ def vizGround(viz, elevation_fn, space, name="ground", color=[1.0, 1.0, 0.6, 0.8
obj = pin.GeometryObject("ground", 0, pl, heightField)
obj.meshColor[:] = color
viz.addGeometryObject(obj)
viz.viewer.open()


# Load the robot in the viewer.
vizer.loadViewerModel()

colorrgb = [128, 149, 255, 200]
colorrgb = np.array(colorrgb) / 255.0
vizGround(vizer, ground, 0.02, color=colorrgb)

vizer.display(q_ref)
time.sleep(1.0)
Loading