Skip to content

Commit d3973b8

Browse files
committed
Arguments for proper installation, timers to avoid blocking instructions, better paths and arguments reading
1 parent 3f2c224 commit d3973b8

File tree

6 files changed

+103
-46
lines changed

6 files changed

+103
-46
lines changed

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,23 @@ PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
8080
IF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
8181
INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})
8282
ENDIF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
83+
84+
# Install scripts
85+
find_package(catkin REQUIRED)
86+
87+
catkin_package()
88+
catkin_install_python(PROGRAMS
89+
script/sim_walk_torque.py
90+
script/run_test_utils.py
91+
script/sim_walk_vel.py
92+
script/test_ddp_sinu_effort.py
93+
python/dynamic_graph/sot/torque_control/talos/main_sim_walk_torque.py
94+
python/dynamic_graph/sot/torque_control/talos/main_sim_walk_torque_online.py
95+
python/dynamic_graph/sot/torque_control/talos/main_sim_walk_vel.py
96+
python/dynamic_graph/sot/torque_control/talos/main_sim_walk_vel_online.py
97+
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
98+
99+
FOREACH(dir python traj_multicontact_api)
100+
INSTALL(DIRECTORY ${dir}
101+
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
102+
ENDFOREACH(dir)

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<author>Olivier Stasse</author>
1212
<maintainer email="[email protected]">Guilhem Saurel</maintainer>
1313

14+
<buildtool_depend>catkin</buildtool_depend>
1415
<depend>sot-torque-control</depend>
1516
</package>

python/dynamic_graph/sot/torque_control/talos/balance_ctrl_sim_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
0.1, 0.1))
3535

