7 from geometry_msgs.msg
import Twist
8 from std_msgs.msg
import Bool
11 enfile =
'/dev/rtmotoren0' 14 with open(enfile,
'w')
as f:
15 if message.on:
print >> f,
'1' 18 rospy.logerr(
"cannot write to " + enfile)
24 lfile =
'/dev/rtmotor_raw_l0' 25 rfile =
'/dev/rtmotor_raw_r0' 30 print >> lf, str(message.left)
31 print >> rf, str(message.right)
33 rospy.logerr(
"cannot write to rtmotor_raw_*")
39 lfile =
'/dev/rtmotor_raw_l0' 40 rfile =
'/dev/rtmotor_raw_r0' 43 forward_hz = 80000.0*message.linear.x/(9*math.pi)
45 rot_hz = 400.0*message.angular.z/math.pi
49 lf.write(str(int(round(forward_hz - rot_hz))) +
'\n')
50 rf.write(str(int(round(forward_hz + rot_hz))) +
'\n')
52 rospy.logerr(
"cannot write to rtmotor_raw_*")
58 devfile =
'/dev/rtmotor0' 61 with open(devfile,
'w')
as f:
62 print >> f,
"%s %s %s" % (message.left, message.right, message.duration)
64 rospy.logerr(
"cannot write to " + devfile)
69 if __name__ ==
'__main__':
70 rospy.init_node(
'rtmotor')
71 sub = rospy.Subscriber(
'motor_raw', MotorFreqs, callback_motor_raw)
72 sub = rospy.Subscriber(
'cmd_vel', Twist, callback_cmd_vel)
73 srv = rospy.Service(
'switch_motors', SwitchMotors, callback_motor_sw)
74 srv = rospy.Service(
'put_motor_freqs', PutMotorFreqs, callback_put_freqs)
def callback_motor_sw(message)
def callback_put_freqs(message)
def callback_motor_raw(message)
def callback_cmd_vel(message)