def Run(self): # Get and broadcast status of all USB Relays. while not rospy.is_shutdown(): relaystatus = usbRelayStatus() relaystatus.relayOn = [False] * 8 # Fill array for use. if self.relayExists: # Only poll if the relay exists. relaystatus.relayPresent = True # Gather USB Relay status for each relay and publish for i in range(1,9): relayEnabled = rospy.get_param("~relay" + str(i) + "enabled", False) if relayEnabled: # Do not touch (poll or anything) Relays that are not listed as enabled. relayLabel = rospy.get_param("~relay" + str(i) + "label", "No Label") while self._Busy: # Prevent simultaneous polling of serial port by multiple processes within this app due to ROS threading. print "BitBangDevice Busy . . ." rospy.sleep(0.1) self._Busy = True state = get_relay_state( BitBangDevice(self.relaySerialNumber).port, str(i) ) self._Busy = False if state == 0: #print "Relay " + str(i) + " state:\tOFF (" + str(state) + ")" #print str(i) + " - " + relayLabel + ": OFF" relaystatus.relayOn[i-1] = False else: #print "Relay " + str(i) + " state:\tON (" + str(state) + ")" #print str(i) + " - " + relayLabel + ": ON" relaystatus.relayOn[i-1] = True else: # If the relay does not exist just broadcast "False" to everything. relaystatus.relayPresent = False self._usbRelayStatusPublisher.publish(relaystatus) # Publish USB Relay status self.r.sleep() # Sleep long enough to maintain the rate set in __init__
def Run(self): # Get and broadcast status of all USB Relays. while not rospy.is_shutdown(): relaystatus = usbRelayStatus() relaystatus.relayOn = [False] * 8 # Fill array for use. if self.relayExists: # Only poll if the relay exists. relaystatus.relayPresent = True # Gather USB Relay status for each relay and publish for i in range(1,9): relayEnabled = rospy.get_param("~relay" + str(i) + "enabled", False) if relayEnabled: # Do not touch (poll or anything) Relays that are not listed as enabled. relayLabel = rospy.get_param("~relay" + str(i) + "label", "No Label") while self._Busy: # Prevent simultaneous polling of serial port by multiple processes within this app due to ROS threading. rospy.loginfo("BitBangDevice Busy . . .") rospy.sleep(0.2) self._Busy = True state = get_relay_state( BitBangDevice(self.relaySerialNumber).port, str(i) ) self._Busy = False if state == 0: #print "Relay " + str(i) + " state:\tOFF (" + str(state) + ")" #print str(i) + " - " + relayLabel + ": OFF" relaystatus.relayOn[i-1] = False else: #print "Relay " + str(i) + " state:\tON (" + str(state) + ")" #print str(i) + " - " + relayLabel + ": ON" relaystatus.relayOn[i-1] = True else: # If the relay does not exist just broadcast "False" to everything. relaystatus.relayPresent = False self._usbRelayStatusPublisher.publish(relaystatus) # Publish USB Relay status self.r.sleep() # Sleep long enough to maintain the rate set in __init__
def Run(self): ''' Description: main loop for the service node which performs checking on the change state of the relays and publishes a message when there is a change :return: None ''' while not rospy.is_shutdown(): relay_status = usbRelayStatus() if self._relay_exists: for key, io in self._relay_io_map.iteritems(): if not io.LastState is io.CommandedState: relay_status.Name.append(key) relay_status.States.append(io.ActualState) else: relay_status.Names = ["Unused"] * self.NUM_RELAYS relay_status.States = [False] * self.NUM_RELAYS self._usbRelayStatusPublisher.publish(relay_status) # Publish USB Relay status self.r.sleep() # Sleep long enough to maintain the rate set in __init__