From e339297388ea5701f2eb54d96527db64dbd91bf3 Mon Sep 17 00:00:00 2001 From: alexklimaj Date: Fri, 30 Sep 2022 21:41:17 -0600 Subject: [PATCH] Basic gps base station app --- boards/px4/sitl/gps_base.px4board | 1 + src/modules/gps_base_station/CMakeLists.txt | 44 +++++++ .../gps_base_station/GPSBaseStation.cpp | 121 ++++++++++++++++++ .../gps_base_station/GPSBaseStation.hpp | 76 +++++++++++ src/modules/gps_base_station/Kconfig | 5 + src/modules/gps_base_station/parameters.c | 41 ++++++ 6 files changed, 288 insertions(+) create mode 100644 src/modules/gps_base_station/CMakeLists.txt create mode 100644 src/modules/gps_base_station/GPSBaseStation.cpp create mode 100644 src/modules/gps_base_station/GPSBaseStation.hpp create mode 100644 src/modules/gps_base_station/Kconfig create mode 100644 src/modules/gps_base_station/parameters.c diff --git a/boards/px4/sitl/gps_base.px4board b/boards/px4/sitl/gps_base.px4board index bfda686d24..4a0c4709a3 100644 --- a/boards/px4/sitl/gps_base.px4board +++ b/boards/px4/sitl/gps_base.px4board @@ -4,6 +4,7 @@ CONFIG_BOARD_ETHERNET=y CONFIG_DRIVERS_GPS=y CONFIG_MODULES_DATAMAN=y CONFIG_MODULES_EVENTS=y +CONFIG_MODULES_GPS_BASE_STATION=y CONFIG_MODULES_LOAD_MON=y CONFIG_MODULES_LOGGER=y CONFIG_MODULES_MAVLINK=y diff --git a/src/modules/gps_base_station/CMakeLists.txt b/src/modules/gps_base_station/CMakeLists.txt new file mode 100644 index 0000000000..f0429a2eed --- /dev/null +++ b/src/modules/gps_base_station/CMakeLists.txt @@ -0,0 +1,44 @@ +############################################################################ +# +# Copyright (c) 2021-2022 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_module( + MODULE modules__gps_base_station + MAIN gps_base_station + COMPILE_FLAGS + #-DDEBUG_BUILD + SRCS + GPSBaseStation.cpp + GPSBaseStation.hpp + DEPENDS + px4_work_queue + ) diff --git a/src/modules/gps_base_station/GPSBaseStation.cpp b/src/modules/gps_base_station/GPSBaseStation.cpp new file mode 100644 index 0000000000..d4cd099057 --- /dev/null +++ b/src/modules/gps_base_station/GPSBaseStation.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** + * + * Copyright (c) 2021-2022 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 "GPSBaseStation.hpp" + +GPSBaseStation::GPSBaseStation() : + ModuleParams(nullptr), + ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default) +{ +} + +GPSBaseStation::~GPSBaseStation() +{ + perf_free(_loop_interval_perf); +} + +bool GPSBaseStation::init() +{ + ScheduleOnInterval(INTERVAL_US); + return true; +} + +void GPSBaseStation::Run() +{ + if (should_exit()) { + ScheduleClear(); + exit_and_cleanup(); + return; + } + + perf_count(_loop_interval_perf); +} + +int GPSBaseStation::task_spawn(int argc, char *argv[]) +{ + GPSBaseStation *instance = new GPSBaseStation(); + + if (instance) { + _object.store(instance); + _task_id = task_id_is_work_queue; + + if (instance->init()) { + return PX4_OK; + } + + } else { + PX4_ERR("alloc failed"); + } + + delete instance; + _object.store(nullptr); + _task_id = -1; + + return PX4_ERROR; +} + +int GPSBaseStation::print_status() +{ + perf_print_counter(_loop_interval_perf); + return 0; +} + +int GPSBaseStation::custom_command(int argc, char *argv[]) +{ + return print_usage("unknown command"); +} + +int GPSBaseStation::print_usage(const char *reason) +{ + if (reason) { + PX4_WARN("%s\n", reason); + } + + PRINT_MODULE_DESCRIPTION( + R"DESCR_STR( +### Description +Simple online gyroscope calibration. + +)DESCR_STR"); + + PRINT_MODULE_USAGE_NAME("gyro_calibration", "system"); + PRINT_MODULE_USAGE_COMMAND("start"); + PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); + + return 0; +} + +extern "C" __EXPORT int gps_base_station_main(int argc, char *argv[]) +{ + return GPSBaseStation::main(argc, argv); +} diff --git a/src/modules/gps_base_station/GPSBaseStation.hpp b/src/modules/gps_base_station/GPSBaseStation.hpp new file mode 100644 index 0000000000..96d72253d7 --- /dev/null +++ b/src/modules/gps_base_station/GPSBaseStation.hpp @@ -0,0 +1,76 @@ +/**************************************************************************** + * + * Copyright (c) 2021-2022 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. + * + ****************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace time_literals; + +class GPSBaseStation : public ModuleBase, public ModuleParams, public px4::ScheduledWorkItem +{ +public: + GPSBaseStation(); + ~GPSBaseStation() override; + + /** @see ModuleBase */ + static int task_spawn(int argc, char *argv[]); + + /** @see ModuleBase */ + static int custom_command(int argc, char *argv[]); + + /** @see ModuleBase */ + static int print_usage(const char *reason = nullptr); + + bool init(); + + int print_status() override; + +private: + static constexpr hrt_abstime INTERVAL_US = 20000_us; + + void Run() override; + + uORB::Publication _gps_inject_data_pub{ORB_ID(gps_inject_data)}; + + perf_counter_t _loop_interval_perf{perf_alloc(PC_INTERVAL, MODULE_NAME": interval")}; +}; diff --git a/src/modules/gps_base_station/Kconfig b/src/modules/gps_base_station/Kconfig new file mode 100644 index 0000000000..8f7dee4471 --- /dev/null +++ b/src/modules/gps_base_station/Kconfig @@ -0,0 +1,5 @@ +menuconfig MODULES_GPS_BASE_STATION + bool "gps_base_station" + default n + ---help--- + Enable support for gps_base_station diff --git a/src/modules/gps_base_station/parameters.c b/src/modules/gps_base_station/parameters.c new file mode 100644 index 0000000000..f6f0206192 --- /dev/null +++ b/src/modules/gps_base_station/parameters.c @@ -0,0 +1,41 @@ +/**************************************************************************** + * + * Copyright (c) 2021 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. + * + ****************************************************************************/ + +/** +* IMU gyro auto calibration enable. +* +* @unit m +* @reboot_required true +* @group GPS_Base_Station +*/ +PARAM_DEFINE_INT32(GPS_BASE_ACC_LIM, 2);