37 import roslib; roslib.load_manifest(
'kobuki_testsuite')
39 import curses, sys, traceback
41 from tf.transformations
import euler_from_quaternion
42 from math
import degrees
44 from sensor_msgs.msg
import Imu
45 from geometry_msgs.msg
import Quaternion
46 from kobuki_msgs.msg
import SensorState
47 from kobuki_msgs.msg
import ButtonEvent
48 from kobuki_msgs.msg
import BumperEvent
49 from kobuki_msgs.msg
import WheelDropEvent
50 from kobuki_msgs.msg
import CliffEvent
51 from kobuki_msgs.msg
import PowerSystemEvent
52 from kobuki_msgs.msg
import DigitalInputEvent
55 quat = data.orientation
56 q = [quat.x, quat.y, quat.z, quat.w]
57 roll, pitch, yaw = euler_from_quaternion(q)
58 imu_string=str(
"Gyro Angle: [" +
"{0:+.4f}".format(yaw) +
" rad] ["\
59 +
"{0: >+7.2f}".format(degrees(yaw)) +
" deg]"\
60 +
" Rate: [" +
"{0:+.4f}".format(data.angular_velocity.z) +
" rad/s] ["\
61 +
"{0: >+7.2f}".format(degrees(data.angular_velocity.z)) +
" deg/s] ")
62 stdscr.addstr(5,3,imu_string)
65 stdscr.addstr(6,3,str(
"Analog input: [%4d, %4d, %4d, %4d]" \
66 %(data.analog_input[0], data.analog_input[1], \
67 data.analog_input[2], data.analog_input[3])))
70 digitalS = [
False,
False,
False,
False]
74 digitalS = data.values
76 button0 = { ButtonEvent.Button0:0, ButtonEvent.Button1:1, ButtonEvent.Button2:2, }
77 button1 = { ButtonEvent.RELEASED:
'Released', ButtonEvent.PRESSED:
'Pressed ', }
78 buttonS = [
'Released',
'Released',
'Released', ]
81 buttonS[button0[data.button]]=button1[data.state]
83 bumper0 = { BumperEvent.LEFT:0, BumperEvent.CENTER:1, BumperEvent.RIGHT:2, }
84 bumper1 = { BumperEvent.RELEASED:
'Released', BumperEvent.PRESSED:
'Pressed ', }
85 bumperS = [
'Released',
'Released',
'Released', ]
88 bumperS[bumper0[data.bumper]]=bumper1[data.state]
90 wheel0 = { WheelDropEvent.LEFT:0, WheelDropEvent.RIGHT:1, }
91 wheel1 = { WheelDropEvent.RAISED:
'Raised ', WheelDropEvent.DROPPED:
'Dropped', }
92 wheelS = [
'Raised ',
'Raised ', ]
95 wheelS[wheel0[data.wheel]]=wheel1[data.state]
97 cliff0 = { CliffEvent.LEFT:0, CliffEvent.CENTER:1, CliffEvent.RIGHT:2, }
98 cliff1 = { CliffEvent.FLOOR:
'Floor', CliffEvent.CLIFF:
'Cliff', }
99 cliffS = [
'Floor',
'Floor',
'Floor',]
102 cliffS[cliff0[data.sensor]]=cliff1[data.state]
105 PowerSystemEvent.UNPLUGGED:
"Robot unplugged",
106 PowerSystemEvent.PLUGGED_TO_ADAPTER:
"Robot plugged to adapter",
107 PowerSystemEvent.PLUGGED_TO_DOCKBASE:
"Robot plugged to docking base",
108 PowerSystemEvent.CHARGE_COMPLETED:
"Robot charge completed",
109 PowerSystemEvent.BATTERY_LOW:
"Robot battery low",
110 PowerSystemEvent.BATTERY_CRITICAL:
"Robot battery critical", }
112 powerS =
"Not Available" 116 powerS = power0[data.event]
124 if __name__ ==
'__main__':
125 stdscr = curses.initscr()
126 stdscr.addstr(1,1,
"Test Every Input of Kobuki")
127 stdscr.addstr(2,1,
"--------------------------")
128 stdscr.addstr(3,1,
"q: Quit")
133 rospy.init_node(
'test_input')
134 rospy.on_shutdown(clearing)
135 rospy.Subscriber(
"/mobile_base/sensors/imu_data", Imu, ImuCallback )
136 rospy.Subscriber(
"/mobile_base/sensors/core", SensorState, SensorStateCallback )
137 rospy.Subscriber(
"/mobile_base/events/digital_input", DigitalInputEvent, DigitalInputEventCallback )
138 rospy.Subscriber(
"/mobile_base/events/button", ButtonEvent, ButtonEventCallback )
139 rospy.Subscriber(
"/mobile_base/events/bumper", BumperEvent, BumperEventCallback )
140 rospy.Subscriber(
"/mobile_base/events/wheel_drop", WheelDropEvent, WheelDropEventCallback )
141 rospy.Subscriber(
"/mobile_base/events/cliff", CliffEvent, CliffEventCallback )
142 rospy.Subscriber(
"/mobile_base/events/power_system",PowerSystemEvent,PowerEventCallback)
145 while not rospy.is_shutdown():
146 stdscr.addstr(7,3,str(
"Digital input: [%5s, %5s, %5s, %5s]"\
147 %(str(digitalS[0]), str(digitalS[1]), str(digitalS[2]), str(digitalS[3]))))
148 stdscr.addstr(8,3,str(
"Button: B0: %s B1: %s B2: %s"%(buttonS[0], buttonS[1], buttonS[2])))
149 stdscr.addstr(9,3,str(
"Bumper: Left: %s Center: %s Right: %s"%(bumperS[0], bumperS[1], bumperS[2])))
150 stdscr.addstr(10,3,str(
"WheelDrop: Left: %s Right: %s"%(wheelS[0], wheelS[1])))
151 stdscr.addstr(11,3,str(
"Cliff: Left: %s Center: %s Right: %s"%(cliffS[0], cliffS[1], cliffS[2])))
152 stdscr.addstr(12,3,str(
"Power: " +
"{0: <80s}".format(powerS)))
156 rospy.signal_shutdown(
'user request')
161 traceback.print_exc()