sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
test_dcmComControl.py
Go to the documentation of this file.
1 """Test CoM admittance control without using the ZMP, with CoM computed as implemented
2 in reference code."""
3 
4 from time import sleep
5 
6 import matplotlib.pyplot as plt
7 import numpy as np
8 
9 from dynamic_graph.sot_talos_balance.utils.gazebo_utils import apply_force
10 from dynamic_graph.sot_talos_balance.utils.run_test_utils import (
11  evalCommandClient,
12  run_test,
13  runCommandClient,
14 )
15 
16 try:
17  # Python 2
18  input = raw_input # noqa
19 except NameError:
20  pass
21 
22 run_test("appli_dcmComControl.py")
23 
24 sleep(5.0)
25 
26 # Connect CoM reference and reset controllers
27 print("Connect CoM reference")
29  "robot.com_admittance_control.setState(robot.dynamic.com.value,[0.0,0.0,0.0])"
30 )
31 runCommandClient("robot.dcm_control.Ki.value = Ki_dcm")
32 runCommandClient("robot.dcm_control.resetDcmIntegralError()")
34  "plug(robot.dcm_control.ddcomRef,robot.com_admittance_control.ddcomDes)"
35 )
36 
37 sleep(5.0)
38 
39 print("Kick the robot...")
40 apply_force([-1000.0, 0, 0], 0.01)
41 print("... kick!")
42 
43 sleep(5.0)
44 
45 runCommandClient("dump_tracer(robot.tracer)")
46 
47 # --- DISPLAY
48 dcm_data = np.loadtxt(
49  "/tmp/dg_" + evalCommandClient("robot.estimator.name") + "-dcm.dat"
50 )
51 zmp_data = np.loadtxt("/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-zmp.dat")
52 zmpDes_data = np.loadtxt(
53  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-zmpRef.dat"
54 )
55 com_data = np.loadtxt("/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-com.dat")
56 comDes_data = np.loadtxt(
57  "/tmp/dg_" + evalCommandClient("robot.com_admittance_control.name") + "-comRef.dat"
58 )
59 
60 plt.ion()
61 
62 plt.figure()
63 plt.plot(dcm_data[:, 1], "b-")
64 plt.plot(dcm_data[:, 2], "r-")
65 plt.title("DCM")
66 plt.legend(["x", "y"])
67 
68 plt.figure()
69 plt.plot(com_data[:, 1], "b-")
70 plt.plot(comDes_data[:, 1], "b--")
71 plt.plot(com_data[:, 2], "r-")
72 plt.plot(comDes_data[:, 2], "r--")
73 plt.plot(com_data[:, 3], "g-")
74 plt.plot(comDes_data[:, 3], "g--")
75 plt.title("COM real vs desired")
76 plt.legend(["Real x", "Desired x", "Real y", "Desired y", "Real z", "Desired z"])
77 
78 plt.figure()
79 plt.plot(com_data[:, 1], "b-")
80 plt.title("COM real x")
81 plt.figure()
82 plt.plot(comDes_data[:, 1], "b--")
83 plt.title("COM desired x")
84 
85 plt.figure()
86 plt.plot(com_data[:, 2], "r-")
87 plt.title("COM real y")
88 plt.figure()
89 plt.plot(comDes_data[:, 2], "r--")
90 plt.title("COM desired y")
91 
92 plt.figure()
93 plt.plot(com_data[:, 3], "g-")
94 plt.title("COM real z")
95 plt.figure()
96 plt.plot(comDes_data[:, 3], "g--")
97 plt.title("COM desired z")
98 
99 plt.figure()
100 plt.plot(zmp_data[:, 1], "b-")
101 plt.plot(zmpDes_data[:, 1], "b--")
102 plt.plot(zmp_data[:, 2], "r-")
103 plt.plot(zmpDes_data[:, 2], "r--")
104 plt.title("ZMP real vs desired")
105 plt.legend(["Real x", "Desired x", "Real y", "Desired y"])
106 
107 plt.figure()
108 plt.plot(zmp_data[:, 1] - zmpDes_data[:, 1], "b-")
109 plt.plot(zmp_data[:, 2] - zmpDes_data[:, 2], "r-")
110 plt.title("ZMP error")
111 plt.legend(["Error on x", "Error on y"])
112 
113 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)