def __init__(self, node, rate, deadband): messaging.MessageObserver.__init__(self) self.__node = node node.join("control") node.join("gui") self.lastButtonValues = {} self.lastAxisValues = {} self.rate = rate self.deadband = deadband self.hasGamepad = False info("Gamepad server starting up...") node.addObserver(self) node.send(msg.SetPenultimateResortTimeoutMessage(10)) pygame.init() if pygame.joystick.get_count() == 0: error ("No gamepads detected") raise IOError() else: self.hasGamepad = True if self.hasGamepad: self.joystick = pygame.joystick.Joystick(0) self.joystick.init() info( "Initialized Joystick : %s" % self.joystick.get_name() ) for i in range(0, self.joystick.get_numbuttons()): self.lastButtonValues[i] = 0 for i in range(0, self.joystick.get_numaxes()): self.lastAxisValues[i] = 0.00
def __init__(self, node, bin, channel='Hue', no_trigger=3): messaging.BufferedMessageObserver.__init__(self) self.__node = node node.join("processing") node.addObserver(self) self.bin = bin self.channel = channel self.binMovingmean = []
def __init__(self, node): msg.MessageObserver.__init__(self) threading.Thread.__init__(self) self.__node = node node.join("control") node.addObserver(self) self.eval_queue = Queue.Queue(1000) self.daemon = True self.start()
def __init__(self, node): msg.MessageObserver.__init__(self) self.__node = node node.join("gui") self.lastTimeoutSet = 0 self.lastAliveTime = 0 node.addObserver(self)
def __init__(self, node, shelf, watch_list, auto): msg.MessageObserver.__init__(self) self.__node = node self.__shelf = shelf self.__auto = auto if auto: node.subMessage(msg.MembershipChangedMessage()) for message in watch_list: debug('Listening for %s messages' % message) node.subMessage(getattr(msg, message + 'Message')()) self.attachOnMessageFunc(message) node.addObserver(self)
def __init__(self, node, environment): msg.MessageObserver.__init__(self) self.node = node self.env = environment self._position_lock = threading.Lock() self._position = None self._config_lock = threading.Lock() self._config = None node.addObserver(self) node.subMessage(msg.SimPositionMessage()) node.subMessage(msg.GeminiControlMessage())
def __init__(self, node): messaging.BufferedMessageObserver.__init__(self) node.join("gui") node.join("external") node.addObserver(self) self.node = node self.motor_demand_log_lock = dict([(x, threading.Lock()) for x in motor_ids]) self.motor_demand_log = dict([(x, []) for x in motor_ids]) self.light_log_lock = dict([(x, threading.Lock()) for x in light_ids]) self.light_log = dict([(x, [(time.time(), 0)]) for x in light_ids]) self.battery_log_lock = dict([(x, threading.Lock()) for x in battery_ids]) self.battery_log = dict([(x, [(time.time(), 0)]) for x in battery_ids])
def __init__(self, node, channel='Value', no_trigger=3): messaging.BufferedMessageObserver.__init__(self) self.__node = node node.join("processing") node.addObserver(self) self.channel = channel self.no_trigger = no_trigger self.detect = 0 # A class to calculate the moving average of last maxcount number of # sample, and set trigger flag when sample is outside tolerance range: self.skewMovingMean = MovingAverage('lower', tolerance=1, maxcount=30, st_multiplier=3) self.meanMovingMean = MovingAverage('upper', tolerance=5, maxcount=30, st_multiplier=3)
def __init__(self, node, mode='simple'): messaging.MessageObserver.__init__(self) self.__node = node node.join("control") node.join("gui") node.join("telemetry") self.mode = mode # displacement estimators running in their own threads self.displacementEstimator = displacement.Displacement(mode=self.mode) self.location = NorthEastDepthCoord(0, 0, 0) self.timeLast = time.time() self.speed = XYZSpeed() self.depth = None self.control_bearing = None self.telemetry_bearing = None node.addObserver(self)
def __init__(self, node, bin, no_trigger=3, tolerance=0.15, maxcount=30, st_multiplier=3, st_on=1): messaging.BufferedMessageObserver.__init__(self) self.__node = node node.join("processing") node.addObserver(self) self.bin = bin self.no_trigger = no_trigger self.detect = 0 self.binMovingmean = [] self.lock = threading.Lock() for uni_bin in self.bin: # A class to calculate the moving average of last maxcount number of # sample, multiplier sets the tolerance range multiplier and set # trigger flag when sample is outside tolerance range: self.binMovingmean.append( MovingAverage('upper', tolerance, maxcount, st_multiplier, st_on))
if __name__ == "__main__": import sys node = cauv.node.Node('py-sonPos', sys.argv[1:]) class TestObserver(msg.MessageObserver): sonarRange = 60000 lastPos = vec(0, 0) alpha = 0.1 def onLinesMessage(self, m): if m.name == "bay lines": rawpos = positionInBay(m.lines) if rawpos != None: a = vec(self.lastPos.x * (1 - self.alpha), self.lastPos.y * (1 - self.alpha)) b = vec(rawpos.x * (self.alpha), rawpos.y * (self.alpha)) pos = a + b self.lastPos = pos realpos = vec(self.sonarRange * 2 * pos.x / 1000.0, self.sonarRange * 2 * pos.y / 1000.0) print rawpos, realpos def onSonarControlMessage(self, m): self.sonarRange = m.range node.addObserver(TestObserver()) node.join("processing") node.join("sonarctl") while True: time.sleep(1.0)
node = cauv.node.Node('py-gmpd') try: auv = control.AUV(node) auv.priority = 10 auv.timeout = 10 d = GamepadServer(node, args.rate, args.deadband) if d.hasGamepad: mapFile = ("gamepad_maps.%s" % d.gamepadName().replace(' ','')) if args.mapping: mapFile = ("gamepad_maps.%s" % args.mapping) module = __import__(mapFile, fromlist=['gamepad_maps']) info('Imported mapping module '+str(module)) if args.debug: d.mapping = GamepadMapping(auv) else: d.mapping = ConcreteGamepadMapping(auv, module.XBoxAxes, module.XBoxButtons) if args.controls: try: print d.mapping.controls() except AttributeError: print "Mapping did not provide controls listing" else: node.addObserver(d.mapping) d.run() except IOError: info("Stopping due to IO Error") finally: node.stop()