meshcat-viewer-solo.py
Go to the documentation of this file.
1 """
2 Pose a Solo-12 robot on a surface defined through a function and displayed through an
3 hppfcl.HeightField.
4 """
5 
6 import time
7 from pathlib import Path
8 
9 import numpy as np
10 import pinocchio as pin
11 from pinocchio.visualize import MeshcatVisualizer
12 
13 # Load the URDF model.
14 # Conversion with str seems to be necessary when executing this file with ipython
15 pinocchio_model_dir = Path(__file__).parent.parent / "models"
16 
17 model_path = pinocchio_model_dir / "example-robot-data/robots"
18 mesh_dir = pinocchio_model_dir
19 urdf_filename = "solo12.urdf"
20 urdf_model_path = model_path / "solo_description/robots" / urdf_filename
21 
22 model, collision_model, visual_model = pin.buildModelsFromUrdf(
23  urdf_model_path, mesh_dir, pin.JointModelFreeFlyer()
24 )
25 
26 q_ref = np.array(
27  [
28  [0.09906518],
29  [0.20099078],
30  [0.32502457],
31  [0.19414175],
32  [-0.00524735],
33  [-0.97855773],
34  [0.06860185],
35  [0.00968163],
36  [0.60963582],
37  [-1.61206407],
38  [-0.02543309],
39  [0.66709088],
40  [-1.50870083],
41  [0.32405118],
42  [-1.15305599],
43  [1.56867351],
44  [-0.39097222],
45  [-1.29675892],
46  [1.39741073],
47  ]
48 )
49 
50 
51 vizer = MeshcatVisualizer(model, collision_model, visual_model)
52 vizer.initViewer(open=True)
53 
54 
55 def ground(xy):
56  return (
57  np.sin(xy[0] * 3) / 5
58  + np.cos(xy[1] ** 2 * 3) / 20
59  + np.sin(xy[1] * xy[0] * 5) / 10
60  )
61 
62 
63 def vizGround(viz, elevation_fn, space, name="ground", color=[1.0, 1.0, 0.6, 0.8]):
64  xg = np.arange(-2, 2, space)
65  nx = xg.shape[0]
66  xy_g = np.meshgrid(xg, xg)
67  xy_g = np.stack(xy_g)
68  elev_g = np.zeros((nx, nx))
69  elev_g[:, :] = elevation_fn(xy_g)
70 
71  sx = xg[-1] - xg[0]
72  sy = xg[-1] - xg[0]
73  elev_g[:, :] = elev_g[::-1, :]
74  import hppfcl
75 
76  heightField = hppfcl.HeightFieldAABB(sx, sy, elev_g, np.min(elev_g))
77  pl = pin.SE3.Identity()
78  obj = pin.GeometryObject("ground", 0, pl, heightField)
79  obj.meshColor[:] = color
80  viz.addGeometryObject(obj)
81 
82 
83 # Load the robot in the viewer.
84 vizer.loadViewerModel()
85 
86 colorrgb = [128, 149, 255, 200]
87 colorrgb = np.array(colorrgb) / 255.0
88 vizGround(vizer, ground, 0.02, color=colorrgb)
89 
90 vizer.display(q_ref)
91 time.sleep(1.0)
pinocchio.visualize
Definition: bindings/python/pinocchio/visualize/__init__.py:1
meshcat-viewer-solo.ground
def ground(xy)
Definition: meshcat-viewer-solo.py:55
pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer
Definition: meshcat_visualizer.py:576
meshcat-viewer-solo.vizGround
def vizGround(viz, elevation_fn, space, name="ground", color=[1.0, 1.0, 0.6, 0.8])
Definition: meshcat-viewer-solo.py:63


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:11