-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into basic-system-manager
- Loading branch information
Showing
11 changed files
with
275 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters