Beispiel #1
0
    def __init__(self, kml_file_name=None):
        self._data = {}
        self._logger = AsyncLogger()
        self._speed_history = collections.deque()
        self._z_acceleration_g = collections.deque()
        self._lock = threading.Lock()

        # TODO: For the competition, just hard code the compass. For now, the
        # Kalman filter should start reading in values and correct quickly.
        self._location_filter = LocationFilter(0.0, 0.0, 0.0)
        self._estimated_steering = 0.0
        self._estimated_throttle = 0.0

        self._target_steering = 0.0
        self._target_throttle = 0.0

        self._ignored_points = collections.defaultdict(lambda: 0)
        self._ignored_points_thresholds = collections.defaultdict(lambda: 10)

        consume = lambda: consume_messages(
            config.TELEMETRY_EXCHANGE,
            self._handle_message
        )
        thread = threading.Thread(target=consume)
        thread.name = '{}:consume_messages:{}'.format(
            self.__class__.__name__,
            config.TELEMETRY_EXCHANGE
        )
        thread.start()

        self._course_m = None
        try:
            if kml_file_name is not None:
                self.load_kml_from_file_name(kml_file_name)
                self._logger.info(
                    'Loaded {} course points and {} inner objects'.format(
                        len(self._course_m['course']),
                        len(self._course_m['inner'])
                    )
                )
            else:
                self._course_m = None

            if self._course_m is not None:
                if len(self._course_m['course']) == 0:
                    self._logger.warn(
                        'No course defined for {}'.format(kml_file_name)
                    )
                if len(self._course_m['inner']) == 0:
                    self._logger.warn(
                        'No inner obstacles defined for {}'.format(kml_file_name)
                    )
        except Exception as e:
            self._logger.error('Unable to load course file: {}'.format(e))
 def __init__(self, logger):
     super(AsyncLoggerReceiver, self).__init__()
     self._message_type_to_logger = {
         'debug': logger.debug,
         'info': logger.info,
         'warn': logger.warn,
         'error': logger.error,
         'critical': logger.critical,
     }
     consume = lambda: consume_messages(config.LOGS_EXCHANGE, self._callback
                                        )
     self._thread = threading.Thread(target=consume)
     self._thread.name = '{}:consume_messages'.format(
         self.__class__.__name__)
Beispiel #3
0
 def __init__(self, logger):
     super(AsyncLoggerReceiver, self).__init__()
     self._message_type_to_logger = {
         'debug': logger.debug,
         'info': logger.info,
         'warn': logger.warn,
         'error': logger.error,
         'critical': logger.critical,
     }
     consume = lambda: consume_messages(config.LOGS_EXCHANGE, self._callback)
     self._thread = threading.Thread(target=consume)
     self._thread.name = '{}:consume_messages'.format(
         self.__class__.__name__
     )
    def __init__(self, kml_file_name=None):
        self._data = {}
        self._logger = AsyncLogger()
        self._speed_history = collections.deque()
        self._z_acceleration_g = collections.deque()
        self._lock = threading.Lock()

        # TODO: For the competition, just hard code the compass. For now, the
        # Kalman filter should start reading in values and correct quickly.
        self._location_filter = LocationFilter(0.0, 0.0, 0.0)
        self._estimated_steering = 0.0
        self._estimated_throttle = 0.0

        self._target_steering = 0.0
        self._target_throttle = 0.0

        self._ignored_points = collections.defaultdict(lambda: 0)
        self._ignored_points_thresholds = collections.defaultdict(lambda: 10)

        consume = lambda: consume_messages(config.TELEMETRY_EXCHANGE, self.
                                           _handle_message)
        thread = threading.Thread(target=consume)
        thread.name = '{}:consume_messages:{}'.format(
            self.__class__.__name__, config.TELEMETRY_EXCHANGE)
        thread.start()

        self._course_m = None
        try:
            if kml_file_name is not None:
                self.load_kml_from_file_name(kml_file_name)
                self._logger.info(
                    'Loaded {} course points and {} inner objects'.format(
                        len(self._course_m['course']),
                        len(self._course_m['inner'])))
            else:
                self._course_m = None

            if self._course_m is not None:
                if len(self._course_m['course']) == 0:
                    self._logger.warn(
                        'No course defined for {}'.format(kml_file_name))
                if len(self._course_m['inner']) == 0:
                    self._logger.warn(
                        'No inner obstacles defined for {}'.format(
                            kml_file_name))
        except Exception as e:
            self._logger.error('Unable to load course file: {}'.format(e))
