mirror of
https://github.com/okalachev/flix.git
synced 2026-08-16 00:38:56 +00:00
Simplify parameter defaults definition
This commit is contained in:
@@ -179,8 +179,6 @@ Before flight you need to calibrate the accelerometer:
|
|||||||
|
|
||||||
If using non-default motor pins, set the pin numbers using the parameters: `MOTOR_PIN_FL`, `MOTOR_PIN_FR`, `MOTOR_PIN_RL`, `MOTOR_PIN_RR` (front-left, front-right, rear-left, rear-right respectively).
|
If using non-default motor pins, set the pin numbers using the parameters: `MOTOR_PIN_FL`, `MOTOR_PIN_FR`, `MOTOR_PIN_RL`, `MOTOR_PIN_RR` (front-left, front-right, rear-left, rear-right respectively).
|
||||||
|
|
||||||
Certain ESP32 models (such as ESP32-S3 and ESP32-C3) support a lower maximum PWM frequency; on these boards the parameter `MOT_PWM_FREQ` should be set to 38000 Hz.
|
|
||||||
|
|
||||||
#### Brushless motors
|
#### Brushless motors
|
||||||
|
|
||||||
In case of using brushless motors with ESCs:
|
In case of using brushless motors with ESCs:
|
||||||
|
|||||||
+19
-61
@@ -1,69 +1,27 @@
|
|||||||
// Copyright (c) 2026 Oleg Kalachev <okalachev@gmail.com>
|
// Copyright (c) 2026 Oleg Kalachev <okalachev@gmail.com>
|
||||||
// Repository: https://github.com/okalachev/flix
|
// Repository: https://github.com/okalachev/flix
|
||||||
|
|
||||||
// Default configuration parameters
|
// Parameter defaults
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// IMU
|
void setDefaults() {
|
||||||
#define IMU_MODEL -1
|
// Set defaults here
|
||||||
#define IMU_BUS 0
|
|
||||||
#define IMU_PIN_INT -1
|
|
||||||
#define IMU_ROT_ROLL 0
|
|
||||||
#define IMU_ROT_PITCH 0
|
|
||||||
#define IMU_ROT_YAW -PI/2
|
|
||||||
|
|
||||||
// Motors
|
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
#define MOTOR_PIN_FL 12
|
pwmFrequency = 38000;
|
||||||
#define MOTOR_PIN_FR 13
|
|
||||||
#define MOTOR_PIN_RL 14
|
|
||||||
#define MOTOR_PIN_RR 15
|
|
||||||
#define MOT_PWM_FREQ 78000
|
|
||||||
#define MOT_PWM_RES 10
|
|
||||||
#define MOT_PWM_STOP 0
|
|
||||||
#define MOT_PWM_MIN 0
|
|
||||||
#define MOT_PWM_MAX -1
|
|
||||||
|
|
||||||
// Control
|
|
||||||
#define PITCHRATE_P 0.05
|
|
||||||
#define PITCHRATE_I 0.2
|
|
||||||
#define PITCHRATE_D 0.001
|
|
||||||
#define PITCHRATE_I_LIM 0.3
|
|
||||||
#define ROLLRATE_P PITCHRATE_P
|
|
||||||
#define ROLLRATE_I PITCHRATE_I
|
|
||||||
#define ROLLRATE_D PITCHRATE_D
|
|
||||||
#define ROLLRATE_I_LIM PITCHRATE_I_LIM
|
|
||||||
#define YAWRATE_P 0.3
|
|
||||||
#define YAWRATE_I 0.0
|
|
||||||
#define YAWRATE_D 0.0
|
|
||||||
#define YAWRATE_I_LIM 0.3
|
|
||||||
#define ROLL_P 6
|
|
||||||
#define ROLL_I 0
|
|
||||||
#define ROLL_D 0
|
|
||||||
#define PITCH_P ROLL_P
|
|
||||||
#define PITCH_I ROLL_I
|
|
||||||
#define PITCH_D ROLL_D
|
|
||||||
#define YAW_P 3
|
|
||||||
#define RATES_D_LPF_ALPHA 0.2 // cutoff frequency ~ 40 Hz
|
|
||||||
|
|
||||||
// Power
|
|
||||||
#define VOLTAGE_PIN -1
|
|
||||||
#define VOLTAGE_SCALE 2
|
|
||||||
|
|
||||||
// RC
|
|
||||||
#define RC_PIN_RX -1
|
|
||||||
|
|
||||||
// Flix2 board configuration
|
|
||||||
#ifdef FLIX2
|
|
||||||
#define IMU_MODEL 4 // ICM-40609-D
|
|
||||||
#define IMU_PIN_INT 10
|
|
||||||
#define SS 14
|
|
||||||
|
|
||||||
#define MOTOR_PIN_RL 41
|
|
||||||
#define MOTOR_PIN_RR 7
|
|
||||||
#define MOTOR_PIN_FL 38
|
|
||||||
#define MOTOR_PIN_FR 18
|
|
||||||
#define MOT_PWM_FREQ 38000
|
|
||||||
|
|
||||||
#define VOLTAGE_PIN 3
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FLIX2
|
||||||
|
imuModel = 4; // ICM-40609-D
|
||||||
|
imuIntPin = 10;
|
||||||
|
imuCsPin = 14;
|
||||||
|
|
||||||
|
motorPins[0] = 41;
|
||||||
|
motorPins[1] = 7;
|
||||||
|
motorPins[2] = 38;
|
||||||
|
motorPins[3] = 18;
|
||||||
|
|
||||||
|
voltagePin = 3;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
+7
-7
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
// Flight control
|
// Flight control
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "quaternion.h"
|
#include "quaternion.h"
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
@@ -13,6 +12,7 @@
|
|||||||
const int RAW = 0, ACRO = 1, STAB = 2, AUTO = 3; // flight modes
|
const int RAW = 0, ACRO = 1, STAB = 2, AUTO = 3; // flight modes
|
||||||
int mode = STAB;
|
int mode = STAB;
|
||||||
bool armed = false;
|
bool armed = false;
|
||||||
|
int _desaturate = 1;
|
||||||
|
|
||||||
Quaternion attitudeTarget;
|
Quaternion attitudeTarget;
|
||||||
Vector ratesTarget;
|
Vector ratesTarget;
|
||||||
@@ -20,12 +20,12 @@ Vector ratesExtra; // feedforward rates
|
|||||||
Vector torqueTarget; // 0 - no torque, 1 - maximum torque
|
Vector torqueTarget; // 0 - no torque, 1 - maximum torque
|
||||||
float thrustTarget;
|
float thrustTarget;
|
||||||
|
|
||||||
PID rollRatePID(ROLLRATE_P, ROLLRATE_I, ROLLRATE_D, ROLLRATE_I_LIM, RATES_D_LPF_ALPHA);
|
PID rollRatePID(0.05, 0.2, 0.001, 0.3, 0.2);
|
||||||
PID pitchRatePID(PITCHRATE_P, PITCHRATE_I, PITCHRATE_D, PITCHRATE_I_LIM, RATES_D_LPF_ALPHA);
|
PID pitchRatePID(0.05, 0.2, 0.001, 0.3, 0.2);
|
||||||
PID yawRatePID(YAWRATE_P, YAWRATE_I, YAWRATE_D);
|
PID yawRatePID(0.3);
|
||||||
PID rollPID(ROLL_P, ROLL_I, ROLL_D);
|
PID rollPID(6);
|
||||||
PID pitchPID(PITCH_P, PITCH_I, PITCH_D);
|
PID pitchPID(6);
|
||||||
PID yawPID(YAW_P);
|
PID yawPID(3);
|
||||||
Vector maxRate(radians(360), radians(360), radians(360));
|
Vector maxRate(radians(360), radians(360), radians(360));
|
||||||
float tiltMax = radians(30);
|
float tiltMax = radians(30);
|
||||||
int flightModes[] = {STAB, STAB, STAB}; // map for rc mode switch
|
int flightModes[] = {STAB, STAB, STAB}; // map for rc mode switch
|
||||||
|
|||||||
+4
-5
@@ -6,17 +6,16 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <FlixPeriph.h>
|
#include <FlixPeriph.h>
|
||||||
#include "config.h"
|
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
IMU *imu;
|
IMU *imu;
|
||||||
int imuModel = IMU_MODEL; // 1 - MPU9250, 2 - ICM20948, 3 - MPU6050, 4 - ICM40609D
|
int imuModel = -1; // 1 - MPU9250, 2 - ICM20948, 3 - MPU6050, 4 - ICM40609D
|
||||||
int imuBus = IMU_BUS; // 0 - SPI, 1 - I2C
|
int imuBus = 0; // 0 - SPI, 1 - I2C
|
||||||
int imuSckPin = SCK, imuMisoPin = MISO, imuMosiPin = MOSI, imuCsPin = SS, imuIntPin = IMU_PIN_INT;
|
int imuSckPin = SCK, imuMisoPin = MISO, imuMosiPin = MOSI, imuCsPin = SS, imuIntPin = -1;
|
||||||
int imuSdaPin = SDA, imuSclPin = SCL;
|
int imuSdaPin = SDA, imuSclPin = SCL;
|
||||||
Vector imuRotation(IMU_ROT_ROLL, IMU_ROT_PITCH, IMU_ROT_YAW); // imu orientation as Euler angles
|
Vector imuRotation(0, 0, -PI/2); // imu orientation as Euler angles
|
||||||
|
|
||||||
Vector gyro; // gyroscope output, rad/s
|
Vector gyro; // gyroscope output, rad/s
|
||||||
Vector gyroBias;
|
Vector gyroBias;
|
||||||
|
|||||||
+6
-7
@@ -3,17 +3,16 @@
|
|||||||
|
|
||||||
// PWM control for motors
|
// PWM control for motors
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
float motors[4]; // normalized motor thrusts in range [0..1]
|
float motors[4]; // normalized motor thrusts in range [0..1]
|
||||||
|
|
||||||
int motorPins[4] = {MOTOR_PIN_RL, MOTOR_PIN_RR, MOTOR_PIN_FR, MOTOR_PIN_FL}; // default pin numbers
|
int motorPins[4] = {-1, -1, -1, -1}; // default pin numbers
|
||||||
int pwmFrequency = MOT_PWM_FREQ;
|
int pwmFrequency = 78000;
|
||||||
int pwmResolution = MOT_PWM_RES;
|
int pwmResolution = 10;
|
||||||
int pwmStop = MOT_PWM_STOP;
|
int pwmStop = 0;
|
||||||
int pwmMin = MOT_PWM_MIN;
|
int pwmMin = 0;
|
||||||
int pwmMax = MOT_PWM_MAX; // -1 means duty cycle mode
|
int pwmMax = -1; // -1 means duty cycle mode
|
||||||
|
|
||||||
const int MOTOR_REAR_LEFT = 0, MOTOR_REAR_RIGHT = 1, MOTOR_FRONT_RIGHT = 2, MOTOR_FRONT_LEFT = 3;
|
const int MOTOR_REAR_LEFT = 0, MOTOR_REAR_RIGHT = 1, MOTOR_FRONT_RIGHT = 2, MOTOR_FRONT_LEFT = 3;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ extern float rcLossTimeout, descendTime, disarmTilt;
|
|||||||
extern float voltageScale;
|
extern float voltageScale;
|
||||||
extern LowPassFilter<float> voltageFilter;
|
extern LowPassFilter<float> voltageFilter;
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
Preferences storage;
|
Preferences storage;
|
||||||
|
|
||||||
struct Parameter {
|
struct Parameter {
|
||||||
@@ -161,6 +163,7 @@ Parameter parameters[] = {
|
|||||||
|
|
||||||
void setupParameters() {
|
void setupParameters() {
|
||||||
print("Setup parameters\n");
|
print("Setup parameters\n");
|
||||||
|
setDefaults();
|
||||||
storage.begin("flix");
|
storage.begin("flix");
|
||||||
// Read parameters from storage
|
// Read parameters from storage
|
||||||
for (auto ¶meter : parameters) {
|
for (auto ¶meter : parameters) {
|
||||||
|
|||||||
+2
-3
@@ -5,14 +5,13 @@
|
|||||||
|
|
||||||
#include <soc/soc.h>
|
#include <soc/soc.h>
|
||||||
#include <soc/rtc_cntl_reg.h>
|
#include <soc/rtc_cntl_reg.h>
|
||||||
#include "config.h"
|
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
float voltage = NAN;
|
float voltage = NAN;
|
||||||
LowPassFilter<float> voltageFilter(1);
|
LowPassFilter<float> voltageFilter(1);
|
||||||
int voltagePin = VOLTAGE_PIN;
|
int voltagePin = -1;
|
||||||
float voltageScale = VOLTAGE_SCALE;
|
float voltageScale = 2;
|
||||||
|
|
||||||
void setupPower() {
|
void setupPower() {
|
||||||
REG_CLR_BIT(RTC_CNTL_BROWN_OUT_REG, RTC_CNTL_BROWN_OUT_ENA); // disable reset on low voltage
|
REG_CLR_BIT(RTC_CNTL_BROWN_OUT_REG, RTC_CNTL_BROWN_OUT_ENA); // disable reset on low voltage
|
||||||
|
|||||||
+1
-2
@@ -4,11 +4,10 @@
|
|||||||
// Work with the RC receiver
|
// Work with the RC receiver
|
||||||
|
|
||||||
#include <SBUS.h>
|
#include <SBUS.h>
|
||||||
#include "config.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
SBUS rc(Serial1);
|
SBUS rc(Serial1);
|
||||||
int rcRxPin = RC_PIN_RX; // -1 means disabled
|
int rcRxPin = -1; // -1 means disabled
|
||||||
|
|
||||||
uint16_t channels[16]; // raw rc channels
|
uint16_t channels[16]; // raw rc channels
|
||||||
int channelZero[16]; // calibration zero values
|
int channelZero[16]; // calibration zero values
|
||||||
|
|||||||
Reference in New Issue
Block a user