From 3968b35ac5c0ad162516f0f58d87b47199ce1192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=C3=A1rio=20Lago?= <58235456+joaomariolago@users.noreply.github.com> Date: Wed, 9 Apr 2025 19:14:06 -0300 Subject: [PATCH] boards: bluerobotics: Add navigator board support (#24018) --- .vscode/cmake-variants.yaml | 5 + Tools/docker_run.sh | 4 +- boards/bluerobotics/navigator/CMakeLists.txt | 34 ++++ .../bluerobotics/navigator/cmake/upload.cmake | 53 ++++++ .../bluerobotics/navigator/default.px4board | 78 +++++++++ .../navigator/init/rc.board_defaults | 13 ++ .../navigator/init/rc.board_extras | 7 + .../navigator/init/rc.board_sensors | 39 +++++ .../navigator/neopixel/CMakeLists.txt | 36 ++++ .../navigator/neopixel/srgbled_impl.cpp | 157 ++++++++++++++++++ .../bluerobotics/navigator/src/CMakeLists.txt | 37 +++++ .../bluerobotics/navigator/src/board_config.h | 66 ++++++++ boards/bluerobotics/navigator/src/i2c.cpp | 40 +++++ boards/bluerobotics/navigator/src/spi.cpp | 45 +++++ posix-configs/rpi/navigator/sub.config | 49 ++++++ 15 files changed, 661 insertions(+), 2 deletions(-) create mode 100644 boards/bluerobotics/navigator/CMakeLists.txt create mode 100644 boards/bluerobotics/navigator/cmake/upload.cmake create mode 100644 boards/bluerobotics/navigator/default.px4board create mode 100644 boards/bluerobotics/navigator/init/rc.board_defaults create mode 100644 boards/bluerobotics/navigator/init/rc.board_extras create mode 100644 boards/bluerobotics/navigator/init/rc.board_sensors create mode 100644 boards/bluerobotics/navigator/neopixel/CMakeLists.txt create mode 100644 boards/bluerobotics/navigator/neopixel/srgbled_impl.cpp create mode 100644 boards/bluerobotics/navigator/src/CMakeLists.txt create mode 100644 boards/bluerobotics/navigator/src/board_config.h create mode 100644 boards/bluerobotics/navigator/src/i2c.cpp create mode 100644 boards/bluerobotics/navigator/src/spi.cpp create mode 100644 posix-configs/rpi/navigator/sub.config diff --git a/.vscode/cmake-variants.yaml b/.vscode/cmake-variants.yaml index 03968a6e06..5e37372b96 100644 --- a/.vscode/cmake-variants.yaml +++ b/.vscode/cmake-variants.yaml @@ -231,6 +231,11 @@ CONFIG: buildType: MinSizeRel settings: CONFIG: bitcraze_crazyflie_default + bluerobotics_navigator_default: + short: bluerobotics_navigator + buildType: MinSizeRel + settings: + CONFIG: bluerobotics_navigator_default cuav_can-gps-v1_default: short: cuav_can-gps-v1_default buildType: MinSizeRel diff --git a/Tools/docker_run.sh b/Tools/docker_run.sh index 46888cd066..c7ab8fce32 100755 --- a/Tools/docker_run.sh +++ b/Tools/docker_run.sh @@ -5,8 +5,8 @@ if [ -z ${PX4_DOCKER_REPO+x} ]; then if [[ $@ =~ .*px4_fmu.* ]]; then # nuttx-px4fmu-v{1,2,3,4,5} PX4_DOCKER_REPO="px4io/px4-dev-nuttx-focal:2022-08-12" - elif [[ $@ =~ .*navio2.* ]] || [[ $@ =~ .*raspberry.* ]] || [[ $@ =~ .*beaglebone.* ]] || [[ $@ =~ .*pilotpi.default ]]; then - # beaglebone_blue_default, emlid_navio2_default, px4_raspberrypi_default, scumaker_pilotpi_default + elif [[ $@ =~ .*navio2.* ]] || [[ $@ =~ .*raspberry.* ]] || [[ $@ =~ .*beaglebone.* ]] || [[ $@ =~ .*pilotpi.default ]] || [[ $@ =~ .*navigator.* ]]; then + # beaglebone_blue_default, emlid_navio2_default, px4_raspberrypi_default, scumaker_pilotpi_default, bluerobotics_navigator_default PX4_DOCKER_REPO="px4io/px4-dev-armhf:2023-06-26" elif [[ $@ =~ .*pilotpi.arm64 ]]; then # scumaker_pilotpi_arm64 diff --git a/boards/bluerobotics/navigator/CMakeLists.txt b/boards/bluerobotics/navigator/CMakeLists.txt new file mode 100644 index 0000000000..fa87dc20bb --- /dev/null +++ b/boards/bluerobotics/navigator/CMakeLists.txt @@ -0,0 +1,34 @@ +############################################################################ +# +# Copyright (c) 2024 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +add_subdirectory(neopixel) diff --git a/boards/bluerobotics/navigator/cmake/upload.cmake b/boards/bluerobotics/navigator/cmake/upload.cmake new file mode 100644 index 0000000000..d4aa3b75be --- /dev/null +++ b/boards/bluerobotics/navigator/cmake/upload.cmake @@ -0,0 +1,53 @@ +############################################################################ +# +# Copyright (c) 2020 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +if(DEFINED ENV{AUTOPILOT_HOST}) + set(AUTOPILOT_HOST $ENV{AUTOPILOT_HOST}) +else() + set(AUTOPILOT_HOST "raspberrypi") +endif() + +if(DEFINED ENV{AUTOPILOT_USER}) + set(AUTOPILOT_USER $ENV{AUTOPILOT_USER}) +else() + set(AUTOPILOT_USER "pi") +endif() + +add_custom_target(upload + COMMAND rsync -arh --progress + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${PX4_SOURCE_DIR}/posix-configs/rpi/navigator/*.config ${PX4_BINARY_DIR}/etc # source + "${AUTOPILOT_USER}@${AUTOPILOT_HOST}:/home/${AUTOPILOT_USER}/px4" # destination + DEPENDS px4 + COMMENT "uploading px4" + USES_TERMINAL +) diff --git a/boards/bluerobotics/navigator/default.px4board b/boards/bluerobotics/navigator/default.px4board new file mode 100644 index 0000000000..49ff0a2aba --- /dev/null +++ b/boards/bluerobotics/navigator/default.px4board @@ -0,0 +1,78 @@ +CONFIG_PLATFORM_POSIX=y +CONFIG_BOARD_LINUX_TARGET=y +CONFIG_BOARD_TESTING=y +CONFIG_BOARD_TOOLCHAIN="arm-linux-gnueabihf" +CONFIG_BOARD_ARCHITECTURE="cortex-a53" +CONFIG_DRIVERS_ADC_ADS1115=y +CONFIG_DRIVERS_BATT_SMBUS=y +CONFIG_DRIVERS_CAMERA_TRIGGER=y +CONFIG_DRIVERS_LIGHTS_NEOPIXEL=y +CONFIG_DRIVERS_IMU_INVENSENSE_ICM20602=y +CONFIG_DRIVERS_BAROMETER_BMP280=y +CONFIG_DRIVERS_GPS=y +CONFIG_DRIVERS_MAGNETOMETER_MEMSIC_MMC5983MA=y +CONFIG_DRIVERS_MAGNETOMETER_AKM_AK09916=y +CONFIG_DRIVERS_PCA9685_PWM_OUT=y +CONFIG_PCA9685_USE_EXTERNAL_CRYSTAL=y +CONFIG_DRIVERS_RC_INPUT=y +CONFIG_DRIVERS_SMART_BATTERY_BATMON=y +CONFIG_COMMON_RC=y +CONFIG_COMMON_DIFFERENTIAL_PRESSURE=y +CONFIG_COMMON_DISTANCE_SENSOR=y +CONFIG_MODULES_AIRSPEED_SELECTOR=y +CONFIG_MODULES_ATTITUDE_ESTIMATOR_Q=y +CONFIG_MODULES_BATTERY_STATUS=y +CONFIG_MODULES_CAMERA_FEEDBACK=y +CONFIG_MODULES_COMMANDER=y +CONFIG_MODULES_CONTROL_ALLOCATOR=y +CONFIG_MODULES_DATAMAN=y +CONFIG_MODULES_EKF2=y +CONFIG_MODULES_EVENTS=y +CONFIG_MODULES_FLIGHT_MODE_MANAGER=y +CONFIG_MODULES_GIMBAL=y +CONFIG_MODULES_GYRO_CALIBRATION=y +CONFIG_MODULES_GYRO_FFT=y +CONFIG_MODULES_LAND_DETECTOR=y +CONFIG_MODULES_LANDING_TARGET_ESTIMATOR=y +CONFIG_MODULES_LOAD_MON=y +CONFIG_MODULES_LOCAL_POSITION_ESTIMATOR=y +CONFIG_MODULES_LOGGER=y +CONFIG_MODULES_MAG_BIAS_ESTIMATOR=y +CONFIG_MODULES_MAVLINK=y +CONFIG_MODULES_MC_HOVER_THRUST_ESTIMATOR=y +CONFIG_MODULES_NAVIGATOR=y +CONFIG_MODULES_RC_UPDATE=y +CONFIG_MODULES_SENSORS=y +CONFIG_MODULES_SIMULATION_SIMULATOR_SIH=y +CONFIG_MODULES_TEMPERATURE_COMPENSATION=y +CONFIG_MODULES_UUV_ATT_CONTROL=y +CONFIG_MODULES_UUV_POS_CONTROL=y +CONFIG_MODULES_FW_ATT_CONTROL=y +CONFIG_MODULES_FW_AUTOTUNE_ATTITUDE_CONTROL=y +CONFIG_MODULES_FW_POS_CONTROL=y +CONFIG_MODULES_FW_RATE_CONTROL=y +CONFIG_MODULES_MANUAL_CONTROL=y +CONFIG_MODULES_MC_ATT_CONTROL=y +CONFIG_MODULES_MC_AUTOTUNE_ATTITUDE_CONTROL=y +CONFIG_MODULES_MC_POS_CONTROL=y +CONFIG_MODULES_MC_RATE_CONTROL=y +CONFIG_MODULES_ROVER_POS_CONTROL=y +CONFIG_MODULES_VTOL_ATT_CONTROL=y +CONFIG_SYSTEMCMDS_BSONDUMP=y +CONFIG_SYSTEMCMDS_DYN=y +CONFIG_SYSTEMCMDS_LED_CONTROL=y +CONFIG_SYSTEMCMDS_PARAM=y +CONFIG_SYSTEMCMDS_PERF=y +CONFIG_SYSTEMCMDS_SD_BENCH=y +CONFIG_SYSTEMCMDS_SHUTDOWN=y +CONFIG_SYSTEMCMDS_TOPIC_LISTENER=y +CONFIG_SYSTEMCMDS_TUNE_CONTROL=y +CONFIG_SYSTEMCMDS_UORB=y +CONFIG_SYSTEMCMDS_VER=y +CONFIG_SYSTEMCMDS_WORK_QUEUE=y +CONFIG_EXAMPLES_DYN_HELLO=y +CONFIG_EXAMPLES_FAKE_GPS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_PX4_MAVLINK_DEBUG=y +CONFIG_EXAMPLES_PX4_SIMPLE_APP=y +CONFIG_EXAMPLES_WORK_ITEM=y diff --git a/boards/bluerobotics/navigator/init/rc.board_defaults b/boards/bluerobotics/navigator/init/rc.board_defaults new file mode 100644 index 0000000000..18dc930ba7 --- /dev/null +++ b/boards/bluerobotics/navigator/init/rc.board_defaults @@ -0,0 +1,13 @@ +#!/bin/sh +# +# board specific defaults +#------------------------------------------------------------------------------ + +# system_power not implemented +param set CBRK_SUPPLY_CHK 894281 + +# 1K + 4.7K +param set BAT1_V_DIV 5.7 + +# Always keep current config +param set SYS_AUTOCONFIG 0 diff --git a/boards/bluerobotics/navigator/init/rc.board_extras b/boards/bluerobotics/navigator/init/rc.board_extras new file mode 100644 index 0000000000..4b33eed7c2 --- /dev/null +++ b/boards/bluerobotics/navigator/init/rc.board_extras @@ -0,0 +1,7 @@ +#!/bin/sh +# +# board specific extras init +#------------------------------------------------------------------------------ + +rc_input start -d /dev/ttyAMA1 +rc_update start diff --git a/boards/bluerobotics/navigator/init/rc.board_sensors b/boards/bluerobotics/navigator/init/rc.board_sensors new file mode 100644 index 0000000000..411995664b --- /dev/null +++ b/boards/bluerobotics/navigator/init/rc.board_sensors @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Navigator specific board sensors init +#------------------------------------------------------------------------------ + +if ! mmc5983ma start -s -m 0 -R 4 +then + echo "mmc5983ma not found." +fi + +if ! ak09916 start -I -R 6 +then + echo "AK09916 not found." +fi + +if ! icm20602 start -s -m 0 -R 14 +then + echo "ICM20602 not found." +fi + +if ! bmp280 start -I +then + echo "bmp280 not found." +fi + +if ! ads1115 start -I +then + echo "ads1115 not found." +fi + +if ! pca9685_pwm_out start -a 0x40 -b 4 +then + echo "pca9685_pwm_out not found." +fi + +if ! neopixel start +then + echo "neopixel not found." +fi diff --git a/boards/bluerobotics/navigator/neopixel/CMakeLists.txt b/boards/bluerobotics/navigator/neopixel/CMakeLists.txt new file mode 100644 index 0000000000..c75e22965a --- /dev/null +++ b/boards/bluerobotics/navigator/neopixel/CMakeLists.txt @@ -0,0 +1,36 @@ +############################################################################ +# +# Copyright (c) 2024 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +px4_add_library(arch_srgbled_dma + srgbled_impl.cpp +) diff --git a/boards/bluerobotics/navigator/neopixel/srgbled_impl.cpp b/boards/bluerobotics/navigator/neopixel/srgbled_impl.cpp new file mode 100644 index 0000000000..ada3841d88 --- /dev/null +++ b/boards/bluerobotics/navigator/neopixel/srgbled_impl.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** + * + * Copyright (c) 2024 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file srgbled_impl.cpp + * + * Implementation of functions to control NeoPixel LEDs on the BlueRobotics Navigator for the neopixel driver. + * + * Definitions: + * - BOARD_HAS_N_S_RGB_LED: Number of NeoPixel LEDs on the Navigator. + * - BOARD_RGB_SPI_BUS: SPI bus connected to the NeoPixel data line. + * - BOARD_RGB_SPI_FREQ: SPI bus frequency for the NeoPixel connection. + */ + +#include +#include +#include +#include +#include +#include + +#if defined(BOARD_HAS_N_S_RGB_LED) + +#if !defined(BOARD_RGB_SPI_BUS) +# error BOARD_RGB_SPI_BUS must be defined to use the NeoPixel driver implementation for the BlueRobotics Navigator +#endif +#if !defined(BOARD_RGB_SPI_FREQ) +# error BOARD_RGB_SPI_FREQ must be defined to use the NeoPixel driver implementation for the BlueRobotics Navigator +#endif + +#define LED_T0 0b11000000 +#define LED_T1 0b11110000 + +class NavigatorLED : public device::SPI +{ +public: + NavigatorLED(); + ~NavigatorLED() override = default; + + int init(); + int write(uint8_t red, uint8_t green, uint8_t blue); + int deinit(); + +protected: + void _setup_data(uint8_t red, uint8_t green, uint8_t blue); + +private: + uint8_t _data[24]; + px4_sem_t _sem; +}; + +NavigatorLED::NavigatorLED() : + // By default we don't use the CS line and MODE must be 0 for compatibility with Raspberry Pi + SPI(DRV_DEVTYPE_UNUSED, "navigator-neopixel", BOARD_RGB_SPI_BUS, 0, SPIDEV_MODE0, BOARD_RGB_SPI_FREQ) +{ + px4_sem_init(&_sem, 0, 1); +} + +int NavigatorLED::init() +{ + int ret = SPI::init(); + + if (ret != PX4_OK) { + PX4_ERR("Neopixel SPI init failed"); + return ret; + } + + return PX4_OK; +} + +void NavigatorLED::_setup_data(uint8_t red, uint8_t green, uint8_t blue) +{ + for (uint8_t i = 0; i < 8; i++) { + _data[i] = (green & (1 << (7 - i))) ? LED_T1 : LED_T0; + } + + for (uint8_t i = 0; i < 8; i++) { + _data[8 + i] = (red & (1 << (7 - i))) ? LED_T1 : LED_T0; + } + + for (uint8_t i = 0; i < 8; i++) { + _data[16 + i] = (blue & (1 << (7 - i))) ? LED_T1 : LED_T0; + } +} + +int NavigatorLED::write(uint8_t red, uint8_t green, uint8_t blue) +{ + _setup_data(red, green, blue); + + px4_sem_wait(&_sem); + + int ret = transfer(_data, nullptr, sizeof(_data)); + + px4_sem_post(&_sem); + + if (ret != PX4_OK) { + PX4_ERR("Failed to write data to NeoPixel %d", ret); + } + + return ret; +} + +int NavigatorLED::deinit() +{ + PX4_INFO("Neopixel deinitialized"); + return PX4_OK; +} + +// Neopixel driver impl + +NavigatorLED navigator_led; + +int neopixel_init(neopixel::NeoLEDData *led_data, int number_of_packages) +{ + return navigator_led.init(); +} + +int neopixel_write(neopixel::NeoLEDData *led_data, int number_of_packages) +{ + return navigator_led.write(led_data->R(), led_data->G(), led_data->B()); +} + +int neopixel_deinit() +{ + return navigator_led.deinit(); +} +#endif // defined(BOARD_HAS_N_S_RGB_LED) diff --git a/boards/bluerobotics/navigator/src/CMakeLists.txt b/boards/bluerobotics/navigator/src/CMakeLists.txt new file mode 100644 index 0000000000..5778212f66 --- /dev/null +++ b/boards/bluerobotics/navigator/src/CMakeLists.txt @@ -0,0 +1,37 @@ +############################################################################ +# +# Copyright (c) 2024 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +add_library(drivers_board + i2c.cpp + spi.cpp +) diff --git a/boards/bluerobotics/navigator/src/board_config.h b/boards/bluerobotics/navigator/src/board_config.h new file mode 100644 index 0000000000..4b34a5ad28 --- /dev/null +++ b/boards/bluerobotics/navigator/src/board_config.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * + * Copyright (C) 2024 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file board_config.h + * + * BlueRobotics Navigator board configuration. + */ + +#pragma once + +#define BOARD_OVERRIDE_UUID "BRNAVID000000000" // must be of length 16 +#define PX4_SOC_ARCH_ID PX4_SOC_ARCH_ID_RPI + +#define BOARD_MAX_LEDS 1 + +// Neopixel config +#define BOARD_HAS_N_S_RGB_LED 1 +#define BOARD_RGB_SPI_BUS 0 +#define BOARD_RGB_SPI_FREQ 8 * 1000 * 1000 // Emulated 800Kbps since we use 1 byte as 1 bit + +// I2C +#define CONFIG_I2C 1 +#define PX4_NUMBER_I2C_BUSES 3 + +// SPI +#define CONFIG_SPI 1 + +#define ADC_BATTERY_VOLTAGE_CHANNEL 3 +#define ADC_BATTERY_CURRENT_CHANNEL 2 +#define ADC_5V_RAIL_SENSE 0 + +#define ADC_DP_V_DIV 1.0f + +#include +#include diff --git a/boards/bluerobotics/navigator/src/i2c.cpp b/boards/bluerobotics/navigator/src/i2c.cpp new file mode 100644 index 0000000000..e4dfa3f095 --- /dev/null +++ b/boards/bluerobotics/navigator/src/i2c.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** + * + * Copyright (C) 2024 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include + +constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = { + initI2CBusInternal(1), + initI2CBusInternal(4), + initI2CBusExternal(6), +}; diff --git a/boards/bluerobotics/navigator/src/spi.cpp b/boards/bluerobotics/navigator/src/spi.cpp new file mode 100644 index 0000000000..72425ddfd1 --- /dev/null +++ b/boards/bluerobotics/navigator/src/spi.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** + * + * Copyright (C) 2024 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include +#include + +constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = { + initSPIBus(1, { + initSPIDevice(DRV_MAG_DEVTYPE_MMC5983MA, 1), + initSPIDevice(DRV_IMU_DEVTYPE_ICM20602, 2), + }), + initSPIBus(0, { + initSPIDevice(DRV_DEVTYPE_UNUSED, 0), + }), +}; diff --git a/posix-configs/rpi/navigator/sub.config b/posix-configs/rpi/navigator/sub.config new file mode 100644 index 0000000000..7eb3f9cfe0 --- /dev/null +++ b/posix-configs/rpi/navigator/sub.config @@ -0,0 +1,49 @@ +#!/bin/sh +. px4-alias.sh + +param select parameters.bson +param import + +. ./etc/init.d/rc.board_defaults + +# Submarine +set VEHICLE_TYPE uuv +param set MAV_TYPE 12 +param set SYS_AUTOSTART 60002 + +# Disable GPS check and use barometer as reference +param set EKF2_GPS_CTRL 0 +param set EKF2_GPS_CHECK 0 + +param set EKF2_BARO_CTRL 1 +param set EKF2_HGT_REF 0 + +param set EKF2_RNG_CTRL 0 +param set EKF2_OF_CTRL 0 +param set EKF2_EV_CTRL 0 + +dataman start +load_mon start +battery_status start + +. ./etc/init.d/rc.board_sensors + +. ./etc/init.d/rc.board_extras + +# Sensoring and core modules +sensors start +commander start +navigator start +ekf2 start +flight_mode_manager start +control_allocator start + +# Sub specific modules +land_detector start rover +uuv_att_control start +uuv_pos_control start + +mavlink start -x -u 14556 -r 1000000 -p +logger start -t -b 200 + +mavlink boot_complete