6 from geometry_msgs.msg
import TwistStamped
7 from sensor_msgs.msg
import JointState
8 import termios, fcntl, sys, os
12 from std_srvs.srv
import Empty
16 twist_topic=
"/uwsim/g500_B/twist_command" 17 joint_topic=
"/uwsim/g500_B/joint_command" 23 fd = sys.stdin.fileno()
24 oldterm = termios.tcgetattr(fd)
25 newattr = termios.tcgetattr(fd)
26 newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
27 termios.tcsetattr(fd, termios.TCSANOW, newattr)
28 oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
29 fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
32 pubTwist = rospy.Publisher(twist_topic, TwistStamped,queue_size=1)
33 pubJoint = rospy.Publisher(joint_topic, JointState,queue_size=1)
34 rospy.init_node(
'keyboardCommand_B')
38 while not rospy.is_shutdown():
39 msgTwist = TwistStamped()
40 msgJoint = JointState()
48 msgTwist.twist.angular.y=-baseVelocity
50 msgTwist.twist.angular.y=baseVelocity
52 msgTwist.twist.angular.z=baseVelocity
54 msgTwist.twist.angular.z=-baseVelocity
56 msgTwist.twist.linear.x = baseVelocity
58 msgTwist.twist.linear.x = -baseVelocity
60 msgTwist.twist.linear.y = baseVelocity
62 msgTwist.twist.linear.y = -baseVelocity
64 msgTwist.twist.linear.z = baseVelocity
66 msgTwist.twist.linear.z = -baseVelocity
68 msgTwist.twist.angular.x = -baseVelocity
70 msgTwist.twist.angular.x = baseVelocity
73 msgJoint.name.append(
"Slew")
74 msgJoint.velocity.append(baseJoint)
76 msgJoint.name.append(
"Shoulder")
77 msgJoint.velocity.append(baseJoint)
79 msgJoint.name.append("Elbow")
80 msgJoint.velocity.append(baseJoint)
82 msgJoint.name.append(
"JawRotate")
83 msgJoint.velocity.append(baseJoint)
85 msgJoint.name.append(
"JawOpening")
86 msgJoint.velocity.append(baseJoint)
88 msgJoint.name.append(
"Slew")
89 msgJoint.velocity.append(-baseJoint)
91 msgJoint.name.append(
"Shoulder")
92 msgJoint.velocity.append(-baseJoint)
94 msgJoint.name.append(
"Elbow")
95 msgJoint.velocity.append(-baseJoint)
97 msgJoint.name.append(
"JawRotate")
98 msgJoint.velocity.append(-baseJoint)
100 msgJoint.name.append(
"JawOpening")
101 msgJoint.velocity.append(-baseJoint)
105 print "baseVelocity: " , baseVelocity
107 if baseVelocity > 0.2:
109 elif baseVelocity > 0:
113 print "baseVelocity: " , baseVelocity
116 print "jointVelocity: " , baseJoint
124 print "jointVelocity: ", baseJoint
126 print 'wrong key pressed' 128 c = sys.stdin.read(1)
132 pubTwist.publish(msgTwist)
133 pubJoint.publish(msgJoint)
138 termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
139 fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)