Пример #1
0
def create_sensor_port_handler(interface: RevvyControl):
    port_amount = interface.get_sensor_port_amount()
    port_types = interface.get_sensor_port_types()

    handler = PortHandler("Sensor", interface, NullSensor, port_amount,
                          port_types)
    handler._set_port_type = interface.set_sensor_port_type

    return handler
Пример #2
0
def create_motor_port_handler(interface: RevvyControl, configs: dict):
    port_amount = interface.get_motor_port_amount()
    port_types = interface.get_motor_port_types()

    drivers = {'NotConfigured': NullMotor, 'DcMotor': DcMotorController}
    handler = PortHandler(interface, configs, drivers, port_amount, port_types)
    handler._set_port_type = interface.set_motor_port_type

    return handler
Пример #3
0
def create_sensor_port_handler(interface: RevvyControl, configs: dict):
    port_amount = interface.get_sensor_port_amount()
    port_types = interface.get_sensor_port_types()

    drivers = {
        'NotConfigured': NullSensor,
        'BumperSwitch': bumper_switch,
        'HC_SR04': hcsr04
    }
    handler = PortHandler(interface, configs, drivers, port_amount, port_types)
    handler._set_port_type = interface.set_sensor_port_type

    return handler
Пример #4
0
    def __init__(self, interface: RevvyControl, sound_paths, sw_version):
        self._interface = interface

        self._start_time = time.time()

        # read versions
        hw = interface.get_hardware_version()
        fw = interface.get_firmware_version()
        sw = sw_version

        print('Hardware: {}\nFirmware: {}\nFramework: {}'.format(hw, fw, sw))

        self._version = RobotVersion(hw, fw, sw)

        setup = {
            Version('1.0'): setup_sound_v1,
            Version('1.1'): setup_sound_v1,
            Version('2.0'): setup_sound_v2,
        }
        play = {
            Version('1.0'): play_sound_v1,
            Version('1.1'): play_sound_v1,
            Version('2.0'): play_sound_v2,
        }

        self._ring_led = RingLed(interface)
        self._sound = Sound(setup[hw], play[hw], sound_paths or {})

        self._status = RobotStatusIndicator(interface)
        self._status_updater = McuStatusUpdater(interface)
        self._battery = BatteryStatus(0, 0, 0)

        self._imu = IMU()

        def _motor_config_changed(motor: PortInstance, config_name):
            callback = None if config_name == 'NotConfigured' else motor.update_status
            self._status_updater.set_slot(mcu_updater_slots["motors"][motor.id], callback)

        def _sensor_config_changed(sensor: PortInstance, config_name):
            callback = None if config_name == 'NotConfigured' else sensor.update_status
            self._status_updater.set_slot(mcu_updater_slots["sensors"][sensor.id], callback)

        self._motor_ports = create_motor_port_handler(interface, Motors)
        for port in self._motor_ports:
            port.on_config_changed(_motor_config_changed)

        self._sensor_ports = create_sensor_port_handler(interface, Sensors)
        for port in self._sensor_ports:
            port.on_config_changed(_sensor_config_changed)

        self._drivetrain = DifferentialDrivetrain(interface, self._motor_ports.port_count)
Пример #5
0
    def test_revvy_command_ids(self):
        # noinspection PyTypeChecker
        control = RevvyControl(None)

        self.assertEqual(0, control.ping.command_id)

        self.assertEqual(0x04, control.set_master_status.command_id)
        self.assertEqual(0x06, control.read_operation_mode.command_id)
        self.assertEqual(0x05,
                         control.set_bluetooth_connection_status.command_id)
        self.assertEqual(0x01, control.get_hardware_version.command_id)
        self.assertEqual(0x02, control.get_firmware_version.command_id)
        self.assertEqual(0x0B, control.reboot_bootloader.command_id)

        self.assertEqual(0x10, control.get_motor_port_amount.command_id)
        self.assertEqual(0x11, control.get_motor_port_types.command_id)
        self.assertEqual(0x12, control.set_motor_port_type.command_id)
        self.assertEqual(0x13, control.set_motor_port_config.command_id)
        self.assertEqual(0x14, control.set_motor_port_control_value.command_id)

        self.assertEqual(0x20, control.get_sensor_port_amount.command_id)
        self.assertEqual(0x21, control.get_sensor_port_types.command_id)
        self.assertEqual(0x22, control.set_sensor_port_type.command_id)
        self.assertEqual(0x23, control.write_sensor_port.command_id)
        self.assertEqual(0x24, control.read_sensor_info.command_id)

        self.assertEqual(0x30, control.ring_led_get_scenario_types.command_id)
        self.assertEqual(0x32, control.ring_led_get_led_amount.command_id)
        self.assertEqual(0x31, control.ring_led_set_scenario.command_id)
        self.assertEqual(0x33, control.ring_led_set_user_frame.command_id)

        self.assertEqual(0x3A, control.status_updater_reset.command_id)
        self.assertEqual(0x3B, control.status_updater_control.command_id)
        self.assertEqual(0x3C, control.status_updater_read.command_id)
