test_Contact.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 Contact")
10 print("")
11 
12 tol = 1e-5
13 
14 filename = str(Path(__file__).resolve().parent)
15 path = filename + "/../models/romeo"
16 urdf = path + "/urdf/romeo.urdf"
17 vector = se3.StdVec_StdString()
18 vector.extend(item for item in path)
19 robot = tsid.RobotWrapper(urdf, vector, se3.JointModelFreeFlyer(), False)
20 model = robot.model()
21 data = robot.data()
22 
23 lx = 0.07
24 ly = 0.12
25 lz = 0.105
26 mu = 0.3
27 fMin = 10.0
28 fMax = 1000.0
29 frameName = "RAnkleRoll"
30 
31 contactNormal = np.matrix(np.zeros(3)).transpose()
32 contactNormal[2] = 1.0
33 contact_Point = np.matrix(np.ones((3, 4)) * lz)
34 contact_Point[0, :] = [-lx, -lx, lx, lx]
35 contact_Point[1, :] = [-ly, ly, -ly, ly]
36 
37 contact = tsid.Contact6d(
38  "contact6d", robot, frameName, contact_Point, contactNormal, mu, fMin, fMax, 1e-3
39 )
40 
41 assert contact.n_motion == 6
42 assert contact.n_force == 12
43 
44 Kp = np.matrix(np.ones(6)).transpose()
45 Kd = 2 * Kp
46 contact.setKp(Kp)
47 contact.setKd(Kd)
48 
49 assert np.linalg.norm(contact.Kp - Kp, 2) < tol
50 assert np.linalg.norm(contact.Kd - Kd, 2) < tol
51 
52 q = model.neutralConfiguration
53 v = np.matrix(np.zeros(robot.nv)).transpose()
54 robot.computeAllTerms(data, q, v)
55 
56 H_ref = robot.position(data, robot.model().getJointId(frameName))
57 contact.setReference(H_ref)
58 
59 t = 0.0
60 contact.computeMotionTask(t, q, v, data)
61 forceIneq = contact.computeForceTask(t, q, v, data)
62 f3 = np.matrix(np.zeros(3)).transpose()
63 f3[2] = 100.0
64 f = np.matrix(np.zeros(12)).transpose()
65 for i in range(0, 4):
66  f[i * 3 : 3 * (i + 1)] = f3
67 
68 assert (forceIneq.matrix * f <= forceIneq.upperBound).all()
69 assert (forceIneq.matrix * f >= forceIneq.lowerBound).all()
70 
71 forceGenMat = contact.getForceGeneratorMatrix
72 assert forceGenMat.shape[0] == 6 and forceGenMat.shape[1] == 12
73 contact.computeForceRegularizationTask(t, q, v, data)
74 
75 print("All test is done")


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Sat May 3 2025 02:48:17