def __init__(self): # Storing the engines of this car self.__leftengine = Engine('A') self.__rightengine = Engine('B') self.__leftled = Light.Light('D') self.__rightled = Light.Light('C') self.__distance_sensor = DistanceSensor(17, 4) # Storing the distance between the centers of the cars # TODO measure width and gearratio self.__widthcar = 20. self.__gearratio = 1. / 3. # Storing the perimeter of the wheels (2*pi*r) self.__perimeter = 2 * math.pi * 2.579 print 'initing Controller' ControllerCommands.init(self.__leftengine, self.__rightengine, self.__distance_sensor, self.__perimeter, self.__gearratio, self.__widthcar, self.__leftled, self.__rightled) print 'Controller inited' # Storing a reference to a brickpi thread self.__io = IO_Thread([self.__leftengine, self.__rightengine], [self.__distance_sensor], [self.__leftled, self.__rightled]) self.__command_going = False self.__command_thread = None self.__parcours = None
def __init__(self): # Storing the engines of this car self.__leftengine = Engine("A") self.__rightengine = Engine("B") self.__engines = [self.__leftengine, self.__rightengine] # Storing the distance between the centers of the cars self.__widthcar = 2.6 + 11.1 - 0.2 self.__gearratio = 1.0 # Storing the perimeter of the wheels (2*pi*r) self.__perimeter = 2 * math.pi * 2.579 ControllerCommands.init( self.__leftengine, self.__rightengine, self.__perimeter, self.__gearratio, self.__widthcar ) # Storing a reference to a brickpi thread self.__brickpi = BrickPi_Thread(self.__engines) self.__command_going = False self.__command_thread = None self.__parcours = None
def __init__(self): # Storing the engines of this car self.__leftengine = Engine('A') self.__rightengine = Engine('B') self.__engines = [self.__leftengine, self.__rightengine] # Storing the distance between the centers of the cars self.__widthcar = 2.6 + 11.1 - .2 self.__gearratio = 1. # Storing the perimeter of the wheels (2*pi*r) self.__perimeter = 2 * math.pi * 2.579 ControllerCommands.init(self.__leftengine, self.__rightengine, self.__perimeter, self.__gearratio, self.__widthcar) # Storing a reference to a brickpi thread self.__brickpi = BrickPi_Thread(self.__engines) self.__command_going = False self.__command_thread = None self.__parcours = None
def __init__(self): # Storing the engines of this car self.__leftengine = Engine('A') self.__rightengine = Engine('B') self.__distance_sensor = DistanceSensor(17,4) # Storing the distance between the centers of the cars # TODO measure width and gearratio self.__widthcar = 20. self.__gearratio = 1./3. # Storing the perimeter of the wheels (2*pi*r) self.__perimeter = 2*math.pi* 2.579 print 'initing Controller' ControllerCommands.init(self.__leftengine,self.__rightengine,self.__distance_sensor,self.__perimeter,self.__gearratio,self.__widthcar) print 'Controller inited' # Storing a reference to a brickpi thread self.__io = IO_Thread([self.__leftengine,self.__rightengine],[self.__distance_sensor]) self.__command_going = False self.__command_thread = None self.__parcours = None
else: return True else: return False if __name__ == "__main__": while True: # check if any new data is available conn, message = socket.get_data() # Check if the current lock has expired lock.check_expire() print "Received request: ", message # Check if the incomming message is valid if message.get("command", None) == "INITSOCKET": ControllerCommands.init_socket(message["adress"], message["port"]) return_message = "OK" else: messageOK = check_message(message) return_message = "SORRY" if messageOK: command = str(message["command"]) identifier = message["ID"] argument = message.get("arguments", []) opt_arguments = commands[command].get("optional_arguments", None) if opt_arguments != None: argument = opt_arguments + argument f = commands[command]["function"] return_message = f(identifier, argument, lock) else:
return False if __name__ == '__main__': while True: # check if any new data is available conn, message = socket.get_data() # Check if the current lock has expired lock.check_expire() print "Received request: ", message # Check if the incomming message is valid if DEBUG: return_message = 'OK' else: if message.get('command', None) == 'INITSOCKET': ControllerCommands.init_socket(message["adress"], message["port"]) return_message = 'OK' else: messageOK = check_message(message) return_message = 'SORRY' if (messageOK): command = str(message['command']) identifier = message['ID'] argument = message.get('arguments', []) opt_arguments = commands[command].get( 'optional_arguments', None) if opt_arguments != None: argument = opt_arguments + argument f = commands[command]['function'] return_message = f(identifier, argument, lock)