7 from sensor_msgs.msg
import Joy
8 from controller_manager_msgs.srv
import ListControllers
12 from controllers_info
import *
23 m =
"Choose an axis to move with your current joy binding:\n" 24 m +=
"0. linear.x\t1. linear.y\t2. linear.z\n" 25 m +=
"3. angular.x\t4. angular.y\t5. angular.z\n" 30 m =
"Choose a category to move with your current joy binding:\n" 31 m +=
"0. position\t1. velocity\n" 32 m +=
"2. acceleration\t3. effort\n" 38 for i, action
in enumerate(actions):
39 d[i] = {
"button": action.button,
41 "value": action.value,
42 "joint": action.joint,
43 "msg_field": action.msg_field
50 for controller
in controllers:
51 if controller.joyActions:
52 d[controller.name] = {
"type": controller.type,
53 "topic": controller.topic,
61 filename = config_file_location+ os.sep+
"config_"+datetime.datetime.now().strftime(
"%d-%m-%Y_%H-%M-%S")+
".yaml" 62 with open(filename,
"w")
as outfile:
65 print(
"Saved at {}".format(filename))
73 print(
"(Accepted answers: {})".format(accepted_ans))
81 if not accepted_ans
or inp
in accepted_ans:
99 print(
"Please provide a number!")
107 if saved_buti != -1
or saved_axi != -1:
119 global saved_axi, saved_buti
120 max_ax = max(map(abs, msg.axes))
123 if min(msg.axes) == -max_ax
and max_ax !=0:
124 axis_i = -1
if max_ax == 0
else msg.axes.index(-max_ax)
126 axis_i = -1
if max_ax == 0
else msg.axes.index(max_ax)
128 button_i = msg.buttons.index(1)
130 if button_i != -1
and button_i != saved_buti:
132 if axis_i != -1
and axis_i != saved_axi:
134 saved_buti = button_i
if button_i != -1
else saved_buti
135 saved_axi = axis_i
if axis_i != -1
else saved_axi
137 combo =
"[Axis{}]".format(saved_axi)
139 if combo
is not None:
140 combo +=
"+[Button{}]".format(saved_buti)
142 combo =
"[Button{}]".format(saved_buti)
149 print(
"Controls for {}".format(curr_controller.name))
151 if saved_axi != -1
or saved_buti != -1:
152 print(
"Press enter on your keyboard to continue with the current configuration...")
156 os.system(
"cls" if os.name ==
"nt" else "clear")
161 while msvcrt.kbhit():
164 termios.tcflush(sys.stdin, termios.TCIOFLUSH)
168 global read_joy, keepItUp, curr_controller, saved_buti, saved_axi, ui
169 ans =
youTalkinToMe(
"Do you want to see all the discovered controllers?", YES+NO+QUIT)
176 print(
"Initiating joystick configuration...")
179 for controller
in controllers:
181 if controller.type
in supported_controllers:
185 ans =
youTalkinToMe(
"Do you want to assign a joystick command to {}?".format(controller.name), YES+NO+QUIT)
187 ans =
youTalkinToMe(
"Do you want to assign another joystick command to {}?".format(controller.name), YES+NO+QUIT)
192 curr_controller = controller
193 for joint
in controller.joints:
195 if controller.type
in ignore_controller_joints:
198 ans =
youTalkinToMe(
"[{}] Do you want to assign a joystick command to {}?".format(controller.name, joint), YES+NO+QUIT)
202 print(
"Now use your controller to set a new configuration...")
203 t = threading.Thread(target=youTalkinToMeAboutThreads, args=(
"Don't touch your keyboard now!",))
206 while read_joy
and keepItUp
and not rospy.is_shutdown():
207 if ui[0]
is not None and (saved_axi != -1
or saved_buti != -1):
210 if controller.type
in twist_controllers:
212 msg_field = twisty_dict[ans]
213 elif controller.type
in joint_traj_controllers:
215 msg_field = jt_dict[ans]
218 if controller.type
not in non_step_controllers:
223 ans =
youTalkinToMe(
"Do you want to save the current joy binding?", YES+NO+QUIT)
225 controller.joyActions.append(
JoyAction(saved_buti, saved_axi, val, joint, msg_field))
226 print(
"Saved! (Not on disk yet!)")
234 if controller.type
in ignore_controller_joints:
243 ans =
youTalkinToMe(
"Do you want to save your configuration?", YES+NO+QUIT)
251 if ans
in YES
or ans
in QUIT:
256 global config_file_location
257 rospy.init_node(
"jointstick_setup")
258 config_file_location = rospy.get_param(
"config_file_location", os.path.expanduser(
"~"))
259 print(
"Config file save location was set as: {}".format(config_file_location))
260 rospy.Subscriber(
"/joy", Joy, joyCallback)
261 controllers_srv = rospy.ServiceProxy(
"controller_manager/list_controllers", ListControllers)
263 print(
"Reading available controllers....")
265 rospy.wait_for_service(
"controller_manager/list_controllers")
267 c = controllers_srv().controller
270 if controller.type !=
"joint_state_controller/JointStateController":
271 controllers.append(
Controller(controller.name, controller.type, [], controller.claimed_resources[0].resources, controller.name+topic_extension[controller.type]))
277 while not rospy.is_shutdown()
and keepItUp:
def youTalkinToMeAboutFloats(prompt)
def youTalkinToMe(prompt, accepted_ans)
def configureJoyActions()
def youTalkinToMeAboutThreads(prompt)
def joyActionsToDict(actions)