sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
test_dcmComZmpControl.py
Go to the documentation of this file.
1 """Test CoM admittance control as implemented in reference code."""
2 from time import sleep
3 
4 import matplotlib.pyplot as plt
5 import numpy as np
6 
7 from dynamic_graph.sot_talos_balance.utils.gazebo_utils import apply_force
8 from dynamic_graph.sot_talos_balance.utils.run_test_utils import (
9  evalCommandClient,
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_dcmComZmpControl.py")
21 
22 sleep(5.0)
23 
24 # Connect ZMP reference and reset controllers
25 print("Connect ZMP reference")
26 runCommandClient("plug(robot.dcm_control.zmpRef,robot.com_admittance_control.zmpDes)")
28  "robot.com_admittance_control.setState(robot.dynamic.com.value,[0.0,0.0,0.0])"
29 )
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(5.0)
35 
36 print("Kick the robot...")
37 apply_force([-1000.0, 0, 0], 0.01)
38 print("... kick!")
39 
40 sleep(5.0)
41 
42 runCommandClient("dump_tracer(robot.tracer)")
43 
44 # --- DISPLAY
45 dcm_data = np.loadtxt(
46  "/tmp/dg_" + evalCommandClient("robot.estimator.name") + "-dcm.dat"
47 )
48 zmp_data = np.loadtxt("/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-zmp.dat")
49 zmpDes_data = np.loadtxt(
50  "/tmp/dg_" + evalCommandClient("robot.dcm_control.name") + "-zmpRef.dat"
51 )
52 com_data = np.loadtxt("/tmp/dg_" + evalCommandClient("robot.dynamic.name") + "-com.dat")
53 comDes_data = np.loadtxt(
54  "/tmp/dg_" + evalCommandClient("robot.com_admittance_control.name") + "-comRef.dat"
55 )
56 
57 plt.ion()
58 
59 plt.figure()
60 plt.plot(dcm_data[:, 1], "b-")
61 plt.plot(dcm_data[:, 2], "r-")
62 plt.title("DCM")
63 plt.legend(["x", "y"])
64 
65 plt.figure()
66 plt.plot(com_data[:, 1], "b-")
67 plt.plot(comDes_data[:, 1], "b--")
68 plt.plot(com_data[:, 2], "r-")
69 plt.plot(comDes_data[:, 2], "r--")
70 plt.plot(com_data[:, 3], "g-")
71 plt.plot(comDes_data[:, 3], "g--")
72 plt.title("COM real vs desired")
73 plt.legend(["Real x", "Desired x", "Real y", "Desired y", "Real z", "Desired z"])
74 
75 plt.figure()
76 plt.plot(zmp_data[:, 1], "b-")
77 plt.plot(zmpDes_data[:, 1], "b--")
78 plt.plot(zmp_data[:, 2], "r-")
79 plt.plot(zmpDes_data[:, 2], "r--")
80 plt.title("ZMP real vs desired")
81 plt.legend(["Real x", "Desired x", "Real y", "Desired y"])
82 
83 plt.figure()
84 plt.plot(zmp_data[:, 1] - zmpDes_data[:, 1], "b-")
85 plt.plot(zmp_data[:, 2] - zmpDes_data[:, 2], "r-")
86 plt.title("ZMP error")
87 plt.legend(["Error on x", "Error on y"])
88 
89 input("Wait before leaving the simulation")
sot_talos_balance.utils.run_test_utils.runCommandClient
runCommandClient
Definition: run_test_utils.py:23
sot_talos_balance.utils.gazebo_utils.apply_force
def apply_force(force, duration, body_name="talos::torso_2_link")
Definition: gazebo_utils.py:21
sot_talos_balance.test.test_dcmComZmpControl.input
input
Definition: test_dcmComZmpControl.py:16
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