floating-base-velocity-viewer.py
Go to the documentation of this file.
1 from time import sleep
2 
3 import hppfcl
4 import numpy as np
5 import pinocchio as pin
6 from pinocchio.visualize import MeshcatVisualizer
7 
8 
9 def create_pin_cube_model(j0="freeflyer"):
10  model = pin.Model()
11 
12  if j0 == "freeflyer":
13  j0 = pin.JointModelFreeFlyer()
14  elif j0 == "spherical":
15  j0 = pin.JointModelSpherical()
16  elif j0 == "sphericalzyx":
17  j0 = pin.JointModelSphericalZYX()
18  else:
19  raise ValueError("Unknown joint type")
20 
21  jointCube = model.addJoint(0, j0, pin.SE3.Identity(), "joint0")
22  M = pin.SE3.Identity()
23  model.appendBodyToJoint(jointCube, pin.Inertia.FromBox(1, 0.8, 0.4, 0.2), M)
24  return model
25 
26 
28  jointCube = model.getFrameId("joint0")
29  geom_model = pin.GeometryModel()
30  cube_shape = hppfcl.Box(0.8, 0.4, 0.2) # x, y, z
31  cube = pin.GeometryObject(
32  "cube_shape", 0, jointCube, cube_shape, pin.SE3.Identity()
33  )
34  cube.meshColor = np.array([1.0, 0.1, 0.1, 0.5])
35  geom_model.addGeometryObject(cube)
36  return geom_model
37 
38 
39 def create_model(joint0_type="freeflyer"):
40  model = create_pin_cube_model(joint0_type)
41  geom_model = create_pin_geometry_cube_model(model)
42  return model, geom_model
43 
44 
45 def pin_step(model, vizer, v_index_increment, dt=0.1):
46  q = pin.neutral(model)
47  v = np.zeros(model.nv)
48  v[v_index_increment] += 1.0
49 
50  vizer.display(q)
51  print(f"{q=}, {v=}")
52 
53  sleep(1)
54 
55  q_next = pin.integrate(model, q, v * dt)
56 
57  print(f"{q_next=}")
58  return q_next
59 
60 
61 if __name__ == "__main__":
62  list_joint0 = ["freeflyer", "sphericalzyx", "spherical"]
63 
64  for joint0_name in list_joint0:
65  print(f"\njoint0_name = {joint0_name}")
66 
67  model, geom_model = create_model(joint0_name)
68  print(f"{model.nq=}")
69  print(f"{model.nv=}")
70 
71  q = pin.neutral(model)
72  print(f"neutral q configuration: {q=}")
73 
74  vizer = MeshcatVisualizer(model, geom_model, geom_model)
75  vizer.initViewer(open=True, loadModel=True)
76  vizer.display(q)
77 
78  sleep(2)
79 
80  for i in range(model.nv):
81  print(f"v[{i}] += 1")
82  q_next = pin_step(model, vizer, i, dt=0.2)
83  vizer.display(q_next)
84  sleep(2)
floating-base-velocity-viewer.create_pin_cube_model
def create_pin_cube_model(j0="freeflyer")
Definition: floating-base-velocity-viewer.py:9
pinocchio.visualize
Definition: bindings/python/pinocchio/visualize/__init__.py:1
floating-base-velocity-viewer.create_model
def create_model(joint0_type="freeflyer")
Definition: floating-base-velocity-viewer.py:39
floating-base-velocity-viewer.pin_step
def pin_step(model, vizer, v_index_increment, dt=0.1)
Definition: floating-base-velocity-viewer.py:45
pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer
Definition: meshcat_visualizer.py:576
floating-base-velocity-viewer.create_pin_geometry_cube_model
def create_pin_geometry_cube_model(model)
Definition: floating-base-velocity-viewer.py:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:29