sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
test_dcmComZmpControl.py
Go to the documentation of this file.
1 """Test CoM admittance control as implemented in reference code."""
2 
3 from time import sleep
4 
5 import matplotlib.pyplot as plt
6 import numpy as np
7 
8 from dynamic_graph.sot_talos_balance.utils.gazebo_utils import apply_force
9 from dynamic_graph.sot_talos_balance.utils.run_test_utils import (
10  evalCommandClient,
11  run_test,
12  runCommandClient,
13 )
14 
15 try:
16  # Python 2
17  input = raw_input # noqa
18 except NameError:
19  pass
20 
21 run_test("appli_dcmComZmpControl.py")
22 
23 sleep(5.0)
24 
25 # Connect ZMP reference and reset controllers
26 print("Connect ZMP reference")
27 runCommandClient("plug(robot.dcm_control.zmpRef,robot.com_admittance_control.zmpDes)")
29  "robot.com_admittance_control.setState(robot.dynamic.com.value,[0.0,0.0,0.0])"
30 )
31 runCommandClient("robot.com_admittance_control.Kp.value = Kp_adm")
32 runCommandClient("robot.dcm_control.resetDcmIntegralError()")
33 runCommandClient("robot.dcm_control.Ki.value = Ki_dcm")
34 
35 sleep(5.0)
36 
37 print("Kick the robot...")
38 apply_force([-1000.0, 0, 0], 0.01)
39 print("... kick!")
40 
41 sleep(5.0)
42 
43 runCommandClient("dump_tracer(robot.tracer)")
44 
45 # --- DISPLAY
46 dcm_data = np.loadtxt(
47  "/tmp/dg_" + evalCommandClient("robot.estimator.name") + "-dcm.dat"
48 )
49 zmp_data = np.loadtxt("/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-zmp.dat")
50 zmpDes_data = np.loadtxt(
51  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-zmpRef.dat"
52 )
53 com_data = np.loadtxt("/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-com.dat")
54 comDes_data = np.loadtxt(
55  "/tmp/dg_" + evalCommandClient("robot.com_admittance_control.name") + "-comRef.dat"
56 )
57 
58 plt.ion()
59 
60 plt.figure()
61 plt.plot(dcm_data[:, 1], "b-")
62 plt.plot(dcm_data[:, 2], "r-")
63 plt.title("DCM")
64 plt.legend(["x", "y"])
65 
66 plt.figure()
67 plt.plot(com_data[:, 1], "b-")
68 plt.plot(comDes_data[:, 1], "b--")
69 plt.plot(com_data[:, 2], "r-")
70 plt.plot(comDes_data[:, 2], "r--")
71 plt.plot(com_data[:, 3], "g-")
72 plt.plot(comDes_data[:, 3], "g--")
73 plt.title("COM real vs desired")
74 plt.legend(["Real x", "Desired x", "Real y", "Desired y", "Real z", "Desired z"])
75 
76 plt.figure()
77 plt.plot(zmp_data[:, 1], "b-")
78 plt.plot(zmpDes_data[:, 1], "b--")
79 plt.plot(zmp_data[:, 2], "r-")
80 plt.plot(zmpDes_data[:, 2], "r--")
81 plt.title("ZMP real vs desired")
82 plt.legend(["Real x", "Desired x", "Real y", "Desired y"])
83 
84 plt.figure()
85 plt.plot(zmp_data[:, 1] - zmpDes_data[:, 1], "b-")
86 plt.plot(zmp_data[:, 2] - zmpDes_data[:, 2], "r-")
87 plt.title("ZMP error")
88 plt.legend(["Error on x", "Error on y"])
89 
90 input("Wait before leaving the simulation")
def apply_force(force, duration, body_name="talos::torso_2_link")
Definition: gazebo_utils.py:21
def run_test(appli, verbosity=1, interactive=True)