test_RobotWrapper.py
Go to the documentation of this file.
1 from pathlib import Path
2 
3 import numpy as np
4 import pinocchio as se3
5 
6 import tsid
7 
8 print("")
9 print("Test RobotWrapper")
10 print("")
11 
12 
13 filename = str(Path(__file__).resolve().parent)
14 path = filename + "/../../models/romeo"
15 urdf = path + "/urdf/romeo.urdf"
16 vector = se3.StdVec_StdString()
17 vector.extend(item for item in path)
18 
19 robot = tsid.RobotWrapper(urdf, vector, se3.JointModelFreeFlyer(), False)
20 model = robot.model()
21 lb = model.lowerPositionLimit
22 lb[0:3] = -10.0 * np.ones(3)
23 lb[3:7] = -1.0 * np.ones(4)
24 
25 ub = model.upperPositionLimit
26 ub[0:3] = 10.0 * np.ones(3)
27 ub[3:7] = 1.0 * np.ones(4)
28 
29 q = se3.randomConfiguration(robot.model(), lb, ub)
30 print(q.transpose())
31 
32 
33 data = robot.data()
34 v = np.ones(robot.nv)
35 robot.computeAllTerms(data, q, v)
36 print(robot.com(data))
37 base_mass_matrix = robot.mass(data)
38 
39 # Adding motor inertia
40 rng = np.random.default_rng()
41 rotor_inertia = rng.uniform(0, 1, size=(robot.nq - 7))
42 gear_ratio = rng.uniform(0, 1, size=(robot.nq - 7))
43 expected_inertia = rotor_inertia * gear_ratio**2
44 print(f"Expected motors inertia: {expected_inertia}")
45 
46 robot.set_rotor_inertias(rotor_inertia)
47 robot.set_gear_ratios(gear_ratio)
48 
49 robot.computeAllTerms(data, q, v)
50 
51 mass_matrix_with_motor_inertia = robot.mass(data)
52 
53 # Assert that mass matrices are different by motor's inertia
54 np.testing.assert_allclose(
55  np.diag(mass_matrix_with_motor_inertia - base_mass_matrix)[6:], expected_inertia
56 )
57 
58 
59 print("All test is done")


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Thu Apr 3 2025 02:47:16