sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
test_dcmZmpControl.py
Go to the documentation of this file.
1 """Test CoM admittance control as described in paper."""
2 
3 from time import sleep
4 
5 import matplotlib.pyplot as plt
6 import numpy as np
7 from dynamic_graph.sot_talos_balance.utils.run_test_utils import (
8  evalCommandClient,
9  run_test,
10  runCommandClient,
11 )
12 
13 try:
14  # Python 2
15  input = raw_input # noqa
16 except NameError:
17  pass
18 
19 run_test("appli_dcmZmpControl.py")
20 
21 sleep(5.0)
22 
23 # Connect ZMP reference and reset controllers
24 print("Connect ZMP reference")
25 runCommandClient("plug(robot.dcm_control.zmpRef,robot.com_admittance_control.zmpDes)")
26 runCommandClient("robot.com_admittance_control.setState(comDes,[0.0,0.0,0.0])")
27 runCommandClient("robot.com_admittance_control.Kp.value = Kp_adm")
28 runCommandClient("robot.dcm_control.resetDcmIntegralError()")
29 runCommandClient("robot.dcm_control.Ki.value = Ki_dcm")
30 
31 # sleep(5.0)
32 
33 # print('Kick the robot...')
34 # apply_force([-1000.0,0,0],0.01)
35 # print('... kick!')
36 
37 # sleep(5.0)
38 
39 sleep(30.0)
40 
41 runCommandClient("dump_tracer(robot.tracer)")
42 
43 # --- DISPLAY
44 # desired CoM (workaround)
45 comDes_data = np.loadtxt(
46  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-dcmDes.dat"
47 )
48 # estimated CoM (workaround)
49 comEst_data = np.loadtxt(
50  "/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-com.dat"
51 )
52 # estimated CoM (to be modified)
53 # comEst_data = np.loadtxt('/tmp/dg_' + evalCommandClient('robot.cdc_estimator.name') +
54 # '-c.dat')
55 # reference CoM
56 comRef_data = np.loadtxt(
57  "/tmp/dg_" + evalCommandClient("robot.com_admittance_control.name") + "-comRef.dat"
58 )
59 comSOT_data = np.loadtxt(
60  "/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-com.dat"
61 ) # resulting SOT CoM
62 
63 dcmDes_data = np.loadtxt(
64  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-dcmDes.dat"
65 ) # desired DCM
66 dcmEst_data = np.loadtxt(
67  "/tmp/dg_" + evalCommandClient("robot.estimator.name") + "-dcm.dat"
68 ) # estimated DCM
69 
70 zmpDes_data = np.loadtxt(
71  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-zmpDes.dat"
72 ) # desired ZMP
73 zmpSOT_data = np.loadtxt(
74  "/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-zmp.dat"
75 ) # SOT ZMP
76 zmpEst_data = np.loadtxt(
77  "/tmp/dg_" + evalCommandClient("robot.zmp_estimator.name") + "-zmp.dat"
78 ) # estimated ZMP
79 zmpRef_data = np.loadtxt(
80  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-zmpRef.dat"
81 ) # reference ZMP
82 
83 plt.ion()
84 
85 plt.figure()
86 plt.plot(comDes_data[:, 1], "b--")
87 plt.plot(comEst_data[:, 1], "b-")
88 plt.plot(comRef_data[:, 1], "b:")
89 plt.plot(comSOT_data[:, 1], "b-.")
90 plt.plot(comDes_data[:, 2], "r--")
91 plt.plot(comEst_data[:, 2], "r-")
92 plt.plot(comRef_data[:, 2], "r:")
93 plt.plot(comSOT_data[:, 2], "r-.")
94 plt.plot(comDes_data[:, 3], "g--")
95 plt.plot(comEst_data[:, 3], "g-")
96 plt.plot(comRef_data[:, 3], "g:")
97 plt.plot(comSOT_data[:, 3], "g-.")
98 plt.title("COM")
99 plt.legend(
100  [
101  "Desired x",
102  "Estimated x",
103  "Reference x",
104  "SOT x",
105  "Desired y",
106  "Estimated y",
107  "Reference y",
108  "SOT y",
109  "Desired z",
110  "Estimated z",
111  "Reference z",
112  "SOT z",
113  ]
114 )
115 
116 plt.figure()
117 plt.plot(dcmDes_data[:, 1], "b--")
118 plt.plot(dcmEst_data[:, 1], "b-")
119 plt.plot(dcmDes_data[:, 2], "r--")
120 plt.plot(dcmEst_data[:, 2], "r-")
121 plt.title("DCM")
122 plt.legend(["Desired x", "Estimated x", "Desired y", "Estimated y"])
123 
124 plt.figure()
125 plt.plot(zmpDes_data[:, 1], "b--")
126 plt.plot(zmpSOT_data[:, 1], "b-")
127 plt.plot(zmpRef_data[:, 1], "b:")
128 plt.plot(zmpDes_data[:, 2], "r--")
129 plt.plot(zmpSOT_data[:, 2], "r-")
130 plt.plot(zmpRef_data[:, 2], "r:")
131 plt.title("ZMP")
132 plt.legend(["Desired x", "SOT x", "Reference x", "Desired y", "SOT y", "Reference y"])
133 
134 zmpErrSOT = zmpSOT_data - zmpDes_data
135 
136 plt.figure()
137 plt.plot(zmpErrSOT[:, 1], "b-")
138 plt.plot(zmpErrSOT[:, 2], "r-")
139 plt.title("ZMP SOT error")
140 plt.legend(["Error on x", "Error on y"])
141 
142 input("Wait before leaving the simulation")
def run_test(appli, verbosity=1, interactive=True)