Skip to content

Commit

Permalink
Added basic SBUS implementation
Browse files Browse the repository at this point in the history
- Added a function to RCControls struct to assign values from an existing object
- Implemented basic SBUS input taking with SM
- Updated CMAKE
  • Loading branch information
TheSpaceDragon committed Jul 13, 2023
1 parent 53f83a9 commit 4255266
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
18 changes: 18 additions & 0 deletions Drivers/rc_receiver/Inc/rcreceiver_datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

2 changes: 2 additions & 0 deletions Tools/Firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 4255266

Please sign in to comment.