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