Beispiel #5
0
    def __init__(
            self,
            telemetry,
            driver,
            waypoint_generator,
            sleep_time_milliseconds=None,
    ):
        """Create the Command thread."""
        super(Command, self).__init__()
        self.name = self.__class__.__name__

        self._telemetry = telemetry
        if sleep_time_milliseconds is None:
            self._sleep_time_seconds = .02
        else:
            self._sleep_time_seconds = sleep_time_milliseconds / 1000.0
        self._driver = driver
        self._logger = AsyncLogger()
        self._forwarder = CommandForwardProducer()
        self._run = True
        self._run_course = False
        self._waypoint_generator = waypoint_generator

        self._sleep_time = None
        self._wake_time = None
        self._start_time = None

        self._camera = picamera.PiCamera()

        # If the car is on the starting line (not started yet)
        self._on_starting_line = True

        self._commands = queue.Queue()
        def callback(message):
            self._commands.put(message)
            # I never could figure out how to do multi consumer exchanges, and
            # I only need it for two consumers... so, just forward the message
            # on to the one place it needs to go
            self._forwarder.forward(message)

        consume = lambda: consume_messages(config.COMMAND_EXCHANGE, callback)
        self._thread = threading.Thread(target=consume)
        self._thread.name = '{}:consume_messages'.format(
            self.__class__.__name__
        )
        self._thread.start()
    def __init__(
        self,
        telemetry,
        driver,
        waypoint_generator,
        sleep_time_milliseconds=None,
    ):
        """Create the Command thread."""
        super(Command, self).__init__()
        self.name = self.__class__.__name__

        self._telemetry = telemetry
        if sleep_time_milliseconds is None:
            self._sleep_time_seconds = .02
        else:
            self._sleep_time_seconds = sleep_time_milliseconds / 1000.0
        self._driver = driver
        self._logger = AsyncLogger()
        self._forwarder = CommandForwardProducer()
        self._run = True
        self._run_course = False
        self._waypoint_generator = waypoint_generator

        self._sleep_time = None
        self._wake_time = None
        self._start_time = None

        self._camera = picamera.PiCamera()

        # If the car is on the starting line (not started yet)
        self._on_starting_line = True

        self._commands = queue.Queue()

        def callback(message):
            self._commands.put(message)
            # I never could figure out how to do multi consumer exchanges, and
            # I only need it for two consumers... so, just forward the message
            # on to the one place it needs to go
            self._forwarder.forward(message)

        consume = lambda: consume_messages(config.COMMAND_EXCHANGE, callback)
        self._thread = threading.Thread(target=consume)
        self._thread.name = '{}:consume_messages'.format(
            self.__class__.__name__)
        self._thread.start()
    def __init__(self, waypoints):
        self._logger = AsyncLogger()
        self._waypoints = copy.deepcopy(waypoints)
        self._current_waypoint_index = 0
        self._logger.info(
            'Loaded {length} waypoints'.format(
                length=len(self._waypoints)
            )
        )
        self._last_distance_m = float('inf')

        consume = lambda: consume_messages(
            config.WAYPOINT_EXCHANGE,
            self._handle_message
        )
        thread = threading.Thread(target=consume)
        thread.name = '{}:consume_messages:{}'.format(
            self.__class__.__name__,
            config.WAYPOINT_EXCHANGE
        )
        thread.start()
    def __init__(self, serial):
        """Create the TelemetryData thread."""
        super(Sup800fTelemetry, self).__init__()
        self.name = self.__class__.__name__

        self._telemetry = TelemetryProducer()
        self._serial = serial
        self._logger = AsyncLogger()
        self._run = True
        self._iterations = 0
        # These initial measurements are from a calibration observation
        self._compass_offsets = (-11.87, -5.97)
        self._magnitude_mean = 353.310
        self._magnitude_std_dev = 117.918

        self._calibrate_compass_end_time = None
        self._nmea_mode = True
        self._last_compass_heading_d = 0.0
        self._dropped_compass_messages = 0
        self._dropped_threshold = 10

        self._hdop = 5.0

        def handle_message(message):
            """Handles command messages. Only cares about calibrate compass;
            other messages are ignored.
            """
            if message == 'calibrate-compass':
                self.calibrate_compass(10)

        consume = lambda: consume_messages(
            config.COMMAND_FORWARDED_EXCHANGE,
            handle_message
        )
        thread = threading.Thread(target=consume)
        thread.name = '{}:consume_messages:{}'.format(
            self.__class__.__name__,
            config.COMMAND_FORWARDED_EXCHANGE
        )
        thread.start()
Beispiel #9
0
    def __init__(self, serial):
        """Create the TelemetryData thread."""
        super(Sup800fTelemetry, self).__init__()
        self.name = self.__class__.__name__

        self._telemetry = TelemetryProducer()
        self._serial = serial
        self._logger = AsyncLogger()
        self._run = True
        self._iterations = 0
        # These initial measurements are from a calibration observation
        self._compass_offsets = (-11.87, -5.97)
        self._magnitude_mean = 353.310
        self._magnitude_std_dev = 117.918

        self._calibrate_compass_end_time = None
        self._nmea_mode = True
        self._last_compass_heading_d = 0.0
        self._dropped_compass_messages = 0
        self._dropped_threshold = 10

        self._hdop = 5.0

        def handle_message(message):
            """Handles command messages. Only cares about calibrate compass;
            other messages are ignored.
            """
            if message == 'calibrate-compass':
                self.calibrate_compass(10)

        consume = lambda: consume_messages(config.COMMAND_FORWARDED_EXCHANGE,
                                           handle_message)
        thread = threading.Thread(target=consume)
        thread.name = '{}:consume_messages:{}'.format(
            self.__class__.__name__, config.COMMAND_FORWARDED_EXCHANGE)
        thread.start()
Beispiel #10
0
def override_imports_for_non_rpi():
    """Overrides modules that only work on the Raspberry Pi. Importing RPIO
    (used in button) on a non Raspberry Pi raises a SystemError, so for testing
    on other systems, just ignore it.
    """
    class Dummy(object):  # pylint: disable=missing-docstring,too-few-public-methods
        def __getattr__(self, attr):
            return lambda *arg, **kwarg: time.sleep(0.01)
    # pylint: disable=invalid-name
    global Button
    Button = lambda *arg: Dummy()
    serial.Serial = lambda *arg: Dummy()
    global Driver
    Driver = lambda *arg: Dummy()
    global Sup800fTelemetry
    Sup800fTelemetry = lambda *arg: Dummy()
    global switch_to_nmea_mode
    switch_to_nmea_mode = lambda *arg: Dummy()
    # Ignore messages
    drop = lambda message: None
    drop2 = lambda: consume_messages(config.COMMAND_FORWARDED_EXCHANGE, drop)
    thread = threading.Thread(target=drop2)
    thread.name = config.COMMAND_FORWARDED_EXCHANGE
    thread.start()
 def consume():
     """Function to consume messages."""
     consume_messages(self.EXCHANGE, save_message)