check_driver_io.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys, time
4 import rospy
5 from raspimouse_ros.srv import *
6 from raspimouse_ros.msg import *
7 from std_msgs.msg import UInt16
8 
9 
10 def switch_motors(onoff):
11  rospy.wait_for_service('/switch_motors')
12  try:
13  p = rospy.ServiceProxy('/switch_motors', SwitchMotors)
14  res = p(onoff)
15  return res.accepted
16  except rospy.ServiceException, e:
17  print "Service call failed: %s"%e
18  else:
19  return False
20 
21 def raw_control(left_hz,right_hz):
22  pub = rospy.Publisher('/motor_raw', MotorFreqs, queue_size=10)
23 
24  if not rospy.is_shutdown():
25  d = MotorFreqs()
26  d.left = left_hz
27  d.right = right_hz
28  pub.publish(d)
29 
30 def buzzer(hz):
31  pub = rospy.Publisher('/buzzer', UInt16, queue_size=10)
32  rospy.init_node('operation_checker', anonymous=True)
33 
34  if not rospy.is_shutdown():
35  pub.publish(hz)
36 
38  print "lightsensors:", data.left_forward, data.left_side, data.right_side, data.right_forward
39 
40 def switch_callback(data):
41  print "switches:",data.front, data.center, data.rear
42 
43 def sensors():
44  subls = rospy.Subscriber('/lightsensors', LightSensorValues, lightsensor_callback)
45  subsw = rospy.Subscriber('/switches', Switches, switch_callback)
46 
47 
48 def pos_control(left_hz,right_hz,time_ms):
49  rospy.wait_for_service('/put_motor_freqs')
50  try:
51  p = rospy.ServiceProxy('/put_motor_freqs', PutMotorFreqs)
52  res = p(left_hz,right_hz,time_ms)
53  return res.accepted
54  except rospy.ServiceException, e:
55  print "Service call failed: %s"%e
56  else:
57  return False
58 
59 if __name__ == "__main__":
60  ### buzzer test ###
61  print >> sys.stderr, "test of the buzzer"
62  buzzer(1000)
63  time.sleep(2.0)
64  buzzer(0)
65 
66  ### motor_raw test ###
67  print >> sys.stderr, "test of raw control of the motors"
68  if not switch_motors(True):
69  print "[check failed]: motors are not empowered"
70 
71  raw_control(0,0)
72  time.sleep(0.5)
73  raw_control(-300,300)
74  time.sleep(0.5)
75  raw_control(0,0)
76  time.sleep(0.5)
77  raw_control(300,-300)
78  time.sleep(0.5)
79  raw_control(0,0)
80 
81  ### motor_pos test ###
82  print >> sys.stderr, "test of position control of the motors"
83  pos_control(300,300,1000)
84  pos_control(-300,-300,1000)
85 
86  if not switch_motors(False):
87  print "[check failed]: motors are not turned off"
88 
89  ### lightsensor test ###
90  print >> sys.stderr, "test of sensors"
91  sensors()
92  time.sleep(10.0)
93 
94 
def raw_control(left_hz, right_hz)
def lightsensor_callback(data)
def pos_control(left_hz, right_hz, time_ms)
def switch_callback(data)
def switch_motors(onoff)


raspimouse_ros
Author(s):
autogenerated on Mon Jun 10 2019 14:27:02