From 42552668c3c8c4f4085b6392f1817c292df22d86 Mon Sep 17 00:00:00 2001 From: TheSpaceDragon Date: Wed, 12 Jul 2023 23:25:54 -0400 Subject: [PATCH] Added basic SBUS implementation - Added a function to RCControls struct to assign values from an existing object - Implemented basic SBUS input taking with SM - Updated CMAKE --- .../rc_receiver/Inc/rcreceiver_datatypes.h | 18 +++++++++++++ SystemManager/{ => Inc}/SystemManager.hpp | 12 ++++----- SystemManager/{ => Src}/SystemManager.cpp | 25 ++++++++----------- Tools/Firmware/CMakeLists.txt | 2 ++ 4 files changed, 37 insertions(+), 20 deletions(-) rename SystemManager/{ => Inc}/SystemManager.hpp (66%) rename SystemManager/{ => Src}/SystemManager.cpp (51%) diff --git a/Drivers/rc_receiver/Inc/rcreceiver_datatypes.h b/Drivers/rc_receiver/Inc/rcreceiver_datatypes.h index dcc6563c..773e7808 100644 --- a/Drivers/rc_receiver/Inc/rcreceiver_datatypes.h +++ b/Drivers/rc_receiver/Inc/rcreceiver_datatypes.h @@ -37,6 +37,24 @@ struct RCControl{ float &operator[] (int i) { return ControlSignals[i]; } + void assignValues(RCControl const &original){ + this->roll = original.roll; + this->pitch = original.pitch; + this->throttle = original.throttle; + this->yaw = original.yaw; + this->aux1 = original.aux1; + this->aux2 = original.aux2; + this->aux3 = original.aux3; + this->aux4 = original.aux4; + this->aux5 = original.aux5; + this->aux6 = original.aux6; + this->aux7 = original.aux7; + this->aux8 = original.aux8; + this->aux9 = original.aux9; + this->aux10 = original.aux10; + this->aux11 = original.aux11; + } + /* initial values*/ RCControl() { diff --git a/SystemManager/SystemManager.hpp b/SystemManager/Inc/SystemManager.hpp similarity index 66% rename from SystemManager/SystemManager.hpp rename to SystemManager/Inc/SystemManager.hpp index d4557a7e..d8cbf53b 100644 --- a/SystemManager/SystemManager.hpp +++ b/SystemManager/Inc/SystemManager.hpp @@ -5,9 +5,9 @@ #ifndef ZEROPILOT_3_5_SYSTEMMANAGER_HPP #define ZEROPILOT_3_5_SYSTEMMANAGER_HPP -#include "global_config.hpp" -#include "sbus_reciever.hpp" -#include "rcreceiver_datatypes.h" +#include "../../Models/global_config.hpp" +#include "../../Drivers/rc_receiver/Inc/sbus_receiver.hpp" +#include "../../Drivers/rc_receiver/Inc/rcreceiver_datatypes.h" class SystemManager { @@ -20,8 +20,8 @@ class SystemManager { void flyManually(); /* Getters and Setters */ - Flightmode getCurrentFlightMode(); - void setCurrentFlightMode(Flightmode flightmode); + config::Flightmode* getCurrentFlightMode(); + void setCurrentFlightMode(config::Flightmode *flightmode); private: /* Private helper functions */ void updateRCInputs(); @@ -30,7 +30,7 @@ class SystemManager { /* SBUS and AM variables to follow */ /* State-keeping variables to follow */ - Flightmode *currentFlightMode_; + config::Flightmode *currentFlightMode_; SBUSReceiver rcController_; RCControl rcInputs_; diff --git a/SystemManager/SystemManager.cpp b/SystemManager/Src/SystemManager.cpp similarity index 51% rename from SystemManager/SystemManager.cpp rename to SystemManager/Src/SystemManager.cpp index 2c78f500..2adaa5e2 100644 --- a/SystemManager/SystemManager.cpp +++ b/SystemManager/Src/SystemManager.cpp @@ -2,32 +2,29 @@ // Created by Gagan Deep Singh on 2023-07-08. // -#include "SystemManager.hpp" -#include "global_config.hpp" -#include "config.hpp" -#include "sbus_reciever.hpp" -#include "drivers_config.hpp" - +#include "../Inc/SystemManager.hpp" +#include "../../Models/testmodel1/config.hpp" +#include "../../Models/global_config.hpp" +#include "../../Drivers/rc_receiver/Inc/sbus_receiver.hpp" +#include "../../Drivers/rc_receiver/Inc/sbus_defines.h" +#include "../../Drivers/rc_receiver/Inc/rcreceiver_datatypes.h" +#include "../../Drivers/Common/Inc/drivers_config.hpp" SystemManager::SystemManager(): currentFlightMode_(config::flightmodes[0]), + rcController_(sbus_uart) {}/* Would need to instantiate SBUS, IWDG, and AM */ SystemManager::~SystemManager() {} void SystemManager::flyManually() { for(;;){ - try{ updateRCInputs(); executeInputs(); - } - catch{ - break; - } } } void SystemManager::updateRCInputs() { - /* Get Inputs from SBUS and update corresponding private variable (also monitors Watchdog) */ + this->rcInputs_.assignValues(rcController_.GetRCControl()); return; } @@ -36,11 +33,11 @@ void SystemManager::executeInputs() { return; } -Flightmode SystemManager::getCurrentFlightMode() { +config::Flightmode* SystemManager::getCurrentFlightMode() { return this->currentFlightMode_; } -void SystemManager::setCurrentFlightMode(config::Flightmode flightmode) { +void SystemManager::setCurrentFlightMode(config::Flightmode *flightmode) { this->currentFlightMode_ = flightmode; } diff --git a/Tools/Firmware/CMakeLists.txt b/Tools/Firmware/CMakeLists.txt index 65ef8f8a..8be5454a 100644 --- a/Tools/Firmware/CMakeLists.txt +++ b/Tools/Firmware/CMakeLists.txt @@ -95,10 +95,12 @@ file(GLOB_RECURSE C_SOURCES ${HAL_DRIVERS_C_SOURCES} ${FREE_RTOS_C_SOURCES} ${HAL_CORE_C_SOURCES} ${ATTITUDE_MANAGER_C_SOURCES} + ${SYSTEM_MANAGER_C_SOURCES} ${DRIVERS_C_SOURCES}) message("C Sources: ${C_SOURCES}") file(GLOB_RECURSE CXX_SOURCES ${HAL_CORE_CXX_SOURCES} ${ATTITUDE_MANAGER_CXX_SOURCES} + ${SYSTEM_MANAGER_CXX_SOURCES} ${DRIVERS_RcReceiver_CXX_SOURCES} ${DRIVERS_Common_CXX_SOURCES} ${DRIVERS_CXX_SOURCES})