fake_powerboard.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 PKG = 'pr2_power_board' # this package name
4 NAME = 'fake_powerboard'
5 
6 import roslib; roslib.load_manifest(PKG)
7 
8 import sys
9 import time
10 
11 import rospy
12 from pr2_msgs.msg import *
13 
14 from optparse import OptionParser
15 
16 import threading
17 from pr2_power_board.srv import PowerBoardCommand
18 
19 class PowerBoard(threading.Thread):
20  def __init__(self, options):
21  threading.Thread.__init__(self)
22  self.setDaemon(True)
23 
24  self.options = options
25 
26  self.pb = PowerBoardState()
27  self.pb.header.stamp = rospy.rostime.get_rostime()
28  self.pb.serial_num = 9999
29  self.pb.input_voltage = 80.123456
30  self.pb.circuit_state = [3,3,3]
31  self.pb.circuit_voltage = [70.123456,70.234567,70.345678]
32  if self.options.run_stop: self.pb.run_stop = 1
33  else: self.pb.run_stop = 0
34  if self.options.wireless_stop: self.pb.wireless_stop = 1
35  else: self.pb.wireless_stop = 0
36 
37  self.pub = rospy.Publisher("power_board/state", PowerBoardState)
38 
39  def power_board_control(self, msg):
40  if msg.command == "disable":
41  self.pb.circuit_state[msg.breaker_number] = 0
42  self.pb.circuit_voltage[msg.breaker_number] = 1
43  if msg.command == "stop":
44  if self.pb.circuit_state[msg.breaker_number] != 0:
45  self.pb.circuit_state[msg.breaker_number] = 1
46  self.pb.circuit_voltage[msg.breaker_number] = 19
47  if msg.command == "reset":
48  if self.pb.circuit_state[msg.breaker_number] == 0:
49  self.pb.circuit_state[msg.breaker_number] = 1
50  if msg.command == "start":
51  if self.pb.circuit_state[msg.breaker_number] != 0:
52  self.pb.circuit_state[msg.breaker_number] = 3
53  self.pb.circuit_voltage[msg.breaker_number] = 70
54 
55  def run(self):
56  while 1:
57  self.pub.publish(self.pb)
58  time.sleep(1)
59 
60 def talker(options):
61  rospy.init_node(NAME, anonymous=True)
62  pb = PowerBoard(options)
63  s = rospy.Service('power_board/control', PowerBoardCommand, pb.power_board_control)
64 
65  pb.start()
66  rospy.spin()
67 
68 
69 if __name__ == '__main__':
70  parser = OptionParser()
71  parser.add_option('-r', '--run_stop', action='store_false', default=True)
72  parser.add_option('-w', '--wireless_stop', action='store_false', default=True)
73  (options, args) = parser.parse_args()
74 
75  try:
76  talker(options)
77  except KeyboardInterrupt as e:
78  pass
79  print("exiting")
80 
fake_powerboard.PowerBoard.pub
pub
Definition: fake_powerboard.py:37
fake_powerboard.talker
def talker(options)
Definition: fake_powerboard.py:60
fake_powerboard.PowerBoard.power_board_control
def power_board_control(self, msg)
Definition: fake_powerboard.py:39
msg
fake_powerboard.PowerBoard.options
options
Definition: fake_powerboard.py:24
fake_powerboard.PowerBoard
Definition: fake_powerboard.py:19
fake_powerboard.PowerBoard.run
def run(self)
Definition: fake_powerboard.py:55
fake_powerboard.PowerBoard.__init__
def __init__(self, options)
Definition: fake_powerboard.py:20
srv
fake_powerboard.PowerBoard.pb
pb
Definition: fake_powerboard.py:26


pr2_power_board
Author(s): Curt Meyers, Blaise Gassend
autogenerated on Tue Mar 7 2023 03:19:35