test_events.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2012, Yujin Robot
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of the Yujin Robot nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 import roslib; roslib.load_manifest('kobuki_testsuite')
36 import rospy
37 
38 from kobuki_msgs.msg import ButtonEvent
39 from kobuki_msgs.msg import BumperEvent
40 from kobuki_msgs.msg import WheelDropEvent
41 from kobuki_msgs.msg import CliffEvent
42 from kobuki_msgs.msg import PowerSystemEvent
43 from kobuki_msgs.msg import DigitalInputEvent
44 
46  if ( data.state == ButtonEvent.RELEASED ) :
47  state = "released"
48  else:
49  state = "pressed"
50  if ( data.button == ButtonEvent.Button0 ) :
51  button = "B0"
52  elif ( data.button == ButtonEvent.Button1 ) :
53  button = "B1"
54  else:
55  button = "B2"
56  rospy.loginfo("Button %s was %s."%(button, state))
57 
59  if ( data.state == BumperEvent.RELEASED ) :
60  state = "released"
61  else:
62  state = "pressed"
63  if ( data.bumper == BumperEvent.LEFT ) :
64  bumper = "Left"
65  elif ( data.bumper == BumperEvent.CENTER ) :
66  bumper = "Center"
67  else:
68  bumper = "Right"
69  rospy.loginfo("%s bumper is %s."%(bumper, state))
70 
72  if ( data.state == WheelDropEvent.RAISED ) :
73  state = "raised"
74  else:
75  state = "dropped"
76  if ( data.wheel == WheelDropEvent.LEFT ) :
77  wheel = "Left"
78  else:
79  wheel = "Right"
80  rospy.loginfo("%s wheel is %s."%(wheel, state))
81 
83  if ( data.state == CliffEvent.FLOOR ) :
84  state = "on the floor"
85  else:
86  state = "on the cliff"
87  if ( data.sensor == CliffEvent.LEFT ) :
88  cliff = "Left"
89  elif ( data.sensor == CliffEvent.CENTER ) :
90  cliff = "Centre"
91  else:
92  cliff = "Right"
93  rospy.loginfo("%s side of robot is %s."%(cliff, state))
94 
96  if ( data.event == PowerSystemEvent.UNPLUGGED ) :
97  rospy.loginfo("Robot unplugged")
98  elif ( data.event == PowerSystemEvent.PLUGGED_TO_ADAPTER ) :
99  rospy.loginfo("Robot plugged to adapter")
100  elif ( data.event == PowerSystemEvent.PLUGGED_TO_DOCKBASE ) :
101  rospy.loginfo("Robot plugged to docking base")
102  elif ( data.event == PowerSystemEvent.CHARGE_COMPLETED ) :
103  rospy.loginfo("Robot charge completed")
104  elif ( data.event == PowerSystemEvent.BATTERY_LOW ) :
105  rospy.loginfo("Robot battery low")
106  elif ( data.event == PowerSystemEvent.BATTERY_CRITICAL ) :
107  rospy.loginfo("Robot battery critical")
108  else:
109  rospy.loginfo("WARN: Unexpected power system event: %d"%(data.event))
110 
112  val_str = ""
113  for val in data.values:
114  val_str = "%s, %s" % (val_str, str(val))
115  rospy.loginfo("Digital input values: [" + val_str[2:] + "]")
116 
117 rospy.init_node("test_events")
118 rospy.Subscriber("/mobile_base/events/button",ButtonEvent,ButtonEventCallback)
119 rospy.Subscriber("/mobile_base/events/bumper",BumperEvent,BumperEventCallback)
120 rospy.Subscriber("/mobile_base/events/wheel_drop",WheelDropEvent,WheelDropEventCallback)
121 rospy.Subscriber("/mobile_base/events/cliff",CliffEvent,CliffEventCallback)
122 rospy.Subscriber("/mobile_base/events/power_system",PowerSystemEvent,PowerEventCallback)
123 rospy.Subscriber("/mobile_base/events/digital_input",DigitalInputEvent,InputEventCallback)
124 print ""
125 print "Try kobuki's hardware components; the following events should be reported:"
126 print " - buttons"
127 print " - bumpers"
128 print " - wheel drops"
129 print " - cliffs"
130 print " - plug/unplug adapter"
131 print " - dock/undock on base"
132 print " - charge completed"
133 print " - battery low/critical"
134 print " - digital input changes"
135 print ""
136 rospy.spin()
137 
def ButtonEventCallback(data)
Definition: test_events.py:45
def CliffEventCallback(data)
Definition: test_events.py:82
def BumperEventCallback(data)
Definition: test_events.py:58
def PowerEventCallback(data)
Definition: test_events.py:95
def WheelDropEventCallback(data)
Definition: test_events.py:71
def InputEventCallback(data)
Definition: test_events.py:111


kobuki_testsuite
Author(s): Jorge Santos Simon
autogenerated on Mon Jun 10 2019 13:45:22