bindings_contact_inverse_dynamics.py
Go to the documentation of this file.
1 import unittest
2 from pathlib import Path
3 
4 import numpy as np
5 import pinocchio as pin
6 from test_case import PinocchioTestCase as TestCase
7 
8 
9 @unittest.skipUnless(pin.WITH_URDFDOM, "Needs URDFDOM")
11  def setUp(self):
12  self.current_dir = Path(__file__).parent
13  self.model_dir = self.current_dir / "../../models"
14  self.model_path = self.model_dir / "example-robot-data/robots/talos_data"
15  self.urdf_filename = "talos_reduced.urdf"
16  self.srdf_filename = "talos.srdf"
17  self.urdf_model_path = self.model_path / "robots" / self.urdf_filename
18  self.srdf_full_path = self.model_path / "srdf" / self.srdf_filename
19 
20  def load_model(self):
21  self.model = pin.buildModelFromUrdf(
22  self.urdf_model_path, pin.JointModelFreeFlyer()
23  )
24  pin.loadReferenceConfigurations(self.model, self.srdf_full_path)
25  self.q0 = self.model.referenceConfigurations["half_sitting"]
26 
28  self.load_model()
29  model = self.model
30  feet_name = ["left_sole_link", "right_sole_link"]
31  frame_ids = [model.getFrameId(frame_name) for frame_name in feet_name]
32 
33  q = self.q0
34  v = np.zeros(model.nv)
35  a = np.zeros(model.nv)
36  data = model.createData()
37 
38  contact_models_list = []
39  contact_datas_list = []
40  cones_list = []
41 
42  contact_models_vec = pin.StdVec_RigidConstraintModel()
43  contact_datas_vec = pin.StdVec_RigidConstraintData()
44  cones_vec = pin.StdVec_CoulombFrictionCone()
45 
46  for frame_id in frame_ids:
47  frame = model.frames[frame_id]
48  contact_model = pin.RigidConstraintModel(
49  pin.ContactType.CONTACT_3D, model, frame.parentJoint, frame.placement
50  )
51 
52  contact_models_list.append(contact_model)
53  contact_datas_list.append(contact_model.createData())
54  cones_list.append(pin.CoulombFrictionCone(0.4))
55 
56  contact_models_vec.append(contact_model)
57  contact_datas_vec.append(contact_model.createData())
58  cones_vec.append(pin.CoulombFrictionCone(0.4))
59 
60  constraint_dim = 0
61  for m in contact_models_list:
62  constraint_dim += m.size()
63 
64  dt = 1e-3
65  R = np.zeros(constraint_dim)
66  constraint_correction = np.zeros(constraint_dim)
67  lambda_guess = np.zeros(constraint_dim)
68  prox_settings = pin.ProximalSettings(1e-12, 1e-6, 1)
69  # pin.initConstraintDynamics(model, data, contact_models_list) # not needed
70 
71  # test 1 with vector of contact models, contact datas and cones
72  tau1 = pin.contactInverseDynamics(
73  model,
74  data,
75  q,
76  v,
77  a,
78  dt,
79  contact_models_vec,
80  contact_datas_vec,
81  cones_vec,
82  R,
83  constraint_correction,
84  prox_settings,
85  lambda_guess,
86  )
87 
88  # test 2 with list of contact models, cones
89  tau2 = pin.contactInverseDynamics(
90  model,
91  data,
92  q,
93  v,
94  a,
95  dt,
96  contact_models_list,
97  contact_datas_vec,
98  cones_list,
99  R,
100  constraint_correction,
101  prox_settings,
102  lambda_guess,
103  )
104 
105  # test 3 with list of contact models, contact datas and cones
106  tau3 = pin.contactInverseDynamics(
107  model,
108  data,
109  q,
110  v,
111  a,
112  dt,
113  contact_models_list,
114  contact_datas_list,
115  cones_list,
116  R,
117  constraint_correction,
118  prox_settings,
119  lambda_guess,
120  )
121  self.assertApprox(tau1, tau2)
122  self.assertApprox(tau1, tau3)
123 
124 
125 if __name__ == "__main__":
126  unittest.main()
bindings_contact_inverse_dynamics.TestContactInverseDynamics.load_model
def load_model(self)
Definition: bindings_contact_inverse_dynamics.py:20
bindings_contact_inverse_dynamics.TestContactInverseDynamics.srdf_full_path
srdf_full_path
Definition: bindings_contact_inverse_dynamics.py:18
bindings_contact_inverse_dynamics.TestContactInverseDynamics.test_call_to_contact_inverse_dynamics
def test_call_to_contact_inverse_dynamics(self)
Definition: bindings_contact_inverse_dynamics.py:27
bindings_contact_inverse_dynamics.TestContactInverseDynamics.model_dir
model_dir
Definition: bindings_contact_inverse_dynamics.py:13
bindings_contact_inverse_dynamics.TestContactInverseDynamics.srdf_filename
srdf_filename
Definition: bindings_contact_inverse_dynamics.py:16
bindings_contact_inverse_dynamics.TestContactInverseDynamics.model
model
Definition: bindings_contact_inverse_dynamics.py:21
bindings_contact_inverse_dynamics.TestContactInverseDynamics.urdf_model_path
urdf_model_path
Definition: bindings_contact_inverse_dynamics.py:17
bindings_contact_inverse_dynamics.TestContactInverseDynamics
Definition: bindings_contact_inverse_dynamics.py:10
bindings_contact_inverse_dynamics.TestContactInverseDynamics.setUp
def setUp(self)
Definition: bindings_contact_inverse_dynamics.py:11
bindings_contact_inverse_dynamics.TestContactInverseDynamics.q0
q0
Definition: bindings_contact_inverse_dynamics.py:25
bindings_contact_inverse_dynamics.TestContactInverseDynamics.urdf_filename
urdf_filename
Definition: bindings_contact_inverse_dynamics.py:15
bindings_contact_inverse_dynamics.TestContactInverseDynamics.current_dir
current_dir
Definition: bindings_contact_inverse_dynamics.py:12
bindings_contact_inverse_dynamics.TestContactInverseDynamics.model_path
model_path
Definition: bindings_contact_inverse_dynamics.py:14


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