sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
test_dcmZmpControl_feedback.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_ft_calibration,
10  run_test,
11  runCommandClient,
12 )
13 
14 try:
15  # Python 2
16  input = raw_input # noqa
17 except NameError:
18  pass
19 
20 run_test("appli_dcmZmpControl_feedback.py")
21 
22 run_ft_calibration("robot.ftc")
23 input("Wait before running the test")
24 
25 # Connect ZMP reference and reset controllers
26 print("Connect ZMP reference")
27 runCommandClient("plug(robot.zmp_estimator.emergencyStop,robot.cm.emergencyStop_zmp)")
28 runCommandClient("plug(robot.dcm_control.zmpRef,robot.com_admittance_control.zmpDes)")
29 runCommandClient("robot.com_admittance_control.setState(comDes,[0.0,0.0,0.0])")
30 runCommandClient("robot.com_admittance_control.Kp.value = Kp_adm")
31 runCommandClient("robot.dcm_control.resetDcmIntegralError()")
32 runCommandClient("robot.dcm_control.Ki.value = Ki_dcm")
33 
34 sleep(30.0)
35 
36 runCommandClient("dump_tracer(robot.tracer)")
37 
38 # --- DISPLAY
39 # desired CoM (workaround)
40 comDes_data = np.loadtxt(
41  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-dcmDes.dat"
42 )
43 # estimated CoM (not directly employed)
44 comEst_data = np.loadtxt(
45  "/tmp/dg_" + evalCommandClient("robot.cdc_estimator.name") + "-c.dat"
46 )
47 # reference CoM
48 comRef_data = np.loadtxt(
49  "/tmp/dg_" + evalCommandClient("robot.com_admittance_control.name") + "-comRef.dat"
50 )
51 comSOT_data = np.loadtxt(
52  "/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-com.dat"
53 ) # resulting SOT CoM
54 
55 dcmDes_data = np.loadtxt(
56  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-dcmDes.dat"
57 ) # desired DCM
58 dcmEst_data = np.loadtxt(
59  "/tmp/dg_" + evalCommandClient("robot.estimator.name") + "-dcm.dat"
60 ) # estimated DCM
61 
62 zmpDes_data = np.loadtxt(
63  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-zmpDes.dat"
64 ) # desired ZMP
65 zmpSOT_data = np.loadtxt(
66  "/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-zmp.dat"
67 ) # SOT ZMP
68 zmpEst_data = np.loadtxt(
69  "/tmp/dg_" + evalCommandClient("robot.zmp_estimator.name") + "-zmp.dat"
70 ) # estimated ZMP
71 zmpRef_data = np.loadtxt(
72  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-zmpRef.dat"
73 ) # reference ZMP
74 
75 plt.ion()
76 
77 plt.figure()
78 plt.plot(comDes_data[:, 1], "b--")
79 plt.plot(comEst_data[:, 1], "b-")
80 plt.plot(comRef_data[:, 1], "b:")
81 plt.plot(comSOT_data[:, 1], "b-.")
82 plt.plot(comDes_data[:, 2], "r--")
83 plt.plot(comEst_data[:, 2], "r-")
84 plt.plot(comRef_data[:, 2], "r:")
85 plt.plot(comSOT_data[:, 2], "r-.")
86 plt.plot(comDes_data[:, 3], "g--")
87 plt.plot(comEst_data[:, 3], "g-")
88 plt.plot(comRef_data[:, 3], "g:")
89 plt.plot(comSOT_data[:, 3], "g-.")
90 plt.title("COM")
91 plt.legend(
92  [
93  "Desired x",
94  "Estimated x",
95  "Reference x",
96  "SOT x",
97  "Desired y",
98  "Estimated y",
99  "Reference y",
100  "SOT y",
101  "Desired z",
102  "Estimated z",
103  "Reference z",
104  "SOT z",
105  ]
106 )
107 
108 plt.figure()
109 plt.plot(dcmDes_data[:, 1], "b--")
110 plt.plot(dcmEst_data[:, 1], "b-")
111 plt.plot(dcmDes_data[:, 2], "r--")
112 plt.plot(dcmEst_data[:, 2], "r-")
113 plt.title("DCM")
114 plt.legend(["Desired x", "Estimated x", "Desired y", "Estimated y"])
115 
116 plt.figure()
117 plt.plot(zmpDes_data[:, 1], "b--")
118 plt.plot(zmpSOT_data[:, 1], "b-")
119 plt.plot(zmpRef_data[:, 1], "b:")
120 plt.plot(zmpDes_data[:, 2], "r--")
121 plt.plot(zmpSOT_data[:, 2], "r-")
122 plt.plot(zmpRef_data[:, 2], "r:")
123 plt.title("ZMP")
124 plt.legend(["Desired x", "SOT x", "Reference x", "Desired y", "SOT y", "Reference y"])
125 
126 zmpErrSOT = zmpSOT_data - zmpDes_data
127 
128 plt.figure()
129 plt.plot(zmpErrSOT[:, 1], "b-")
130 plt.plot(zmpErrSOT[:, 2], "r-")
131 plt.title("ZMP SOT error")
132 plt.legend(["Error on x", "Error on y"])
133 
134 input("Wait before leaving the simulation")
def run_ft_calibration(sensor_name, force=False)
def run_test(appli, verbosity=1, interactive=True)