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 numpy as np
7 import pinocchio as pin
8 from example_robot_data import load
9 from pinocchio.visualize import MeshcatVisualizer
10 
11 robot = load("solo12")
12 
13 q_ref = np.array(
14  [
15  [0.09906518],
16  [0.20099078],
17  [0.32502457],
18  [0.19414175],
19  [-0.00524735],
20  [-0.97855773],
21  [0.06860185],
22  [0.00968163],
23  [0.60963582],
24  [-1.61206407],
25  [-0.02543309],
26  [0.66709088],
27  [-1.50870083],
28  [0.32405118],
29  [-1.15305599],
30  [1.56867351],
31  [-0.39097222],
32  [-1.29675892],
33  [1.39741073],
34  ]
35 )
36 
37 
38 model = robot.model
39 vizer = MeshcatVisualizer(model, robot.collision_model, robot.visual_model)
40 vizer.initViewer(loadModel=True)
41 
42 
43 def ground(xy):
44  return (
45  np.sin(xy[0] * 3) / 5
46  + np.cos(xy[1] ** 2 * 3) / 20
47  + np.sin(xy[1] * xy[0] * 5) / 10
48  )
49 
50 
51 def vizGround(viz, elevation_fn, space, name="ground", color=[1.0, 1.0, 0.6, 0.8]):
52  xg = np.arange(-2, 2, space)
53  nx = xg.shape[0]
54  xy_g = np.meshgrid(xg, xg)
55  xy_g = np.stack(xy_g)
56  elev_g = np.zeros((nx, nx))
57  elev_g[:, :] = elevation_fn(xy_g)
58 
59  sx = xg[-1] - xg[0]
60  sy = xg[-1] - xg[0]
61  elev_g[:, :] = elev_g[::-1, :]
62  import hppfcl
63 
64  heightField = hppfcl.HeightFieldAABB(sx, sy, elev_g, np.min(elev_g))
65  pl = pin.SE3.Identity()
66  obj = pin.GeometryObject("ground", 0, pl, heightField)
67  obj.meshColor[:] = color
68  viz.addGeometryObject(obj)
69  viz.viewer.open()
70 
71 
72 colorrgb = [128, 149, 255, 200]
73 colorrgb = np.array(colorrgb) / 255.0
74 vizGround(vizer, ground, 0.02, color=colorrgb)
75 
76 vizer.display(q_ref)
pinocchio.visualize
Definition: bindings/python/pinocchio/visualize/__init__.py:1
boost::serialization::load
void load(Archive &ar, Eigen::array< _IndexType, _NumIndices > &a, const unsigned int)
Definition: serialization/eigen.hpp:241
meshcat-viewer-solo.ground
def ground(xy)
Definition: meshcat-viewer-solo.py:43
pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer
Definition: meshcat_visualizer.py:540
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:51


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:47