test_ContactPoint.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 import tsid
6 
7 print("")
8 print("Test Contact")
9 print("")
10 
11 tol = 1e-5
12 filename = str(Path(__file__).resolve().parent)
13 
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 robot = tsid.RobotWrapper(urdf, vector, se3.JointModelFreeFlyer(), False)
19 model = robot.model()
20 data = robot.data()
21 
22 mu = 0.3
23 fMin = 10.0
24 fMax = 1000.0
25 frameName = "RAnkleRoll"
26 contactNormal = np.zeros(3)
27 contactNormal[2] = 1.0
28 
29 contact = tsid.ContactPoint(
30  "contactPoint", robot, frameName, contactNormal, mu, fMin, fMax
31 )
32 
33 assert contact.n_motion == 3
34 assert contact.n_force == 3
35 
36 Kp = np.ones(3)
37 Kd = 2 * Kp
38 contact.setKp(Kp)
39 contact.setKd(Kd)
40 
41 assert np.linalg.norm(contact.Kp - Kp, 2) < tol
42 assert np.linalg.norm(contact.Kd - Kd, 2) < tol
43 
44 q = model.neutralConfiguration
45 v = np.zeros(robot.nv)
46 robot.computeAllTerms(data, q, v)
47 
48 H_ref = robot.position(data, robot.model().getJointId(frameName))
49 contact.setReference(H_ref)
50 
51 t = 0.0
52 contact.computeMotionTask(t, q, v, data)
53 forceIneq = contact.computeForceTask(t, q, v, data)
54 f = np.zeros(3)
55 f[2] = 100.0
56 
57 assert (forceIneq.matrix * f <= forceIneq.upperBound).all()
58 assert (forceIneq.matrix * f >= forceIneq.lowerBound).all()
59 
60 forceGenMat = contact.getForceGeneratorMatrix
61 assert forceGenMat.shape[0] == 3 and forceGenMat.shape[1] == 3
62 contact.computeForceRegularizationTask(t, q, v, data)
63 
64 print("All test is done")


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