示例#1
0
def benchmark_command_run_course_iterator():
    """Benchmark the logic for driving the car."""
    logger = DummyLogger()
    telemetry = Telemetry(logger)
    waypoint_generator = SimpleWaypointGenerator(
        SimpleWaypointGenerator.get_waypoints_from_file_name(
            'paths/solid-state-depot.kmz'
        )
    )
    driver = DummyDriver(telemetry, logger)
    command = Command(telemetry, driver, waypoint_generator, logger)

    iterations = 250
    start = time.time()
    iterator = command._run_course_iterator()
    step = None
    for step in zip(range(iterations), iterator):
        pass
    assert step is not None
    assert step[0] == iterations - 1

    end = time.time()
    print(
        '{} iterations of Command._run_course_iterator, each took {:.5}'.format(
            iterations,
            (end - start) / float(iterations)
        )
    )
示例#2
0
def main():
    """Main function."""
    logger = DummyLogger()
    box = [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]
    waypoint_generator = SimpleWaypointGenerator(
        SimpleWaypointGenerator.get_waypoints_from_file_name(
            'control/paths/solid-state-depot.kmz'))
    waypoint_generator._waypoints.clear()
    for x, y in ((x_ * .005 + 10, y_ * .005 + 10) for x_, y_ in box):
        waypoint_generator._waypoints.append((x, y))

    telemetry = DummyTelemetry(
        logger,
        waypoint_generator.get_current_waypoint(
            waypoint_generator._waypoints[0][0],
            waypoint_generator._waypoints[0][1]))
    driver = DummyDriver(telemetry, logger)

    command = Command(
        telemetry,
        driver,
        waypoint_generator,
        logger,
        sleep_time_milliseconds=1,
    )
    command.run_course()
    command.start()

    while not waypoint_generator.done():
        time.sleep(0.1)
    command.kill()
示例#3
0
def main():
    """Main function."""
    logger = DummyLogger()
    box = [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]
    waypoint_generator = SimpleWaypointGenerator(
        SimpleWaypointGenerator.get_waypoints_from_file_name(
            'control/paths/solid-state-depot.kmz'
        )
    )
    waypoint_generator._waypoints.clear()
    for x, y in ((x_ * .005 + 10, y_ * .005 + 10) for x_, y_ in box):
        waypoint_generator._waypoints.append((x, y))

    telemetry = DummyTelemetry(
        logger,
        waypoint_generator.get_current_waypoint(
            waypoint_generator._waypoints[0][0],
            waypoint_generator._waypoints[0][1]
        )
    )
    driver = DummyDriver(telemetry, logger)

    command = Command(
        telemetry,
        driver,
        waypoint_generator,
        logger,
        sleep_time_milliseconds=1,
    )
    command.run_course()
    command.start()

    while not waypoint_generator.done():
        time.sleep(0.1)
    command.kill()
示例#4
0
def benchmark_command_run_course_iterator():
    """Benchmark the logic for driving the car."""
    logger = DummyLogger()
    telemetry = Telemetry(logger)
    waypoint_generator = SimpleWaypointGenerator(
        SimpleWaypointGenerator.get_waypoints_from_file_name(
            'paths/solid-state-depot.kmz'))
    driver = DummyDriver(telemetry, logger)
    command = Command(telemetry, driver, waypoint_generator, logger)

    iterations = 250
    start = time.time()
    iterator = command._run_course_iterator()
    step = None
    for step in zip(range(iterations), iterator):
        pass
    assert step is not None
    assert step[0] == iterations - 1

    end = time.time()
    print('{} iterations of Command._run_course_iterator, each took {:.5}'.
          format(iterations, (end - start) / float(iterations)))
示例#5
0
def start_threads(
        waypoint_generator,
        logger,
        web_socket_handler,
        max_throttle,
        kml_file_name,
):
    """Runs everything."""
    logger.info('Creating Telemetry')
    telemetry = Telemetry(kml_file_name)
    telemetry_dumper = TelemetryDumper(
        telemetry,
        waypoint_generator,
        web_socket_handler
    )
    logger.info('Done creating Telemetry')
    global DRIVER
    DRIVER = Driver(telemetry)
    DRIVER.set_max_throttle(max_throttle)

    logger.info('Setting SUP800F to NMEA mode')
    serial_ = serial.Serial('/dev/ttyAMA0', 115200)
    serial_.setTimeout(1.0)
    for _ in range(10):
        serial_.readline()
    try:
        switch_to_nmea_mode(serial_)
    except:  # pylint: disable=W0702
        logger.error('Unable to set mode')
    for _ in range(10):
        serial_.readline()
    logger.info('Done')

    # The following objects must be created in order, because of message
    # exchange dependencies:
    # sup800f_telemetry: reads from command forwarded
    # command: reads from command, writes to command forwarded
    # button: writes to command
    # cherry_py_server: writes to command
    # TODO(2016-08-21) Have something better than sleeps to work around race
    # conditions
    logger.info('Creating threads')
    sup800f_telemetry = Sup800fTelemetry(serial_)
    time.sleep(0.5)
    command = Command(telemetry, DRIVER, waypoint_generator)
    time.sleep(0.5)
    button = Button()
    port = int(get_configuration('PORT', 8080))
    address = get_configuration('ADDRESS', '0.0.0.0')
    cherry_py_server = CherryPyServer(
        port,
        address,
        telemetry,
        waypoint_generator
    )
    time.sleep(0.5)

    global THREADS
    THREADS += (
        button,
        cherry_py_server,
        command,
        sup800f_telemetry,
        telemetry_dumper,
    )
    for thread in THREADS:
        thread.start()
    logger.info('Started all threads')

    # Use a fake timeout so that the main thread can still receive signals
    sup800f_telemetry.join(100000000000)
    # Once we get here, sup800f_telemetry has died and there's no point in
    # continuing because we're not receiving telemetry messages any more, so
    # stop the command module
    command.stop()
    command.join(100000000000)
    cherry_py_server.kill()
    cherry_py_server.join(100000000000)
    button.kill()
    button.join(100000000000)