3 @author: Gabriele Buondonno
4 This module contains utilities for running the tests
7 from __future__
import print_function
9 from distutils.util
import strtobool
10 from time
import sleep
23 runCommandClient = rospy.ServiceProxy(
"run_command", RunCommand)
28 Auxiliary function to manage the verbosity of runCommandClient
29 verbosity = 0: simply execute runCommandClient
30 verbosity = 1 (default): if runCommandClient returns something on the standard output or standard error, print it
31 verbosity = 2: print the whole answer returned by runCommandClient
40 elif verbosity == 1
and (out.standardoutput
or out.standarderror):
41 print(
"command: " + code)
42 if out.standardoutput:
43 print(
"standardoutput: " + out.standardoutput)
45 print(
"standarderror: " + out.standarderror)
51 Auxiliary function to quickly extract return values from runCommandClient.
52 This will only work when the result in a plain object data type (such as an in or float) or a string
57 def launch_script(code, title, description="", verbosity=1, interactive=True):
59 input(title +
": " + description)
66 if line ==
"" or line.startswith(indent):
67 codeblock +=
"\n" + line
71 rospy.logdebug(answer)
73 if line !=
"" and line[0] !=
"#":
74 if line.endswith(
":"):
79 rospy.logdebug(answer)
80 rospy.loginfo(
"...done with " + title)
83 def run_test(appli, verbosity=1, interactive=True):
85 rospy.loginfo(
"Waiting for run_command")
86 rospy.wait_for_service(
"/run_command")
87 rospy.loginfo(
"...ok")
89 rospy.loginfo(
"Waiting for start_dynamic_graph")
90 rospy.wait_for_service(
"/start_dynamic_graph")
91 rospy.loginfo(
"...ok")
93 runCommandStartDynamicGraph = rospy.ServiceProxy(
"start_dynamic_graph", Empty)
95 initCode = open(appli,
"r").read().split(
"\n")
97 rospy.loginfo(
"Stack of Tasks launched")
100 initCode,
"initialize SoT", verbosity=verbosity, interactive=interactive
103 input(
"Wait before starting the dynamic graph")
104 runCommandStartDynamicGraph()
106 except rospy.ServiceException
as e:
107 rospy.logerr(
"Service call failed: %s" % e)
111 c =
input(text +
" [y/N] ")
123 print(
"Calibrating sensors...")
126 print(
"Sensors are calibrated!")
127 print(
"You can now put the robot on the ground")
129 print(
"Skipping sensor calibration")
137 c =
input(
"Calibrate wrist force sensors? [y/N] ")
143 input(
"Wait before running the calibration")
144 print(
"Calibrating sensors...")
147 print(
"Sensors are calibrated!")
149 print(
"Skipping sensor calibration")
155 sot_talos_balance_folder =
False
156 print(
"No folder data")
158 test_folder = argv[1]
159 sot_talos_balance_folder =
False
160 print(
"Using folder " + test_folder)
163 raise ValueError(
"Unrecognized option: " + argv[1])
164 test_folder = argv[2]
165 sot_talos_balance_folder =
True
166 print(
"Using folder " + test_folder +
" from sot_talos_balance")
168 raise ValueError(
"Bad options")
171 print(
"Sending folder info...")
172 if test_folder
is None:
176 runCommandClient(
"sot_talos_balance_folder = " + str(sot_talos_balance_folder))
178 return test_folder, sot_talos_balance_folder