From 0de72f5af7aaa64bfd485df7bc3d181d7c19360e Mon Sep 17 00:00:00 2001 From: Derek Tang <68519418+DerekTang04@users.noreply.github.com> Date: Sat, 29 Jul 2023 18:30:57 -0400 Subject: [PATCH 1/2] use hard float (#24) --- Boardfiles/discoveryl562qe/discoveryl562qe.cmake | 2 +- Boardfiles/nucleol552zeq/nucleol552zeq.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Boardfiles/discoveryl562qe/discoveryl562qe.cmake b/Boardfiles/discoveryl562qe/discoveryl562qe.cmake index 622fb6ca..dca51df6 100644 --- a/Boardfiles/discoveryl562qe/discoveryl562qe.cmake +++ b/Boardfiles/discoveryl562qe/discoveryl562qe.cmake @@ -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") diff --git a/Boardfiles/nucleol552zeq/nucleol552zeq.cmake b/Boardfiles/nucleol552zeq/nucleol552zeq.cmake index 7423d1f6..d325dc52 100644 --- a/Boardfiles/nucleol552zeq/nucleol552zeq.cmake +++ b/Boardfiles/nucleol552zeq/nucleol552zeq.cmake @@ -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") From f7cffb69ed2abac7795953ec75992098257df85f Mon Sep 17 00:00:00 2001 From: Anthony Bertnyk Date: Tue, 5 Sep 2023 18:26:44 -0400 Subject: [PATCH 2/2] Model configuration system (#17) --- .../FlightModes/Inc/AM_ControlAlgorithm.hpp | 4 +- AttitudeManager/Inc/AM.hpp | 4 +- Models/config_foundation.hpp | 99 +++++++++++++++ Models/example_model/config.hpp | 117 ++++++++++++++++++ Models/temp_drivers.hpp | 37 ++++++ Tools/Firmware/CMakeLists.txt | 7 ++ Tools/default_config.txt | 1 + Tools/tools.bash | 8 +- Tools/tools.ps1 | 7 +- 9 files changed, 276 insertions(+), 8 deletions(-) create mode 100644 Models/config_foundation.hpp create mode 100644 Models/example_model/config.hpp create mode 100644 Models/temp_drivers.hpp diff --git a/AttitudeManager/FlightModes/Inc/AM_ControlAlgorithm.hpp b/AttitudeManager/FlightModes/Inc/AM_ControlAlgorithm.hpp index 2a0a0a52..87ba2443 100644 --- a/AttitudeManager/FlightModes/Inc/AM_ControlAlgorithm.hpp +++ b/AttitudeManager/FlightModes/Inc/AM_ControlAlgorithm.hpp @@ -13,9 +13,9 @@ namespace AM { -class ControlAlgorithm { +class Flightmode { public: - ControlAlgorithm(){}; + Flightmode(){}; /// @brief Run the controls algorithm for the given flight model. /// @param diff --git a/AttitudeManager/Inc/AM.hpp b/AttitudeManager/Inc/AM.hpp index 10431097..1bc70836 100644 --- a/AttitudeManager/Inc/AM.hpp +++ b/AttitudeManager/Inc/AM.hpp @@ -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); @@ -34,7 +34,7 @@ class AttitudeManager { static struct AttitudeManagerInput control_inputs; - ControlAlgorithm* control_algorithm; + Flightmode* control_algorithm; }; } // namespace AM diff --git a/Models/config_foundation.hpp b/Models/config_foundation.hpp new file mode 100644 index 00000000..15832ce5 --- /dev/null +++ b/Models/config_foundation.hpp @@ -0,0 +1,99 @@ +#ifndef ZPSW3_CONFIG_FOUNDATION_HPP +#define ZPSW3_CONFIG_FOUNDATION_HPP + +#include + +#include "AM_ControlAlgorithm.hpp" +#include "temp_drivers.hpp" + +namespace config +{ + using percentage_t = float; + + //Define factory function to create drivers and flightmodes + template + BaseClass* constructObject() { + return new DerivedClass(args...); + } + + //Typedef pointer to factory function + template + using ObjectFactory = BaseClass* (*)(void); + + + + /* Motor declarations */ + + typedef enum { + yaw, + pitch, + roll, + throttle + } ControlAxis_t; + + typedef struct { + ControlAxis_t axis; + bool isInverted = false; + ObjectFactory driverConstructor; + } Motor_t; + + + + /* RC input declarations */ + + typedef struct { + //TODO: determine other config fields relevant to the RC input type + ObjectFactory driverConstructor; + } RCInput_t; + + + + /* GPS declarations */ + + typedef struct { + ObjectFactory 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 flightmodeConstructor; + } Flightmode_t; + +} + +#endif // ZPSW3_CONFIG_FOUNDATION_HPP \ No newline at end of file diff --git a/Models/example_model/config.hpp b/Models/example_model/config.hpp new file mode 100644 index 00000000..27d420be --- /dev/null +++ b/Models/example_model/config.hpp @@ -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 + }, + { //Roll BLDC motor + .axis = roll, + .isInverted = true, + .driverConstructor = constructObject + } + }; + + 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 + }, + { //SBUS input + .driverConstructor = constructObject + } + }; + + 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 + }, + { //Other GPS + .driverConstructor = constructObject + } + }; + + 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 + }, + { //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 + } + }; + +} + +#endif // ZPSW3_CONFIG_HPP \ No newline at end of file diff --git a/Models/temp_drivers.hpp b/Models/temp_drivers.hpp new file mode 100644 index 00000000..dfb4cdae --- /dev/null +++ b/Models/temp_drivers.hpp @@ -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 \ No newline at end of file diff --git a/Tools/Firmware/CMakeLists.txt b/Tools/Firmware/CMakeLists.txt index ef00bd64..f1faf0fb 100644 --- a/Tools/Firmware/CMakeLists.txt +++ b/Tools/Firmware/CMakeLists.txt @@ -28,6 +28,9 @@ include_directories( ${ROOT_DIR}/Drivers/ccontrol/Inc ${ROOT_DIR}/Drivers/sensor_fusion/Inc ${ROOT_DIR}/Drivers/IWDG_Driver/Inc + + ${ROOT_DIR}/Drivers/MotorChannel/Inc + ## Boardfiles Includes ## ${ROOT_DIR}/Boardfiles/${FOLDER_NAME}/Drivers/${FAMILY_NAME}_HAL_Driver/Inc ${ROOT_DIR}/Boardfiles/${FOLDER_NAME}/Core/Inc @@ -38,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 ## diff --git a/Tools/default_config.txt b/Tools/default_config.txt index e4851025..6a84b1c6 100644 --- a/Tools/default_config.txt +++ b/Tools/default_config.txt @@ -2,6 +2,7 @@ COMPILE_TYPE="Firmware" PLATFORM="nucleol552zeq" +MODEL_NAME="example_model" # --- Compile settings end --- diff --git a/Tools/tools.bash b/Tools/tools.bash index a2075bf0..35400b43 100644 --- a/Tools/tools.bash +++ b/Tools/tools.bash @@ -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) @@ -60,6 +60,9 @@ elif [[ $1 == "compile" ]]; then p) PLATFORM=${OPTARG} ;; + m) + MODEL_NAME=${OPTARG} + ;; c) CLEAN=true ;; @@ -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." @@ -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 \ ../ diff --git a/Tools/tools.ps1 b/Tools/tools.ps1 index 221e0943..9493b59e 100644 --- a/Tools/tools.ps1 +++ b/Tools/tools.ps1 @@ -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 @@ -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} # ==================== @@ -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." @@ -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 ` ..