3636
kp_tau = 0.1 * np.array(
37-
(5.0, 5.0, 5.0, 5.0, 8.5, 8.5,
38-
5.0, 5.0, 5.0, 5.0, 8.5, 8.5,
37+
(5.0, 5.0, 5.0, 5.0, 8.0, 8.0,
38+
5.0, 5.0, 5.0, 5.0, 8.0, 8.0,
3939
5.0, 5.0,
4040
5.0, 5.0, 5.0, 5.0, 5.0, 0.0, 0.0,
4141
0.0,

script/run_test_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66
from __future__ import print_function
77

8-
import rospy
8+
import rospy, time
99

1010
from std_srvs.srv import *
1111
from dynamic_graph_bridge_msgs.srv import *
@@ -26,7 +26,8 @@ def evalCommandClient(code):
2626
return eval(runCommandClient(code).result)
2727

2828
def launch_script(code,title,description = ""):
29-
raw_input(title+': '+description)
29+
#raw_input(title+': '+description)
30+
time.sleep(3)
3031
rospy.loginfo(title)
3132
rospy.loginfo(code)
3233
for line in code:
@@ -52,7 +53,8 @@ def run_test(appli):
5253
rospy.loginfo("Stack of Tasks launched")
5354

5455
launch_script(initCode,'initialize SoT')
55-
raw_input("Wait before starting the dynamic graph")
56+
#raw_input("Wait before starting the dynamic graph")
57+
rospy.sleep(6)
5658
runCommandStartDynamicGraph()
5759
print()
5860
except rospy.ServiceException, e:

script/sim_walk_torque.py

100644100755
Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
#!/usr/bin/python
2-
import time, subprocess, os
2+
import time, subprocess, os, rospy
33
from sys import argv
44
from run_test_utils import runCommandClient, run_test
5+
import rospkg
56

67
try:
78
# Python 2
89
input = raw_input # noqa
910
except NameError:
1011
pass
1112

12-
folder = str(os.path.dirname(os.path.abspath(__file__)))
13-
folder = folder + "/../traj_multicontact_api/dat/"
13+
PKG_NAME='talos-torque-control'
14+
15+
rospack = rospkg.RosPack()
16+
pkg_path = rospack.get_path(PKG_NAME)
17+
folder= pkg_path+ "/traj_multicontact_api/dat/"
1418
walk_type = "on_spot"
1519
pattern_generator = False
1620

17-
if len(argv) == 2 and argv[1] == "on_spot":
21+
if len(argv) == 4 and argv[1] == "on_spot":
1822
print("Starting script with folder " + folder + " walking on spot.")
19-
elif len(argv) == 2 and argv[1] == "walk_20":
23+
elif len(argv) == 4 and argv[1] == "walk_20":
2024
print("Starting script with folder " + folder + " walking with 20cm step.")
2125
walk_type = "walk_20"
22-
elif len(argv) == 3 and argv[1] == "on_spot" and argv[2] == "pattern_generator":
26+
elif len(argv) == 5 and argv[1] == "on_spot" and argv[2] == "pattern_generator":
2327
pattern_generator = True
2428
print("Starting script with pattern_generator walking on spot.")
25-
elif len(argv) == 3 and argv[1] == "walk_20" and argv[2] == "pattern_generator":
29+
elif len(argv) == 5 and argv[1] == "walk_20" and argv[2] == "pattern_generator":
2630
pattern_generator = True
2731
walk_type = "walk_20"
2832
print("Starting script with pattern_generator walking with 20cm step.")
29-
elif len(argv) == 3 and argv[1] == "on_spot":
33+
elif len(argv) == 5 and argv[1] == "on_spot":
3034
folder = argv[2]
3135
print("Starting script with folder " + folder + " walking on spot.")
32-
elif len(argv) == 3 and argv[1] == "walk_20":
36+
elif len(argv) == 5 and argv[1] == "walk_20":
3337
folder = argv[2]
3438
print("Starting script with folder " + folder + " walking with 20cm step.")
3539
walk_type = "walk_20"
40+
# Default option: on_spot, without pattern generator
41+
elif len(argv) == 3:
42+
print("Starting script with folder " + folder + " walking on spot.")
43+
3644
else:
3745
print("Usage: python sim_walk_torque.py walk_type:=[on_spot|walk_20] {pattern_generator|path_folder_of_the_reference_trajectories}")
3846
print("By giving only the walk_type the script starts using the default file trajectories")
@@ -42,13 +50,17 @@
4250
runCommandClient('folder = "' + folder + '"')
4351
runCommandClient('walk_type = "' + walk_type + '"')
4452
print("Starting script whith inverse_dyn_balance_controller main_sim_walk_torque.py")
45-
run_test('../python/dynamic_graph/sot/torque_control/talos/main_sim_walk_torque.py')
53+
run_test(pkg_path + '/../../lib/'+PKG_NAME+'/main_sim_walk_torque.py')
4654
else:
4755
runCommandClient('walk_type = "' + walk_type + '"')
4856
print("Starting script whith inverse_dyn_balance_controller main_sim_walk_torque_online.py")
49-
run_test('../python/dynamic_graph/sot/torque_control/talos/main_sim_walk_torque_online.py')
57+
run_test(pkg_path + '/../../lib/'+PKG_NAME+'/main_sim_walk_torque_online.py')
58+
59+
#initializing node to read ros time
60+
rospy.init_node('test_torque_walking', anonymous=True)
5061

51-
input("Waiting before writing the graph")
62+
#input("Waiting before writing the graph")
63+
time.sleep(5)
5264
runCommandClient("from dynamic_graph import writeGraph")
5365

5466
print("WriteGraph in /tmp/sot_talos_tsid.dot")
@@ -57,32 +69,38 @@
5769
proc3 = subprocess.Popen(["dot", "-Tpdf", "/tmp/sot_talos_tsid_walk.dot", "-o", "/tmp/sot_talos_tsid_walk_torque.pdf"])
5870

5971
if pattern_generator:
60-
input("Waiting before setting gains")
72+
#input("Waiting before setting gains")
73+
time.sleep(3)
6174
print("Setting gains")
6275
runCommandClient("robot.inv_dyn.kp_feet.value = 6*(250,)")
63-
runCommandClient("robot.inv_dyn.kp_com.value = 3*(400,)")
76+
#runCommandClient("robot.inv_dyn.kp_com.value = 3*(400,)")
6477
runCommandClient("robot.inv_dyn.kd_feet.value = 6*(12,)")
65-
runCommandClient("robot.inv_dyn.kd_com.value = 3*(12,)")
66-
input("Waiting before playing trajectories")
78+
#runCommandClient("robot.inv_dyn.kd_com.value = 3*(12,)")
79+
#input("Waiting before playing trajectories")
80+
time.sleep(2)
6781
runCommandClient('robot.triggerPG.sin.value = 1')
68-
input("Wait before stopping the trajectory")
82+
rospy.sleep(70) #arbitrary value
83+
#input("Wait before stopping the trajectory")
6984
runCommandClient('robot.pg.velocitydes.value=(0.0,0.0,0.0)')
7085
else:
71-
input("Waiting before setting gains")
86+
#input("Waiting before setting gains")
87+
time.sleep(3)
7288
print("Setting gains")
7389
runCommandClient("robot.inv_dyn.kp_feet.value = 6*(200,)")
74-
runCommandClient("robot.inv_dyn.kp_com.value = 3*(250,)")
90+
# runCommandClient("robot.inv_dyn.kp_com.value = 3*(250,)")
7591
runCommandClient("robot.inv_dyn.kd_feet.value = 6*(12,)")
76-
runCommandClient("robot.inv_dyn.kd_com.value = 3*(12,)")
77-
input("Waiting before playing trajectories")
92+
# runCommandClient("robot.inv_dyn.kd_com.value = 3*(12,)")
93+
#input("Waiting before playing trajectories")
94+
time.sleep(2)
7895
print("Playing trajectories")
7996
runCommandClient("robot.traj_sync.turnOn()")
80-
input("Waiting before stopping the trajectories")
97+
rospy.sleep(64) #64 seconds is the time necessary for the on_spot trajectory (the longest one)
98+
#input("Waiting before stopping the trajectories")
8199
print("Stop trajectories")
82100
runCommandClient("robot.traj_sync.turnOff()")
83101

84102
time.sleep(2.0)
85-
input("Wait before going to halfSitting")
103+
#input("Wait before going to halfSitting")
86104
runCommandClient("go_to_position(robot.traj_gen, robot.halfSitting[6:], 5.0)")
87105
time.sleep(5.0)
88106
print("The robot is back in position!")

script/sim_walk_vel.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
11
#!/usr/bin/python
2-
import time, subprocess, os
2+
import time, subprocess, os, rospy
33
from sys import argv
44
from run_test_utils import runCommandClient, run_test
5+
import rospkg
56

67
try:
78
# Python 2
89
input = raw_input # noqa
910
except NameError:
1011
pass
1112

12-
folder = str(os.path.dirname(os.path.abspath(__file__)))
13-
folder = folder + "/../traj_multicontact_api/dat/"
13+
PKG_NAME='talos-torque-control'
14+
15+
rospack = rospkg.RosPack()
16+
pkg_path = rospack.get_path(PKG_NAME)
17+
folder= pkg_path+ "/traj_multicontact_api/dat/"
1418
walk_type = "on_spot_test"
1519
pattern_generator = False
1620

17-
if len(argv) == 2 and argv[1] == "on_spot":
21+
if len(argv) == 4 and argv[1] == "on_spot":
1822
print("Starting script with folder " + folder + " walking on spot.")
19-
elif len(argv) == 2 and argv[1] == "walk_20":
23+
elif len(argv) == 4 and argv[1] == "walk_20":
2024
print("Starting script with folder " + folder + " walking with 20cm step.")
2125
walk_type = "walk_20_test"
22-
elif len(argv) == 3 and argv[1] == "on_spot" and argv[2] == "pattern_generator":
26+
elif len(argv) == 5 and argv[1] == "on_spot" and argv[2] == "pattern_generator":
2327
pattern_generator = True
2428
print("Starting script with pattern_generator walking on spot.")
25-
elif len(argv) == 3 and argv[1] == "walk_20" and argv[2] == "pattern_generator":
29+
elif len(argv) == 5 and argv[1] == "walk_20" and argv[2] == "pattern_generator":
2630
pattern_generator = True
2731
walk_type = "walk_20_test"
2832
print("Starting script with pattern_generator walking with 20cm step.")
29-
elif len(argv) == 3 and argv[1] == "on_spot":
33+
elif len(argv) == 5 and argv[1] == "on_spot":
3034
folder = argv[2]
3135
print("Starting script with folder " + folder + " walking on spot.")
32-
elif len(argv) == 3 and argv[1] == "walk_20":
36+
elif len(argv) == 5 and argv[1] == "walk_20":
3337
folder = argv[2]
3438
print("Starting script with folder " + folder + " walking with 20cm step.")
3539
walk_type = "walk_20"
40+
# Default option: on_spot_test, without pattern generator
41+
elif len(argv) == 3:
42+
print("Starting script with folder " + folder + " walking on spot.")
3643
else:
3744
print("Usage: python sim_walk_vel.py walk_type:=[on_spot|walk_20] {pattern_generator|path_folder_of_the_reference_trajectories}")
3845
print("By giving only the walk_type the script starts using the default file trajectories")
@@ -42,39 +49,48 @@
4249
runCommandClient('folder = "' + folder + '"')
4350
runCommandClient('walk_type = "' + walk_type + '"')
4451
print("Starting script whith inverse_dyn_balance_controller")
45-
run_test('../python/dynamic_graph/sot/torque_control/talos/main_sim_walk_vel.py')
52+
run_test(pkg_path+'/../../lib/'+PKG_NAME+'/main_sim_walk_vel.py')
4653
else:
4754
runCommandClient('walk_type = "' + walk_type + '"')
4855
print("Starting script whith inverse_dyn_balance_controller")
49-
run_test('../python/dynamic_graph/sot/torque_control/talos/main_sim_walk_vel_online.py')
56+
run_test(pkg_path+'/../../lib/'+PKG_NAME+'/main_sim_walk_vel_online.py')
57+
58+
#initializing node to read ros time
59+
rospy.init_node('test_walking_vel', anonymous=True)
5060

51-
input("Waiting before writing the graph")
61+
#input("Waiting before writing the graph")
62+
time.sleep(5)
5263
runCommandClient("from dynamic_graph import writeGraph")
5364

5465
print("WriteGraph in /tmp/sot_talos_tsid.dot")
5566
runCommandClient("writeGraph('/tmp/sot_talos_tsid_walk.dot')")
5667
print("Convert graph to PDF in /tmp/sot_talos_tsid_walk.pdf")
5768
proc3 = subprocess.Popen(["dot", "-Tpdf", "/tmp/sot_talos_tsid_walk.dot", "-o", "/tmp/sot_talos_tsid_walk.pdf"])
5869

59-
input("Waiting before setting gains")
70+
#input("Waiting before setting gains")
71+
time.sleep(3)
6072
print("Setting gains")
6173
# runCommandClient("robot.inv_dyn.kp_feet.value = 6*(500,)")
6274
# runCommandClient("robot.inv_dyn.kp_com.value = 3*(100,)")
6375
# runCommandClient("robot.inv_dyn.kd_feet.value = 6*(12,)")
6476
# runCommandClient("robot.inv_dyn.kd_com.value = 3*(7,)")
6577

6678
if pattern_generator:
67-
input("Waiting before playing trajectories")
79+
#input("Waiting before playing trajectories")
80+
time.sleep(2)
6881
runCommandClient('robot.triggerPG.sin.value = 1')
6982
runCommandClient('plug(robot.pg.leftfootref, robot.m2qLF.sin)')
7083
runCommandClient('plug(robot.pg.rightfootref, robot.m2qLF.sin)')
71-
input("Wait before stopping the trajectory")
84+
#input("Wait before stopping the trajectory")
85+
rospy.sleep(70)
7286
runCommandClient('robot.pg.velocitydes.value=(0.0,0.0,0.0)')
7387
else:
74-
input("Waiting before playing trajectories")
88+
#input("Waiting before playing trajectories")
89+
time.sleep(2)
7590
print("Playing trajectories")
7691
runCommandClient("robot.traj_sync.turnOn()")
77-
input("Waiting before stopping the trajectories")
92+
#input("Waiting before stopping the trajectories")
93+
time.sleep(64)
7894
print("Stop trajectories")
7995
runCommandClient("robot.traj_sync.turnOff()")
8096
# input("Waiting before reading trajectories")
@@ -85,7 +101,7 @@
85101
# runCommandClient('robot.lf_traj_gen.playTrajectoryFile(folder + walk_type + "/leftFoot.dat")')
86102

87103
time.sleep(2.0)
88-
input("Wait before going to halfSitting")
104+
#input("Wait before going to halfSitting")
89105
runCommandClient("go_to_position(robot.traj_gen, robot.halfSitting[6:], 5.0)")
90106
time.sleep(5.0)
91107
print("The robot is back in position!")

0 commit comments

Comments
 (0)