mirror of
https://github.com/okalachev/flix.git
synced 2025-07-30 12:58:59 +00:00
Move command parsing to doCommand Parse command with splitString instead of stringToken Trim commands Move cliTestMotor to the bottom Rename parseInput to handleInput, which is more clear Move motor test function to motors.ino Remove parameters table functionality to simplify the code
59 lines
1.2 KiB
C++
59 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
|
|
|
|
#define RC_CHANNEL_ROLL 0
|
|
#define RC_CHANNEL_PITCH 1
|
|
#define RC_CHANNEL_THROTTLE 2
|
|
#define RC_CHANNEL_YAW 3
|
|
#define RC_CHANNEL_ARMED 4
|
|
#define RC_CHANNEL_MODE 5
|
|
|
|
float t = NAN; // current step time, s
|
|
float dt; // time delta from previous step, s
|
|
int16_t channels[16]; // raw rc channels
|
|
float controls[16]; // normalized controls in range [-1..1] ([0..1] for throttle)
|
|
Vector gyro; // gyroscope data
|
|
Vector acc; // accelerometer data, m/s/s
|
|
Vector rates; // filtered angular rates, rad/s
|
|
Quaternion attitude; // estimated attitude
|
|
float motors[4]; // normalized motors thrust in range [-1..1]
|
|
|
|
void setup() {
|
|
Serial.begin(SERIAL_BAUDRATE);
|
|
Serial.println("Initializing flix");
|
|
disableBrownOut();
|
|
setupLED();
|
|
setupMotors();
|
|
setLED(true);
|
|
#if WIFI_ENABLED
|
|
setupWiFi();
|
|
#endif
|
|
setupIMU();
|
|
setupRC();
|
|
setLED(false);
|
|
Serial.println("Initializing complete");
|
|
}
|
|
|
|
void loop() {
|
|
readIMU();
|
|
step();
|
|
readRC();
|
|
estimate();
|
|
control();
|
|
sendMotors();
|
|
handleInput();
|
|
#if WIFI_ENABLED
|
|
processMavlink();
|
|
#endif
|
|
logData();
|
|
}
|