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