mirror of
https://github.com/okalachev/flix.git
synced 2026-08-16 00:38:56 +00:00
Move most parameter defaults to config.h
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2026 Oleg Kalachev <okalachev@gmail.com>
|
||||
// Repository: https://github.com/okalachev/flix
|
||||
|
||||
// Default configuration parameters
|
||||
|
||||
#pragma once
|
||||
|
||||
// IMU
|
||||
#define IMU_MODEL -1
|
||||
#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
|
||||
#define MOTOR_PIN_FL 12
|
||||
#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
|
||||
+4
-28
@@ -3,37 +3,13 @@
|
||||
|
||||
// Flight control
|
||||
|
||||
#include "config.h"
|
||||
#include "vector.h"
|
||||
#include "quaternion.h"
|
||||
#include "pid.h"
|
||||
#include "filter.h"
|
||||
#include "util.h"
|
||||
|
||||
#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 PITCHRATE_MAX radians(360)
|
||||
#define ROLLRATE_MAX radians(360)
|
||||
#define YAWRATE_MAX radians(300)
|
||||
#define TILT_MAX radians(30)
|
||||
#define RATES_D_LPF_ALPHA 0.2 // cutoff frequency ~ 40 Hz
|
||||
|
||||
const int RAW = 0, ACRO = 1, STAB = 2, AUTO = 3; // flight modes
|
||||
int mode = STAB;
|
||||
bool armed = false;
|
||||
@@ -49,9 +25,9 @@ PID pitchRatePID(PITCHRATE_P, PITCHRATE_I, PITCHRATE_D, PITCHRATE_I_LIM, RATES_D
|
||||
PID yawRatePID(YAWRATE_P, YAWRATE_I, YAWRATE_D);
|
||||
PID rollPID(ROLL_P, ROLL_I, ROLL_D);
|
||||
PID pitchPID(PITCH_P, PITCH_I, PITCH_D);
|
||||
PID yawPID(YAW_P, 0, 0);
|
||||
Vector maxRate(ROLLRATE_MAX, PITCHRATE_MAX, YAWRATE_MAX);
|
||||
float tiltMax = TILT_MAX;
|
||||
PID yawPID(YAW_P);
|
||||
Vector maxRate(radians(360), radians(360), radians(360));
|
||||
float tiltMax = radians(30);
|
||||
int flightModes[] = {STAB, STAB, STAB}; // map for rc mode switch
|
||||
|
||||
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
|
||||
|
||||
+5
-4
@@ -6,16 +6,17 @@
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <FlixPeriph.h>
|
||||
#include "config.h"
|
||||
#include "vector.h"
|
||||
#include "filter.h"
|
||||
#include "util.h"
|
||||
|
||||
IMU *imu;
|
||||
int imuModel = -1; // 1 - MPU9250, 2 - ICM20948, 3 - MPU6050, 4 - ICM40609D
|
||||
int imuBus = 0; // 0 - SPI, 1 - I2C
|
||||
int imuSckPin = SCK, imuMisoPin = MISO, imuMosiPin = MOSI, imuCsPin = SS, imuIntPin = -1;
|
||||
int imuModel = IMU_MODEL; // 1 - MPU9250, 2 - ICM20948, 3 - MPU6050, 4 - ICM40609D
|
||||
int imuBus = IMU_BUS; // 0 - SPI, 1 - I2C
|
||||
int imuSckPin = SCK, imuMisoPin = MISO, imuMosiPin = MOSI, imuCsPin = SS, imuIntPin = IMU_PIN_INT;
|
||||
int imuSdaPin = SDA, imuSclPin = SCL;
|
||||
Vector imuRotation(0, 0, PI / 2); // imu orientation as Euler angles
|
||||
Vector imuRotation(IMU_ROT_ROLL, IMU_ROT_PITCH, IMU_ROT_YAW); // imu orientation as Euler angles
|
||||
|
||||
Vector gyro; // gyroscope output, rad/s
|
||||
Vector gyroBias;
|
||||
|
||||
+7
-6
@@ -3,16 +3,17 @@
|
||||
|
||||
// PWM control for motors
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
float motors[4]; // normalized motor thrusts in range [0..1]
|
||||
|
||||
int motorPins[4] = {-1, -1, -1, -1}; // default pin numbers
|
||||
int pwmFrequency = 78000;
|
||||
int pwmResolution = 10;
|
||||
int pwmStop = 0;
|
||||
int pwmMin = 0;
|
||||
int pwmMax = -1; // -1 means duty cycle mode
|
||||
int motorPins[4] = {MOTOR_PIN_RL, MOTOR_PIN_RR, MOTOR_PIN_FR, MOTOR_PIN_FL}; // default pin numbers
|
||||
int pwmFrequency = MOT_PWM_FREQ;
|
||||
int pwmResolution = MOT_PWM_RES;
|
||||
int pwmStop = MOT_PWM_STOP;
|
||||
int pwmMin = MOT_PWM_MIN;
|
||||
int pwmMax = MOT_PWM_MAX; // -1 means duty cycle mode
|
||||
|
||||
const int MOTOR_REAR_LEFT = 0, MOTOR_REAR_RIGHT = 1, MOTOR_FRONT_RIGHT = 2, MOTOR_FRONT_LEFT = 3;
|
||||
|
||||
|
||||
+3
-2
@@ -5,13 +5,14 @@
|
||||
|
||||
#include <soc/soc.h>
|
||||
#include <soc/rtc_cntl_reg.h>
|
||||
#include "config.h"
|
||||
#include "filter.h"
|
||||
#include "util.h"
|
||||
|
||||
float voltage = NAN;
|
||||
LowPassFilter<float> voltageFilter(1);
|
||||
int voltagePin = -1;
|
||||
float voltageScale = 2;
|
||||
int voltagePin = VOLTAGE_PIN;
|
||||
float voltageScale = VOLTAGE_SCALE;
|
||||
|
||||
void setupPower() {
|
||||
REG_CLR_BIT(RTC_CNTL_BROWN_OUT_REG, RTC_CNTL_BROWN_OUT_ENA); // disable reset on low voltage
|
||||
|
||||
+2
-1
@@ -4,10 +4,11 @@
|
||||
// Work with the RC receiver
|
||||
|
||||
#include <SBUS.h>
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
SBUS rc(Serial1);
|
||||
int rcRxPin = -1; // -1 means disabled
|
||||
int rcRxPin = RC_PIN_RX; // -1 means disabled
|
||||
|
||||
uint16_t channels[16]; // raw rc channels
|
||||
int channelZero[16]; // calibration zero values
|
||||
|
||||
Reference in New Issue
Block a user