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): 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, 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))
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)
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)