Go to the documentation of this file.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
00044 
00045 def getKey():
00046     tty.setraw(sys.stdin.fileno())
00047     rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
00048     if rlist:
00049         key = sys.stdin.read(1)
00050     else:
00051         key = ''
00052 
00053     
00054     return key
00055 
00056 label = [
00057     '3.3V',
00058     '5V',
00059     '12V5A',
00060     '12V1A',
00061 ]
00062 
00063 def printStatus(values):
00064     sys.stdout.write('\r ')
00065     for idx in range(0,4):
00066         if values[idx]:
00067 
00068             sys.stdout.write('[ \033[1mOn\033[0m] ')
00069         else: 
00070 
00071             sys.stdout.write('[Off] ')
00072     sys.stdout.write('\r')
00073     sys.stdout.flush()
00074 
00075 
00076 keyBindings = {
00077     '1':0,
00078     '2':1,
00079     '3':2,
00080     '4':3,
00081 }
00082 
00083 settings = termios.tcgetattr(sys.stdin)
00084 
00085 def clearing():
00086     sys.stdout.write('\r\n')
00087     sys.stdout.flush()
00088     termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
00089 
00090 rospy.init_node("test_external_power")
00091 rospy.on_shutdown(clearing)
00092 pub = rospy.Publisher('/mobile_base/commands/external_power',DigitalOutput)
00093 rate = rospy.Rate(10)
00094 digital_output = DigitalOutput()
00095 digital_output.values = [ True, True, True, True ]
00096 digital_output.mask = [ True, True, True, True ]
00097 print ""
00098 
00099 
00100 print "Control External Power"
00101 print "----------------------"
00102 print "1: Toggle the state of 3.3V"
00103 print "2: Toggle the state of 5V"
00104 print "3: Toggle the state of 12V5A(arm)"
00105 print "4: Toggle the state of 12V1A(kinect)"
00106 print ""
00107 
00108 print "q: quit"
00109 print ""
00110 print "  3.3V  5.0V 12V5A 12V1A"
00111 
00112 
00113 
00114 while pub.get_num_connections():
00115     rate.sleep()
00116 pub.publish(digital_output)
00117 
00118 while not rospy.is_shutdown():
00119     key = getKey()
00120     printStatus(digital_output.values)
00121     if key == '': continue
00122     if key == 'q' or key == 'Q': 
00123        rospy.signal_shutdown('user request')
00124     elif key in keyBindings.keys():
00125         digital_output.values[keyBindings[key]] ^= True
00126         printStatus(digital_output.values)
00127         
00128 
00129         pub.publish(digital_output)
00130         
00131         
00132