test_external_power.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2012, Yujin Robot
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Yujin Robot nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 # Author: Younghun Ju <yhju@yujinrobot.com> <yhju83@gmail.com>
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     #termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
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 #            sys.stdout.write(label[idx]+'[\033[1mOn\033[0m ] ')
00068             sys.stdout.write('[ \033[1mOn\033[0m] ')
00069         else: 
00070 #            sys.stdout.write(label[idx]+'[Off] ')
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 #print "If you want to control the timing of publish, uses -p option."
00099 #print ""
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 #print "p: publish power on/off status"
00108 print "q: quit"
00109 print ""
00110 print "  3.3V  5.0V 12V5A 12V1A"
00111 #print " [ On] [Off] [ On] [Off]"
00112 
00113 # reset current state of external powers
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         #print digital_output.values    
00128 #    elif key == '\n' or key == 'p' or key == 'P':
00129         pub.publish(digital_output)
00130         #print ' - published [', datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %p %I:%M:%S"), ']'
00131         #rate.sleep()
00132 


kobuki_testsuite
Author(s): Jorge Santos Simon
autogenerated on Wed Sep 16 2015 04:35:48