joy_to_jog_frame.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Take joystick cmds. Republish them as JogFrame
4 
5 # RB: +x, LB: -x
6 # L on L dpad: +x
7 # Up on L dpad: +z
8 
9 # R on R stick: +Rx
10 # Up on R stick: +Ry
11 # B: +Rz, A: -Rz
12 
13 import rospy
14 from jog_msgs.msg import JogFrame
15 from sensor_msgs.msg import Joy
16 
18 
19  def __init__(self):
20  self.enable_button = rospy.get_param('~enable_button', 4)
21  self.angular_button = rospy.get_param('~angular_button', 5)
22  self.axis_linear = rospy.get_param('~axis_linear', {'x': 0, 'y': 1, 'z': 4})
23  self.axis_angular = rospy.get_param('~axis_angular', {'x': 0, 'y': 1, 'z': 4})
24  self.scale_linear = rospy.get_param('~scale_linear', {'x': 0.05, 'y': 0.05, 'z': 0.05})
25  self.scale_angular = rospy.get_param('~scales_angular', {'x': 0.05, 'y': 0.05, 'z': 0.05})
26 
27  self.pub = rospy.Publisher('jog_frame', JogFrame, queue_size=1)
28 
29  # Convert to JogFrame and republish
30  def callback(self, joy):
31 
32  if not joy.buttons[self.enable_button]:
33  return
34 
35  msg = JogFrame()
36 
37  msg.header.stamp = rospy.Time.now()
38  msg.header.frame_id = rospy.get_param('~frame_id', 'base_link')
39  msg.group_name = rospy.get_param('~group_name', 'manipulator')
40  msg.link_name = rospy.get_param('~link_name', 'tool0')
41 
42  if joy.buttons[self.angular_button]:
43  msg.angular_delta.x = self.scale_angular['x']*joy.axes[self.axis_angular['x']]
44  msg.angular_delta.y = self.scale_angular['y']*joy.axes[self.axis_angular['y']]
45  msg.angular_delta.z = self.scale_angular['z']*joy.axes[self.axis_angular['z']]
46  else:
47  # These buttons are binary
48  msg.linear_delta.x = self.scale_linear['x']*joy.axes[self.axis_linear['x']]
49  msg.linear_delta.y = self.scale_linear['y']*joy.axes[self.axis_linear['y']]
50  msg.linear_delta.z = self.scale_linear['z']*joy.axes[self.axis_linear['z']]
51 
52  msg.avoid_collisions = True
53  self.pub.publish(msg)
54 
55  def republish(self):
56  rospy.Subscriber(rospy.get_param('~sub_topic', 'joy'), Joy, self.callback)
57 
58  rospy.spin()
59 
60 if __name__ == '__main__':
61  rospy.init_node('joy_to_jog_frame', anonymous=True)
62  republisher = joy_to_jog_frame()
63  republisher.republish()


jog_controller
Author(s): Ryosuke Tajima
autogenerated on Sun May 17 2020 03:25:01