Пример #1
0
    def detect_navigator() -> Optional[FlightController]:
        """Returns Navigator board if connected.
        Check for connection using the sensors on the I²C and SPI buses.

        Returns:
            Optional[FlightController]: Return FlightController if connected, None otherwise.
        """
        def is_navigator_r5_connected() -> bool:
            try:
                bus = SMBus(1)
                ADS1115_address = 0x48
                bus.read_byte_data(ADS1115_address, 0)

                AK09915_address = 0x0C
                bus.read_byte_data(AK09915_address, 0)

                BME280_address = 0x76
                bus.read_byte_data(BME280_address, 0)

                bus = SMBus(4)
                PCA9685_address = 0x40
                bus.read_byte_data(PCA9685_address, 0)
                return True
            except Exception:
                return False

        def is_navigator_r3_connected() -> bool:
            try:
                bus = SMBus(1)
                ADS1115_address = 0x48
                bus.read_byte_data(ADS1115_address, 0)

                bus = SMBus(4)
                PCA9685_address = 0x40
                bus.read_byte_data(PCA9685_address, 0)
                return True
            except Exception:
                return False

        logger.debug("Trying to detect Navigator board.")
        if is_navigator_r5_connected():
            logger.debug("Navigator R5 detected.")
            return FlightController(name="NavigatorR5",
                                    manufacturer="Blue Robotics",
                                    platform=Platform.NavigatorR5)
        if is_navigator_r3_connected():
            logger.debug("Navigator R3 detected.")
            return FlightController(name="NavigatorR3",
                                    manufacturer="Blue Robotics",
                                    platform=Platform.NavigatorR3)
        logger.debug("No Navigator board detected.")
        return None
Пример #2
0
def test_firmware_validation() -> None:
    downloader = FirmwareDownloader()
    installer = FirmwareInstaller()

    # Pixhawk1 and Pixhawk4 APJ firmwares should always work
    temporary_file = downloader.download(Vehicle.Sub, Platform.Pixhawk1)
    installer.validate_firmware(temporary_file, Platform.Pixhawk1)

    temporary_file = downloader.download(Vehicle.Sub, Platform.Pixhawk4)
    installer.validate_firmware(temporary_file, Platform.Pixhawk4)

    # New SITL firmwares should always work
    temporary_file = downloader.download(Vehicle.Sub,
                                         Platform.SITL,
                                         version="DEV")
    installer.validate_firmware(temporary_file, Platform.SITL)

    # Raise when validating Navigator firmwares (as test platform is x86)
    temporary_file = downloader.download(Vehicle.Sub, Platform.Navigator)
    with pytest.raises(InvalidFirmwareFile):
        installer.validate_firmware(temporary_file, Platform.Navigator)

    # Install SITL firmware
    temporary_file = downloader.download(Vehicle.Sub,
                                         Platform.SITL,
                                         version="DEV")
    board = FlightController(name="SITL",
                             manufacturer="ArduPilot Team",
                             platform=Platform.SITL)
    installer.install_firmware(temporary_file, board,
                               pathlib.Path(f"{temporary_file}_dest"))
Пример #3
0
    def detect_serial_flight_controllers() -> List[FlightController]:
        """Check if a Pixhawk1 or any other valid serial flight controller is connected.

        Returns:
            List[FlightController]: List with connected serial flight controller.
        """
        serial_path = "/dev/autopilot"
        for port in comports(include_links=True):
            if not port.device == serial_path:
                continue
            return [
                FlightController(
                    name=port.product or port.name,
                    manufacturer=port.manufacturer,
                    platform=Platform.Pixhawk1,
                    path=serial_path,
                )
            ]
        return []
Пример #4
0
    def detect_serial_flight_controllers() -> List[FlightController]:
        """Check if a Pixhawk1 or a Pixhawk4 is connected.

        Returns:
            List[FlightController]: List with connected serial flight controller.
        """
        sorted_serial_ports = sorted(
            comports(), key=lambda port: port.name)  # type: ignore
        unique_serial_devices: List[SysFS] = []
        for port in sorted_serial_ports:
            # usb_device_path property will be the same for two serial connections using the same USB port
            if port.usb_device_path not in [
                    device.usb_device_path for device in unique_serial_devices
            ]:
                unique_serial_devices.append(port)
        return [
            FlightController(
                name=port.product or port.name,
                manufacturer=port.manufacturer,
                platform=Detector.detect_serial_platform(port),
                path=port.device,
            ) for port in unique_serial_devices
            if Detector.detect_serial_platform(port) is not None
        ]
 def get_preferred_board(self) -> FlightController:
     preferred_board = self.configuration.get("preferred_board")
     if not preferred_board:
         raise NoPreferredBoardSet("Preferred board not set yet.")
     return FlightController(**preferred_board)
 def set_preferred_board(self, board: FlightController) -> None:
     logger.info(f"Setting {board.name} as preferred flight-controller.")
     self.configuration["preferred_board"] = board.dict(exclude={"path"})
     self.settings.save(self.configuration)
Пример #7
0
 def detect_sitl() -> FlightController:
     return FlightController(name="SITL",
                             manufacturer="ArduPilot Team",
                             platform=Platform.SITL)