2020@dataclass
2121class GeneralParams :
2222 dt : float = 1.0 / 500.0
23- duration : float = 8 .0
23+ duration : float = 100 .0
2424 n_solver_iter : int = 1000
2525
2626
@@ -279,7 +279,10 @@ def _add_com_task(self):
279279 self .com_task = tsid .TaskComEquality ("task-com" , self .robot )
280280 self .com_task .setKp (kp_com * np .ones (3 ))
281281 self .com_task .setKd (kd_com * np .ones (3 ))
282- self .invdyn .addMotionTask (self .com_task , w_com , 0 , 0.0 )
282+ self .invdyn .addMotionTask (self .com_task , w_com , 1 , 0.0 )
283+
284+ com_ref = self .data .com [0 ] # Initial value of the CoM
285+ self .traj_com = tsid .TrajectoryEuclidianConstant ("traj_com" , com_ref )
283286
284287 def _add_posture_task (self , q0 : np .ndarray ):
285288 kp_posture = posture_gains_from_model (self .model )
@@ -290,8 +293,7 @@ def _add_posture_task(self, q0: np.ndarray):
290293 self .posture_task .setKd (2.0 * np .sqrt (kp_posture ))
291294 self .invdyn .addMotionTask (self .posture_task , w_posture , 1 , 0.0 )
292295
293- self .posture_sample = tsid .TrajectorySample (self .robot .nv - 6 )
294- self .posture_sample .value (q0 [7 :])
296+ self .traj_posture = tsid .TrajectoryEuclidianConstant ("traj_joint" , q0 [7 :])
295297
296298 def compute (
297299 self ,
@@ -303,16 +305,30 @@ def compute(
303305 self .com_sample .value (com_ref )
304306 self .com_sample .derivative (self .zero_com_derivatives )
305307 self .com_sample .second_derivative (self .zero_com_derivatives )
306-
307308 self .com_task .setReference (self .com_sample )
308- self .posture_task .setReference (self .posture_sample )
309+
310+ posture_ref = self .traj_posture .computeNext ()
311+ self .posture_task .setReference (posture_ref )
309312
310313 hqp = self .invdyn .computeProblemData (t , q , v )
311314 sol = self .solver .solve (hqp )
312315 if sol .status != 0 :
313316 raise RuntimeError (f"TSID QP solver failed at t={ t :.3f} with status { sol .status } " )
317+
318+ tau = self .invdyn .getActuatorForces (sol )
319+ contact_forces = self .invdyn .getContactForces (sol )
320+
321+ print ("solver status:" , sol .status )
322+ print ("tau max:" , np .max (np .abs (tau )))
323+ print ("com:" , pin .centerOfMass (self .model , self .data , q ))
324+ print ("com err:" , pin .centerOfMass (self .model , self .data , q ) - com_ref )
314325
315- return self .invdyn .getActuatorForces (sol )
326+ for name in ["contact-left" , "contact-right" ]:
327+ if self .invdyn .checkContact (name , sol ):
328+ f = self .invdyn .getContactForce (name , sol )
329+ print (name , "fz:" , f [2 ], "force norm:" , np .linalg .norm (f [:3 ]))
330+
331+ return tau
316332
317333
318334def parse_args ():
@@ -324,7 +340,7 @@ def parse_args():
324340 help = "Path containing the talos_data folder." ,
325341 )
326342 parser .add_argument ("--plot-results" , action = "store_true" )
327- parser .add_argument ("--launch-gui" , action = "store_true " )
343+ parser .add_argument ("--launch-gui" , action = "store_false " )
328344 parser .add_argument ("--record-video" , action = "store_true" )
329345 parser .add_argument ("--duration" , type = float , default = GeneralParams .duration )
330346 return parser .parse_args ()
@@ -348,7 +364,7 @@ def main():
348364 dt = params .dt ,
349365 path_to_robot_urdf = urdf_path ,
350366 model = talos ,
351- launch_gui = True ,
367+ launch_gui = args . launch_gui ,
352368 n_solver_iter = params .n_solver_iter ,
353369 )
354370
@@ -385,7 +401,9 @@ def main():
385401
386402 com0 = pin .centerOfMass (talos .model , talos .data , q_init )
387403 feet_mid = 0.5 * (oMf_lf_tgt .translation + oMf_rf_tgt .translation )
388- com_ref = np .array ([feet_mid [0 ], feet_mid [1 ], com0 [2 ]])
404+ # com_ref = np.array([feet_mid[0], feet_mid[1], com0[2]])
405+
406+ com_ref = com0 .copy ()
389407 print (f"Fixed COM reference: [{ com_ref [0 ]:.3f} , { com_ref [1 ]:.3f} , { com_ref [2 ]:.3f} ]" )
390408
391409 pb .setGravity (0 , 0 , 0 )
@@ -400,21 +418,21 @@ def main():
400418 com_pb_log = np .zeros ((n_steps , 3 ))
401419 tau_max = np .zeros (n_steps )
402420
403- if args .record_video :
404- simulator .start_video_record ()
405-
406421 for k , t in enumerate (time ):
407422 q = simulator .get_q (talos .model .nq )
408423 v = simulator .get_v (talos .model .nv )
409424
410425 try :
411426 tau = controller .compute (t , q , v , com_ref )
427+
428+
412429 except RuntimeError as exc :
413430 print (exc )
414431 break
415432
416433 simulator .apply_joint_torques (tau )
417- simulator .update_camera_to_follow_pos (com_ref [0 ], com_ref [1 ], 0.0 )
434+ # simulator.reset_robot_configuration(q_init)
435+ # simulator.update_camera_to_follow_pos(com_ref[0], com_ref[1], 0.0)
418436 simulator .step ()
419437
420438 pin .forwardKinematics (talos .model , talos .data , q )
0 commit comments