Пример #6
0
    def __init__(self, active_ports):
        '''
        Instantiates the Revvy motor controller and configures the list
        of motor ports for the Revolution Robotics DC Motor.

        :active_ports: a list of ports on the
            revvy bot that actually have motors plugged into them, 
            ex: ['M1','M4'].
        '''

        # Remove duplicates
        active_ports = set(active_ports)

        # instantiate MCU controller and motor handler
        self.hw_controller = RevvyControl(
            RevvyTransport(RevvyTransportI2CDevice(0x2D, SMBus(1))))
        self.motor_handler = create_motor_port_handler(self.hw_controller)

        self.ports = {}

        # configure active ports for Revvy DC motpr
        for p in active_ports:
            if p in MOTOR_PORTS:
                port = self.motor_handler._ports[int(p.lstrip('M'))]
                port.configure(Motors.RevvyMotor)
                self.ports[p] = DcMotorController(port,
                                                  Motors.RevvyMotor['config'])
            else:
                raise ValueError(f'Invalid motor port {p}')
Пример #7
0
    def test_revvy_command_instances(self):
        # noinspection PyTypeChecker
        control = RevvyControl(None)

        self.assertIs(PingCommand, type(control.ping))

        self.assertIs(SetMasterStatusCommand, type(control.set_master_status))
        self.assertIs(ReadOperationModeCommand,
                      type(control.read_operation_mode))
        self.assertIs(SetBluetoothStatusCommand,
                      type(control.set_bluetooth_connection_status))
        self.assertIs(ReadHardwareVersionCommand,
                      type(control.get_hardware_version))
        self.assertIs(ReadFirmwareVersionCommand,
                      type(control.get_firmware_version))
        self.assertIs(RebootToBootloaderCommand,
                      type(control.reboot_bootloader))

        self.assertIs(ReadMotorPortAmountCommand,
                      type(control.get_motor_port_amount))
        self.assertIs(ReadMotorPortTypesCommand,
                      type(control.get_motor_port_types))
        self.assertIs(SetMotorPortTypeCommand,
                      type(control.set_motor_port_type))
        self.assertIs(SetMotorPortConfigCommand,
                      type(control.set_motor_port_config))
        self.assertIs(SetMotorPortControlCommand,
                      type(control.set_motor_port_control_value))

        self.assertIs(ReadSensorPortAmountCommand,
                      type(control.get_sensor_port_amount))
        self.assertIs(ReadSensorPortTypesCommand,
                      type(control.get_sensor_port_types))
        self.assertIs(SetSensorPortTypeCommand,
                      type(control.set_sensor_port_type))
        self.assertIs(WriteSensorPortCommand, type(control.write_sensor_port))
        self.assertIs(ReadSensorPortInfoCommand,
                      type(control.read_sensor_info))

        self.assertIs(ReadRingLedScenarioTypesCommand,
                      type(control.ring_led_get_scenario_types))
        self.assertIs(GetRingLedAmountCommand,
                      type(control.ring_led_get_led_amount))
        self.assertIs(SetRingLedScenarioCommand,
                      type(control.ring_led_set_scenario))
        self.assertIs(SendRingLedUserFrameCommand,
                      type(control.ring_led_set_user_frame))

        self.assertIs(McuStatusUpdater_ResetCommand,
                      type(control.status_updater_reset))
        self.assertIs(McuStatusUpdater_ControlCommand,
                      type(control.status_updater_control))
        self.assertIs(McuStatusUpdater_ReadCommand,
                      type(control.status_updater_read))
Пример #8
0
    parser = argparse.ArgumentParser()
    parser.add_argument('--inject-test-error',
                        help='Record an error',
                        action='store_true')
    parser.add_argument('--clear',
                        help='Clear the error memory',
                        action='store_true')
    parser.add_argument(
        '--only-current',
        help='Only display errors that were recorded with the current firmware',
        action='store_true')

    args = parser.parse_args()

    with RevvyTransportI2C() as transport:
        robot_control = RevvyControl(transport.bind(0x2D))

        current_hw_version = robot_control.get_hardware_version()
        current_fw_version = robot_control.get_firmware_version()
        print('Current version numbers: HW: {} FW: {}'.format(
            current_fw_version, current_fw_version))

        if args.inject_test_error:
            print('Recording a test error')
            robot_control.error_memory_test()

        # read errors
        error_count = robot_control.error_memory_read_count()
        if error_count == 0:
            print('There are no errors stored')
        elif error_count == 1:
Пример #9
0
 def create_application_control(self) -> RevvyControl:
     return RevvyControl(self._bind(self.ROBOT_I2C_ADDRESS))
Пример #10
0
 def __init__(self, interface: RevvyControl):
     self._log = get_logger('McuErrorReader')
     self._interface = interface
     self._count = interface.error_memory_read_count()
     self._log(f'Stored errors: {self._count}')
Пример #11
0
    if args.s1:
        pattern += "\t{1}"
    if args.s2:
        pattern += "\t{2}"
    if args.s3:
        pattern += "\t{3}"
    if args.s4:
        pattern += "\t{4}"
    if args.imu_angle:
        pattern += "\t{5}"

    sensor_data_changed = False
    sensor_data = [0, None, None, None, None, None]

    with RevvyTransportI2C() as transport:
        robot_control = RevvyControl(transport.bind(0x2D))
        manifest = read_json('manifest.json')
        robot = Robot(robot_control, None, manifest['version'])

        def update():
            global sensor_data_changed
            sensor_data_changed = False
            robot.update_status()

            if args.imu_angle:
                angle = robot.imu.yaw_angle
                if angle != sensor_data[5]:
                    sensor_data[5] = angle
                    sensor_data_changed = True

            if sensor_data_changed: