3 from geometry_msgs.msg
import TwistStamped
4 from sensor_msgs.msg
import JointState
5 import termios, fcntl, sys, os
9 from std_srvs.srv
import Empty
13 twist_topic_A=
"/uwsim/g500_A/twist_command" 14 twist_topic_B=
"/uwsim/g500_B/twist_command" 19 fd = sys.stdin.fileno()
20 oldterm = termios.tcgetattr(fd)
21 newattr = termios.tcgetattr(fd)
22 newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
23 termios.tcsetattr(fd, termios.TCSANOW, newattr)
24 oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
25 fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
28 pubTwist_A = rospy.Publisher(twist_topic_A, TwistStamped, queue_size=1)
29 pubTwist_B = rospy.Publisher(twist_topic_B, TwistStamped, queue_size=1)
30 rospy.init_node(
'keyboardCommandVeh_both')
31 msgTwist = TwistStamped()
36 while not rospy.is_shutdown():
39 msgTwist = TwistStamped()
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
74 print "baseVelocity: " , baseVelocity
76 if baseVelocity > 0.2:
78 elif baseVelocity > 0:
82 print "baseVelocity: " , baseVelocity
84 print 'wrong key pressed, and reset all vehicle velocities' 85 msgTwist = TwistStamped()
86 modality =
not modality
93 print 'velocity vehicles published:' 94 print (msgTwist.twist.linear.x, msgTwist.twist.linear.y, msgTwist.twist.linear.z)
95 print (msgTwist.twist.angular.x, msgTwist.twist.angular.y, msgTwist.twist.angular.z )
96 pubTwist_A.publish(msgTwist)
97 pubTwist_B.publish(msgTwist)
102 termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
103 fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)