test_external_power.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 # Author: Younghun Ju <yhju@yujinrobot.com> <yhju83@gmail.com>
36 
37 import roslib; roslib.load_manifest('kobuki_testsuite')
38 import rospy
39 import sys, select, termios, tty
40 import time
41 from datetime import datetime
42 
43 from kobuki_msgs.msg import DigitalOutput
44 
45 def getKey():
46  tty.setraw(sys.stdin.fileno())
47  rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
48  if rlist:
49  key = sys.stdin.read(1)
50  else:
51  key = ''
52 
53  #termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
54  return key
55 
56 label = [
57  '3.3V',
58  '5V',
59  '12V5A',
60  '12V1A',
61 ]
62 
63 def printStatus(values):
64  sys.stdout.write('\r ')
65  for idx in range(0,4):
66  if values[idx]:
67 # sys.stdout.write(label[idx]+'[\033[1mOn\033[0m ] ')
68  sys.stdout.write('[ \033[1mOn\033[0m] ')
69  else:
70 # sys.stdout.write(label[idx]+'[Off] ')
71  sys.stdout.write('[Off] ')
72  sys.stdout.write('\r')
73  sys.stdout.flush()
74 
75 
76 keyBindings = {
77  '1':0,
78  '2':1,
79  '3':2,
80  '4':3,
81 }
82 
83 settings = termios.tcgetattr(sys.stdin)
84 
85 def clearing():
86  sys.stdout.write('\r\n')
87  sys.stdout.flush()
88  termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
89 
90 rospy.init_node("test_external_power")
91 rospy.on_shutdown(clearing)
92 pub = rospy.Publisher('/mobile_base/commands/external_power',DigitalOutput)
93 rate = rospy.Rate(10)
94 digital_output = DigitalOutput()
95 digital_output.values = [ True, True, True, True ]
96 digital_output.mask = [ True, True, True, True ]
97 print ""
98 #print "If you want to control the timing of publish, uses -p option."
99 #print ""
100 print "Control External Power"
101 print "----------------------"
102 print "1: Toggle the state of 3.3V"
103 print "2: Toggle the state of 5V"
104 print "3: Toggle the state of 12V5A(arm)"
105 print "4: Toggle the state of 12V1A(kinect)"
106 print ""
107 #print "p: publish power on/off status"
108 print "q: quit"
109 print ""
110 print " 3.3V 5.0V 12V5A 12V1A"
111 #print " [ On] [Off] [ On] [Off]"
112 
113 # reset current state of external powers
114 while pub.get_num_connections():
115  rate.sleep()
116 pub.publish(digital_output)
117 
118 while not rospy.is_shutdown():
119  key = getKey()
120  printStatus(digital_output.values)
121  if key == '': continue
122  if key == 'q' or key == 'Q':
123  rospy.signal_shutdown('user request')
124  elif key in keyBindings.keys():
125  digital_output.values[keyBindings[key]] ^= True
126  printStatus(digital_output.values)
127  #print digital_output.values
128 # elif key == '\n' or key == 'p' or key == 'P':
129  pub.publish(digital_output)
130  #print ' - published [', datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %p %I:%M:%S"), ']'
131  #rate.sleep()
132 


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