Skip to content

Commit

Permalink
Merge branch 'main' into basic-system-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpaceDragon authored Sep 8, 2023
2 parents 74b3506 + f7cffb6 commit df7c938
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 10 deletions.
4 changes: 2 additions & 2 deletions AttitudeManager/FlightModes/Inc/AM_ControlAlgorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace AM {

class ControlAlgorithm {
class Flightmode {
public:
ControlAlgorithm(){};
Flightmode(){};

/// @brief Run the controls algorithm for the given flight model.
/// @param
Expand Down
4 changes: 2 additions & 2 deletions AttitudeManager/Inc/AM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AttitudeManager {

static AttitudeManagerInput getControlInputs();

AttitudeManager(ControlAlgorithm* control_algorithm) : control_algorithm(control_algorithm){};
AttitudeManager(Flightmode* control_algorithm) : control_algorithm(control_algorithm){};

void runControlLoopIteration(const AttitudeManagerInput& instructions);

Expand All @@ -34,7 +34,7 @@ class AttitudeManager {

static struct AttitudeManagerInput control_inputs;

ControlAlgorithm* control_algorithm;
Flightmode* control_algorithm;
};

} // namespace AM
Expand Down
2 changes: 1 addition & 1 deletion Boardfiles/discoveryl562qe/discoveryl562qe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(CMAKE_SIZE arm-none-eabi-size CACHE INTERNAL "")

# ARM compiler options
set(MCU_CPU cortex-m33)
set(MCU_FLOAT_ABI soft) # since we don't have a floating point unit on this chip. Otherwise should be hard
set(MCU_FLOAT_ABI hard)
set(MCU_FLAGS "-mcpu=${MCU_CPU} -mthumb -mfloat-abi=${MCU_FLOAT_ABI}")

set(COMMON_FLAGS "${MCU_FLAGS} -g -Wall -Wextra -Wno-unused-parameter -ffunction-sections -fdata-sections")
Expand Down
2 changes: 1 addition & 1 deletion Boardfiles/nucleol552zeq/nucleol552zeq.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(CMAKE_SIZE arm-none-eabi-size CACHE INTERNAL "")

# ARM compiler options
set(MCU_CPU cortex-m33)
set(MCU_FLOAT_ABI soft) # since we don't have a floating point unit on this chip. Otherwise should be hard
set(MCU_FLOAT_ABI hard)
set(MCU_FLAGS "-mcpu=${MCU_CPU} -mthumb -mfloat-abi=${MCU_FLOAT_ABI}")

set(COMMON_FLAGS "${MCU_FLAGS} -g -Wall -Wextra -Wno-unused-parameter -ffunction-sections -fdata-sections")
Expand Down
99 changes: 99 additions & 0 deletions Models/config_foundation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#ifndef ZPSW3_CONFIG_FOUNDATION_HPP
#define ZPSW3_CONFIG_FOUNDATION_HPP

#include <cstdint>

#include "AM_ControlAlgorithm.hpp"
#include "temp_drivers.hpp"

namespace config
{
using percentage_t = float;

//Define factory function to create drivers and flightmodes
template <class BaseClass, class DerivedClass, auto... args>
BaseClass* constructObject() {
return new DerivedClass(args...);
}

//Typedef pointer to factory function
template <class BaseClass>
using ObjectFactory = BaseClass* (*)(void);



/* Motor declarations */

typedef enum {
yaw,
pitch,
roll,
throttle
} ControlAxis_t;

typedef struct {
ControlAxis_t axis;
bool isInverted = false;
ObjectFactory<MotorChannel> driverConstructor;
} Motor_t;



/* RC input declarations */

typedef struct {
//TODO: determine other config fields relevant to the RC input type
ObjectFactory<RCInputDriver> driverConstructor;
} RCInput_t;



/* GPS declarations */

typedef struct {
ObjectFactory<GPSDriver> driverConstructor;
} GPS_t;



/* Flightmode declarations */

typedef struct {
bool isEnabled = false;
float p = 0.0f;
float i = 0.0f;
float d = 0.0f;
} AxisPID_t;

typedef struct {
AxisPID_t yawPID = {};
AxisPID_t pitchPID = {};
AxisPID_t rollPID = {};
AxisPID_t throttlePID = {};
} ControlPID_t;

typedef struct {
percentage_t min = 0.0f;
percentage_t max = 100.0f;
} AxisLimits_t;

typedef struct {
AxisLimits_t yawLimit = {};
AxisLimits_t pitchLimit = {};
AxisLimits_t rollLimit = {};
AxisLimits_t throttleLimit = {};
} ControlLimits_t;

typedef struct {
ControlPID_t PIDValues = {};
ControlLimits_t controlLimits = {};
} ControlTuning_t;

typedef struct {
ControlTuning_t tuningData;
ObjectFactory<AM::Flightmode> flightmodeConstructor;
} Flightmode_t;

}

#endif // ZPSW3_CONFIG_FOUNDATION_HPP
117 changes: 117 additions & 0 deletions Models/example_model/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#ifndef ZPSW3_CONFIG_HPP
#define ZPSW3_CONFIG_HPP

#include "config_foundation.hpp"
#include "tim.h"

namespace config
{

/* Motor config */

constexpr Motor_t motors[] = {
{ //Yaw servo motor
.axis = yaw,
.isInverted = false,
.driverConstructor = constructObject<MotorChannel, PWMChannel,
/*timer*/ &htim1, /*timer_channel*/ 0>
},
{ //Roll BLDC motor
.axis = roll,
.isInverted = true,
.driverConstructor = constructObject<MotorChannel, TempDSHOTDriver>
}
};

constexpr uint8_t NUM_MOTORS = sizeof(motors)/sizeof(Motor_t);



/* RC input config */

//Example array for a model that supports both PPM and SBUS input
constexpr RCInput_t RCInputs[] = {
{ //PPM input
.driverConstructor = constructObject<RCInputDriver, TempPPMDriver>
},
{ //SBUS input
.driverConstructor = constructObject<RCInputDriver, TempSBusDriver>
}
};

constexpr uint8_t NUM_RC_INPUTS = sizeof(RCInputs)/sizeof(RCInput_t);



/* GPS config */

//Example array for a model with two GPS modules
constexpr GPS_t GPSArray[] = {
{ //NEOM8
.driverConstructor = constructObject<GPSDriver, TempNEOM8Driver>
},
{ //Other GPS
.driverConstructor = constructObject<GPSDriver, otherGPSDriver>
}
};

constexpr uint8_t NUM_GPS = sizeof(GPSArray)/sizeof(GPS_t);



/* Flightmode Config */

constexpr Flightmode_t flightmodes[] = {
{ //Flightmode1
.tuningData{
.PIDValues = {
.yawPID = {
.isEnabled = true,
.p = 1.0f,
.i = 1.0f,
.d = 1.0f
}
},
.controlLimits = {
.yawLimit = {
.min = 5.0f,
.max = 95.0f
}
}
},
.flightmodeConstructor = constructObject<AM::Flightmode, ExampleFlightmode1>
},
{ //Flightmode2
.tuningData{
.PIDValues = {
.yawPID = {
.isEnabled = true,
.p = 1.0f,
.i = 1.0f,
.d = 1.0f
},
.rollPID = {
.isEnabled = true,
.p = 1.0f,
.i = 1.0f,
.d = 1.0f
}
},
.controlLimits = {
.yawLimit = {
.min = 5.0f,
.max = 95.0f
},
.rollLimit = {
.min = 0.0f,
.max = 100.0f
}
}
},
.flightmodeConstructor = constructObject<AM::Flightmode, ExampleFlightmode2>
}
};

}

#endif // ZPSW3_CONFIG_HPP
37 changes: 37 additions & 0 deletions Models/temp_drivers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef ZPSW3_TEMP_DRIVERS_HPP
#define ZPSW3_TEMP_DRIVERS_HPP

//TODO: Remove this file when drivers and flightmodes are implemented

#include "ZP_D_PWMChannel.hpp"

class TempDSHOTDriver : public MotorChannel
{
public:
TempDSHOTDriver() {}
void set(uint8_t percent){}
};
class RCInputDriver{};
class TempPPMDriver : public RCInputDriver{};
class TempSBusDriver : public RCInputDriver{};
class GPSDriver{};
class TempNEOM8Driver : public GPSDriver{};
class otherGPSDriver : public GPSDriver{};

class ExampleFlightmode1 : public AM::Flightmode{
public:
ExampleFlightmode1(){}
//TODO: Implement control algorithm functions in AM
void run();
void updatePid();
};

class ExampleFlightmode2 : public AM::Flightmode{
public:
ExampleFlightmode2(){}
void run();
void updatePid();
};


#endif // ZPSW3_TEMP_DRIVERS_HPP
4 changes: 4 additions & 0 deletions Tools/Firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ include_directories(
${ROOT_DIR}/Boardfiles/${FOLDER_NAME}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
${ROOT_DIR}/Boardfiles/${FOLDER_NAME}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_${PORTABLE_NAME}
${ROOT_DIR}/Boardfiles/${FOLDER_NAME}/Middlewares/Third_Party/FreeRTOS/Source/include

## Models Includes ##
${ROOT_DIR}/Models
${ROOT_DIR}/Models/${MODEL_NAME}
)

## Boardfile Sources ##
Expand Down
1 change: 1 addition & 0 deletions Tools/default_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

COMPILE_TYPE="Firmware"
PLATFORM="nucleol552zeq"
MODEL_NAME="example_model"

# --- Compile settings end ---

Expand Down
8 changes: 6 additions & 2 deletions Tools/tools.bash
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if [[ $# -eq 0 ]]; then
elif [[ $1 == "compile" ]]; then
RUN_TEST=false
CLEAN=false
shift 1 && while getopts :t:p:c opt
shift 1 && while getopts :t:p:m:c opt
do
case ${opt} in
t)
Expand All @@ -60,6 +60,9 @@ elif [[ $1 == "compile" ]]; then
p)
PLATFORM=${OPTARG}
;;
m)
MODEL_NAME=${OPTARG}
;;
c)
CLEAN=true
;;
Expand Down Expand Up @@ -114,7 +117,7 @@ if [[ $RUN_TEST == false ]]; then
echo "Building ZeroPilot for $(echo $COMPILE_TYPE | tr '[:upper:]' '[:lower:]')."
COMPILE_DIR="$SCRIPT_PATH/$COMPILE_TYPE/build"
if [[ $COMPILE_TYPE == "Firmware" ]]; then
echo "Building for $PLATFORM."
echo "Building for platform $PLATFORM and model $MODEL_NAME."
fi
if [[ $CLEAN == true ]]; then
echo "Cleaning old $(echo $COMPILE_TYPE | tr '[:upper:]' '[:lower:]') build environment."
Expand All @@ -131,6 +134,7 @@ if [[ $RUN_TEST == false ]]; then
-G "${GENERATOR}" \
-DCMAKE_BUILD_TYPE="Debug" \
-DCMAKE_TOOLCHAIN_FILE="../../../Boardfiles/$PLATFORM/$PLATFORM.cmake" \
-DMODEL_NAME="$MODEL_NAME" \
-Wdev \
-Wdeprecated \
../
Expand Down
7 changes: 5 additions & 2 deletions Tools/tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ param(
[string] $t,
[string] $p,
[switch] $c,
[string] $f
[string] $f,
[string] $m
)

# read defaults from file, and set variable intial value
Expand All @@ -29,6 +30,7 @@ foreach($line in Get-Content "$PSScriptRoot/default_config.txt") {
$COMPILE_TYPE = if ($t) {$t} else {$COMPILE_TYPE}
$PLATFORM = if ($p) {$p} else {$PLATFORM}
$TEST_FILTER = if ($f) {$f} else {$TEST_FILTER}
$MODEL_NAME = if ($m) {$m} else {$MODEL_NAME}


# ====================
Expand Down Expand Up @@ -61,7 +63,7 @@ if($FUNCTION -eq "compile") {
Write-Host "Building ZeroPilot for $($COMPILE_TYPE.ToLower())."
$COMPILE_DIR = "$PSScriptRoot/$COMPILE_TYPE/build"
if($COMPILE_TYPE -eq "Firmware") {
Write-Host "Building for $PLATFORM."
Write-Host "Building for platform $PLATFORM and model $MODEL_NAME."
}
if($c) {
Write-Host "Cleaning old $($COMPILE_TYPE.ToLower()) build environment."
Expand All @@ -77,6 +79,7 @@ if($FUNCTION -eq "compile") {
-G "${GENERATOR}" `
-DCMAKE_BUILD_TYPE="Debug" `
-DCMAKE_TOOLCHAIN_FILE="../../../Boardfiles/$PLATFORM/$PLATFORM.cmake" `
-DMODEL_NAME="$MODEL_NAME" `
-Wdev `
-Wdeprecated `
..
Expand Down

0 comments on commit df7c938

Please sign in to comment.