joy_to_jog_joint.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Take joystick cmds. Republish them as JogJoint
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 JogJoint
15 from sensor_msgs.msg import Joy
16 
18 
19  def __init__(self):
20  self.pub = rospy.Publisher('jog_joint', JogJoint, queue_size=1)
21 
22  # Convert to JogJoint and republish
23  def callback(self, joy):
24 
25  msg = JogJoint()
26 
27  msg.header.stamp = rospy.Time.now()
28  msg.header.frame_id = 'base_link'
29  msg.name = ['joint1', 'joint2', 'joint3', 'joint4', 'joint5', 'joint6']
30  # These buttons are binary
31  msg.displacement = [0]*6
32  msg.displacement[0] = 0.05*(-joy.buttons[4] + joy.buttons[5])
33  msg.displacement[1] = 0.05*(joy.axes[0])
34  msg.displacement[2] = 0.05*(joy.axes[1])
35  msg.displacement[3] = 0.05*(joy.buttons[0] - joy.buttons[1])
36  msg.displacement[4] = 0.05*(joy.buttons[2] - joy.buttons[3])
37  msg.displacement[5] = 0.05*(joy.buttons[7] - joy.buttons[6])
38 
39  self.pub.publish(msg)
40 
41  def republish(self):
42  rospy.Subscriber("joy", Joy, self.callback)
43 
44  rospy.spin()
45 
46 if __name__ == '__main__':
47  rospy.init_node('joy_to_jog_joint', anonymous=True)
48  republisher = joy_to_jog_joint()
49  republisher.republish()


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