update-model-after-urdf.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2023 Inria
4 
5 import numpy as np
6 
7 try:
8  from robot_descriptions.loaders.pinocchio import load_robot_description
9 except ModuleNotFoundError:
10  print("This example loads robot descriptions from robot_descriptions.py:")
11  print("\n\tpip install robot_descriptions")
12 
13 print("Goal: load a legged robot from its URDF, then modify leg lengths")
14 
15 print("Loading robot description from URDF...")
16 robot = load_robot_description("upkie_description")
17 model = robot.model
18 
19 # Joint placement offsets compared to the leg length
20 # We know from the robot description that both are along the local y-axis
21 known_offsets = {"knee": 0.072, "wheel": 0.065}
22 
23 
24 def check_limb_lengths(limb_length: float) -> bool:
25  print(f"Checking that limbs are {limb_length} m long... ", end="")
26  for side in ("left", "right"):
27  for joint in ("knee", "wheel"):
28  joint_id = model.getJointId(f"{side}_{joint}")
29  if not np.allclose(
30  model.jointPlacements[joint_id].translation[1],
31  limb_length - known_offsets[joint],
32  ):
33  print("{side}_{joint} placement is wrong!")
34  return False
35  return True
36 
37 
38 # We know from the description that the leg length should be 24 cm
39 if check_limb_lengths(0.24):
40  print("OK, the model is as we expect it")
41 
42 
43 def update_limb_lengths(length: float) -> None:
44  """Update femur and tibia lengths in the robot model.
45 
46  Args:
47  length: New femur and tibia length, in meters.
48  """
49  for side in ("left", "right"):
50  for joint in ("knee", "wheel"):
51  joint_id = model.getJointId(f"{side}_{joint}")
52  model.jointPlacements[joint_id].translation[1] = (
53  length - known_offsets[joint]
54  )
55 
56 
57 update_limb_lengths(0.3) # update femurs and tibias to 30 cm
58 if check_limb_lengths(0.3):
59  print("OK, the update worked!")
update-model-after-urdf.check_limb_lengths
bool check_limb_lengths(float limb_length)
Definition: update-model-after-urdf.py:24
update-model-after-urdf.update_limb_lengths
None update_limb_lengths(float length)
Definition: update-model-after-urdf.py:43


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