mirror of
https://github.com/okalachev/flix.git
synced 2025-07-31 05:18:56 +00:00
Use arm/disarm gestures Add arm/disarm commands Add ratesExtra variable for Rename interpretRC to interpretControls Rename controlRate to controlRates Remove USER mode Add invalidate methods for vector and quaternion Add valid/invalid method for vector and quaternion Add valid/invalid function Print armed in rc command Pass auto mode to heartbeat Use actuator_control_target for motors
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
|
// Repository: https://github.com/okalachev/flix
|
|
|
|
// Main firmware file
|
|
|
|
#include "vector.h"
|
|
#include "quaternion.h"
|
|
#include "util.h"
|
|
|
|
#define SERIAL_BAUDRATE 115200
|
|
#define WIFI_ENABLED 1
|
|
|
|
double t = NAN; // current step time, s
|
|
float dt; // time delta from previous step, s
|
|
float controlRoll, controlPitch, controlYaw, controlThrottle; // pilot's inputs, range [-1, 1]
|
|
float controlArmed = NAN, controlMode = NAN;
|
|
Vector gyro; // gyroscope data
|
|
Vector acc; // accelerometer data, m/s/s
|
|
Vector rates; // filtered angular rates, rad/s
|
|
Quaternion attitude; // estimated attitude
|
|
bool landed; // are we landed and stationary
|
|
float motors[4]; // normalized motors thrust in range [0..1]
|
|
|
|
void setup() {
|
|
Serial.begin(SERIAL_BAUDRATE);
|
|
print("Initializing flix\n");
|
|
disableBrownOut();
|
|
setupParameters();
|
|
setupLED();
|
|
setupMotors();
|
|
setLED(true);
|
|
#if WIFI_ENABLED
|
|
setupWiFi();
|
|
#endif
|
|
setupIMU();
|
|
setupRC();
|
|
setLED(false);
|
|
print("Initializing complete\n");
|
|
}
|
|
|
|
void loop() {
|
|
readIMU();
|
|
step();
|
|
readRC();
|
|
estimate();
|
|
control();
|
|
sendMotors();
|
|
handleInput();
|
|
#if WIFI_ENABLED
|
|
processMavlink();
|
|
#endif
|
|
logData();
|
|
syncParameters();
|
|
}
|