00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 import roslib; roslib.load_manifest('kobuki_testsuite')
00038 import rospy
00039 import sys, select, termios, tty
00040 import time
00041 from datetime import datetime
00042
00043 from kobuki_msgs.msg import DigitalOutput, Led, Sound
00044
00045
00046 def getKey():
00047 tty.setraw(sys.stdin.fileno())
00048 rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
00049 if rlist:
00050 key = sys.stdin.read(1)
00051 else:
00052 key = ''
00053
00054
00055 return key
00056
00057 def printStatus(ext_values, dgt_values, leds):
00058 sys.stdout.write('\r ')
00059 for idx in range(0,4):
00060 if ext_values[idx]:
00061 sys.stdout.write('[ \033[1mOn\033[0m] ')
00062 else:
00063 sys.stdout.write('[Off] ')
00064 sys.stdout.write('| [\033[1m'+textBindings[leds[0].value]+'\033[0m] ')
00065 sys.stdout.write('[\033[1m'+textBindings[leds[1].value]+'\033[0m] | ')
00066
00067 for idx in range(0,4):
00068 if dgt_values[idx]:
00069 sys.stdout.write('[ \033[1mOn\033[0m] ')
00070 else:
00071 sys.stdout.write('[Off] ')
00072
00073 sys.stdout.write('\r')
00074 sys.stdout.flush()
00075
00076 keyBindings1 = {
00077 '1':0,
00078 '2':1,
00079 '3':2,
00080 '4':3,
00081 }
00082
00083 keyBindings2 = {
00084 '5':0,
00085 '6':1,
00086 }
00087
00088 keyBindings3 = {
00089 '7':0,
00090 '8':1,
00091 '9':2,
00092 '0':3,
00093 }
00094
00095 keyBindings4 = {
00096 'a':Sound.ON,
00097 's':Sound.OFF,
00098 'd':Sound.RECHARGE,
00099 'f':Sound.BUTTON,
00100 'z':Sound.ERROR,
00101 'x':Sound.CLEANINGSTART,
00102 'c':Sound.CLEANINGEND,
00103 }
00104
00105 colorBindings = {
00106 Led.GREEN:Led.ORANGE,
00107 Led.ORANGE:Led.RED,
00108 Led.RED:Led.BLACK,
00109 Led.BLACK:Led.GREEN,
00110 }
00111
00112 textBindings = {
00113 Led.GREEN:' Green',
00114 Led.ORANGE:'Orange',
00115 Led.RED:' Red',
00116 Led.BLACK:' Black',
00117 }
00118
00119
00120 settings = termios.tcgetattr(sys.stdin)
00121
00122 def clearing():
00123 sys.stdout.write('\n\r')
00124 sys.stdout.flush()
00125 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
00126
00127
00128 rospy.init_node("test_output")
00129 rospy.on_shutdown(clearing)
00130 rate = rospy.Rate(10)
00131
00132 pub_ext_pwr = rospy.Publisher('/mobile_base/commands/external_power',DigitalOutput)
00133 pub_dgt_out = rospy.Publisher('/mobile_base/commands/digital_output',DigitalOutput)
00134 pub = []
00135 pub.append(rospy.Publisher('/mobile_base/commands/led1',Led))
00136 pub.append(rospy.Publisher('/mobile_base/commands/led2',Led))
00137 pub_sounds = rospy.Publisher('/mobile_base/commands/sound',Sound)
00138
00139
00140 external_power = DigitalOutput()
00141 external_power.values = [ True, True, True, True ]
00142 external_power.mask = [ True, True, True, True ]
00143
00144 digital_output = DigitalOutput()
00145 digital_output.values = [ True, True, True, True ]
00146 digital_output.mask = [ True, True, True, True ]
00147
00148 leds = []
00149 leds.append(Led())
00150 leds.append(Led())
00151 leds[0].value = Led.GREEN
00152 leds[1].value = Led.GREEN
00153
00154
00155 while not pub_ext_pwr.get_num_connections():
00156 rate.sleep()
00157 pub_ext_pwr.publish(external_power)
00158
00159 while not pub_dgt_out.get_num_connections():
00160 rate.sleep()
00161 pub_dgt_out.publish(digital_output)
00162
00163 while not pub[0].get_num_connections():
00164 rate.sleep()
00165 pub[0].publish(leds[0])
00166
00167 while not pub[1].get_num_connections():
00168 rate.sleep()
00169 pub[1].publish(leds[1])
00170
00171
00172 print ""
00173 print "Control Every Output of Kobuki"
00174 print "------------------------------"
00175 print "1: Toggle the state of 3.3V"
00176 print "2: Toggle the state of 5V"
00177 print "3: Toggle the state of 12V5A(arm)"
00178 print "4: Toggle the state of 12V1A(kinect)"
00179 print ""
00180 print "5: Control Led #1"
00181 print "6: Control Led #2"
00182 print ""
00183 print "7~0: Toggle the state of DigitalOut_0~3"
00184 print ""
00185 print "Play Sounds"
00186 print "-----------"
00187 print "a: On s: Off d: Recharge f: Button z: Error x: CleaningStart c: CleaningEnd"
00188 print ""
00189 print "q: Quit"
00190 print ""
00191 print ""
00192 print " 3.3V 5.0V 12V5A 12V1A | Led #1 Led #2 | DO_0 DO_1 DO_2 DO_3"
00193
00194
00195 while not rospy.is_shutdown():
00196 printStatus(external_power.values, digital_output.values, leds)
00197 key = getKey()
00198 if key == '': continue
00199 if key == 'q' or key == 'Q':
00200 rospy.signal_shutdown('user reuest')
00201
00202 elif key in keyBindings1.keys():
00203 external_power.values[keyBindings1[key]] ^= True
00204 printStatus(external_power.values, digital_output.values, leds)
00205 pub_ext_pwr.publish(external_power)
00206
00207 elif key in keyBindings3.keys():
00208 digital_output.values[keyBindings3[key]] ^= True
00209 printStatus(external_power.values, digital_output.values, leds)
00210 pub_dgt_out.publish(digital_output)
00211
00212 elif key in keyBindings2.keys():
00213 leds[keyBindings2[key]].value = colorBindings[ leds[keyBindings2[key]].value ]
00214 printStatus(external_power.values, digital_output.values, leds)
00215 pub[keyBindings2[key]].publish(leds[keyBindings2[key]])
00216 elif key in keyBindings4.keys():
00217 pub_sounds.publish(keyBindings4[key])
00218
00219