1 from pathlib
import Path
4 import pinocchio
as se3
6 from numpy.linalg
import norm
12 filename = str(Path(__file__).resolve().parent)
13 path = filename +
"/../../models/romeo"
14 urdf = path +
"/urdf/romeo.urdf"
15 vector = se3.StdVec_StdString()
16 vector.extend(item
for item
in path)
17 robot = tsid.RobotWrapper(urdf, vector, se3.JointModelFreeFlyer(),
False)
19 srdf = path +
"/srdf/romeo_collision.srdf"
22 se3.loadReferenceConfigurations(model, srdf,
False)
23 q = model.referenceConfigurations[
"half_sitting"]
26 v = np.zeros(robot.nv)
37 rf_frame_name =
"RAnkleRoll"
38 lf_frame_name =
"LAnkleRoll"
39 contactNormal = np.array([0.0, 0.0, 1.0])
47 assert robot.model().existFrame(rf_frame_name)
48 assert robot.model().existFrame(lf_frame_name)
51 invdyn.computeProblemData(t, q, v)
53 contact_Point = np.ones((3, 4)) * lz
54 contact_Point[0, :] = [-lxn, -lxn, lxp, lxp]
55 contact_Point[1, :] = [-lyn, lyp, -lyn, lyp]
57 contactRF = tsid.Contact6d(
68 contactRF.setKp(kp_contact * np.ones(6))
69 contactRF.setKd(2.0 * np.sqrt(kp_contact) * np.ones(6))
70 H_rf_ref = robot.position(data, robot.model().getJointId(rf_frame_name))
71 contactRF.setReference(H_rf_ref)
72 invdyn.addRigidContact(contactRF)
74 contactLF = tsid.Contact6d(
85 contactLF.setKp(kp_contact * np.ones(6))
86 contactLF.setKd(2.0 * np.sqrt(kp_contact) * np.ones(6))
87 H_lf_ref = robot.position(data, robot.model().getJointId(lf_frame_name))
88 contactLF.setReference(H_lf_ref)
89 invdyn.addRigidContact(contactLF)
91 comTask = tsid.TaskComEquality(
"task-com", robot)
92 comTask.setKp(kp_com * np.ones(3))
93 comTask.setKd(2.0 * np.sqrt(kp_com) * np.ones(3))
94 invdyn.addMotionTask(comTask, w_com, 1, 0.0)
96 postureTask = tsid.TaskJointPosture(
"task-posture", robot)
97 postureTask.setKp(kp_posture * np.ones(robot.nv - 6))
98 postureTask.setKd(2.0 * np.sqrt(kp_posture) * np.ones(robot.nv - 6))
99 invdyn.addMotionTask(postureTask, w_posture, 1, 0.0)
104 REMOVE_CONTACT_N = 100
105 CONTACT_TRANSITION_TIME = 1.0
109 rightFootTask = tsid.TaskSE3Equality(
"task-right-foot", robot, rf_frame_name)
110 rightFootTask.setKp(kp_RF * np.ones(6))
111 rightFootTask.setKd(2.0 * np.sqrt(kp_com) * np.ones(6))
112 H_rf_ref = robot.position(data, robot.model().getJointId(rf_frame_name))
113 invdyn.addMotionTask(rightFootTask, w_RF, 1, 0.0)
115 s = tsid.TrajectorySample(12, 6)
116 H_rf_ref_vec = np.zeros(12)
117 H_rf_ref_vec[0:3] = H_rf_ref.translation
118 for i
in range(0, 3):
119 H_rf_ref_vec[3 * i + 3 : 3 * i + 6] = H_rf_ref.rotation[:, i]
120 s.value(H_rf_ref_vec)
121 rightFootTask.setReference(s)
123 com_ref = robot.com(data)
125 trajCom = tsid.TrajectoryEuclidianConstant(
"traj_com", com_ref)
126 sampleCom = tsid.TrajectorySample(3)
129 trajPosture = tsid.TrajectoryEuclidianConstant(
"traj_joint", q_ref)
130 samplePosture = tsid.TrajectorySample(robot.nv - 6)
132 solver = tsid.SolverHQuadProg(
"qp solver")
133 solver.resize(invdyn.nVar, invdyn.nEq, invdyn.nIn)
135 tau_old = np.zeros(robot.nv - 6)
137 for i
in range(0, max_it):
138 if i == REMOVE_CONTACT_N:
139 print(
"Start breaking contact right foot")
140 invdyn.removeRigidContact(contactRF.name, CONTACT_TRANSITION_TIME)
142 sampleCom = trajCom.computeNext()
143 comTask.setReference(sampleCom)
144 samplePosture = trajPosture.computeNext()
145 postureTask.setReference(samplePosture)
147 HQPData = invdyn.computeProblemData(t, q, v)
151 sol = solver.solve(HQPData)
152 tau = invdyn.getActuatorForces(sol)
153 dv = invdyn.getAccelerations(sol)
160 if invdyn.checkContact(contactRF.name, sol):
161 f = invdyn.getContactForce(contactRF.name, sol)
162 print(
" ", contactRF.name,
"force: ", contactRF.getNormalForce(f))
164 if invdyn.checkContact(contactLF.name, sol):
165 f = invdyn.getContactForce(contactLF.name, sol)
166 print(
" ", contactLF.name,
"force: ", contactLF.getNormalForce(f))
168 print(
" ", comTask.name,
" err:", norm(comTask.position_error, 2))
169 print(
" ",
"v: ", norm(v, 2),
"dv: ", norm(dv))
172 q = se3.integrate(robot.model(), q, dt * v)
175 assert norm(dv) < 1e6
178 print(
"Final COM Position", robot.com(invdyn.data()).transpose())
179 print(
"Desired COM Position", com_ref.transpose())