Cleanups and updates

This commit is contained in:
Oleg Kalachev 2025-02-28 23:58:31 +03:00
parent 0a7ed1039f
commit f2aae92f1e
6 changed files with 10 additions and 12 deletions

View File

@ -6,8 +6,6 @@
#include "pid.h"
#include "vector.h"
extern PID rollRatePID, pitchRatePID, yawRatePID, rollPID, pitchPID;
extern LowPassFilter<Vector> ratesFilter;
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
extern float loopRate;

View File

@ -30,8 +30,8 @@
#define YAW_P 3
#define PITCHRATE_MAX radians(360)
#define ROLLRATE_MAX radians(360)
#define YAWRATE_MAX radians(360)
#define MAX_TILT radians(30)
#define YAWRATE_MAX radians(300)
#define TILT_MAX radians(30)
#define RATES_D_LPF_ALPHA 0.2 // cutoff frequency ~ 40 Hz
@ -92,8 +92,8 @@ void interpretRC() {
yawMode = controls[RC_CHANNEL_YAW] == 0 ? YAW : YAW_RATE;
attitudeTarget = Quaternion::fromEulerZYX(Vector(
controls[RC_CHANNEL_ROLL] * MAX_TILT,
controls[RC_CHANNEL_PITCH] * MAX_TILT,
controls[RC_CHANNEL_ROLL] * TILT_MAX,
controls[RC_CHANNEL_PITCH] * TILT_MAX,
attitudeTarget.getYaw()));
ratesTarget.z = -controls[RC_CHANNEL_YAW] * YAWRATE_MAX; // positive yaw stick means clockwise rotation in FLU

View File

@ -8,14 +8,15 @@
extern float controlsTime;
// RC loss failsafe
void failsafe() {
if (t - controlsTime > RC_LOSS_TIMEOUT) {
descend();
}
}
// Smooth descend on RC lost
void descend() {
// Smooth descend on RC lost
mode = STAB;
controls[RC_CHANNEL_ROLL] = 0;
controls[RC_CHANNEL_PITCH] = 0;

View File

@ -7,11 +7,12 @@
#include <MPU9250.h>
#include "util.h"
MPU9250 IMU(SPI);
// NOTE: use 'ca' command to calibrate the accelerometer and put the values here
Vector accBias(0, 0, 0);
Vector accScale(1, 1, 1);
MPU9250 IMU(SPI);
Vector gyroBias;
void setupIMU() {

View File

@ -2,8 +2,6 @@
// Repository: https://github.com/okalachev/flix
// Motors output control using MOSFETs
// In case of using ESC, use this version of the code: https://gist.github.com/okalachev/8871d3a94b6b6c0a298f41a4edd34c61.
// Motor: 8520 3.7V
#include "util.h"

View File

@ -36,14 +36,14 @@ void normalizeRC() {
}
void calibrateRC() {
Serial.println("Calibrate RC: move all sticks to maximum positions in 4 seconds");
Serial.println("Calibrate RC: move all sticks to maximum positions [4 sec]");
Serial.println("··o ··o\n··· ···\n··· ···");
delay(4000);
while (!readRC());
for (int i = 0; i < 16; i++) {
channelMax[i] = channels[i];
}
Serial.println("Calibrate RC: move all sticks to neutral positions in 4 seconds");
Serial.println("Calibrate RC: move all sticks to neutral positions [4 sec]");
Serial.println("··· ···\n··· ·o·\n·o· ···");
delay(4000);
while (!readRC());