virtual_motors.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 import rospy, math
5 from geometry_msgs.msg import Twist
6 import subprocess
7 
8 
10  swfile = "/dev/rtmotoren0"
11  lfile = "/dev/rtmotor_raw_l0"
12  rfile = "/dev/rtmotor_raw_r0"
13  vel = Twist()
14  sound_count = 0
15  while not rospy.is_shutdown():
16  try:
17  with open(swfile, "r") as f:
18  motor_power_status = f.readline().rstrip()
19  if motor_power_status == "0":
20  sound_count = 0
21  if motor_power_status == "1" and sound_count == 0:
22  subprocess.call("aplay $(rospack find raspimouse_control)/misc/ms_sound.wav", shell=True)
23  sound_count = 1
24  if motor_power_status == "1":
25  with open(lfile, "r") as lf, \
26  open(rfile, "r") as rf:
27  lhz_str = lf.readline().rstrip()
28  rhz_str = rf.readline().rstrip()
29  if len(lhz_str) == 0:
30  lhz = 0
31  else:
32  try:
33  lhz = int(lhz_str)
34  except:
35  lhz = 0
36  if len(rhz_str) == 0:
37  rhz = 0
38  else:
39  try:
40  rhz = int(rhz_str)
41  except:
42  rhz = 0
43  vel.linear.x = (lhz + rhz) * 9 * math.pi / 160000.0
44  vel.angular.z = (rhz - lhz) * math.pi / 800.0
45  print(vel)
46  pub.publish(vel)
47 
48  except rospy.ROSInterruptException:
49  pass
50 
51 
52 if __name__ == "__main__":
53  rospy.init_node("virtual_motors")
54  pub = rospy.Publisher(rospy.get_namespace() + "diff_drive_controller/cmd_vel", Twist, queue_size=10)
56  rospy.spin()
def get_motor_freq()


raspimouse_control
Author(s): Daisuke Sato , Yuki Watanabe
autogenerated on Mon Jun 10 2019 14:36:49