mirror of
https://github.com/okalachev/flix.git
synced 2026-09-05 16:00:56 +00:00
Refactor the console subsystem
Rename cli.ino => console.ino. Rename handleInput => handleConsole. Separate console initialization function. Always use usb cdc by default on s3/c3 (no configuration needed).
This commit is contained in:
@@ -21,13 +21,13 @@ jobs:
|
|||||||
- name: Build firmware for ESP32-C3
|
- name: Build firmware for ESP32-C3
|
||||||
run: make BOARD=esp32:esp32:esp32c3
|
run: make BOARD=esp32:esp32:esp32c3
|
||||||
- name: Build firmware for ESP32-S3
|
- name: Build firmware for ESP32-S3
|
||||||
run: make BOARD=esp32:esp32:esp32s3:CDCOnBoot=cdc
|
run: make BOARD=esp32:esp32:esp32s3
|
||||||
- name: Build firmware for ESP32-S3 with QSPI PSRAM
|
- name: Build firmware for ESP32-S3 with QSPI PSRAM
|
||||||
run: make BOARD=esp32:esp32:esp32s3:CDCOnBoot=cdc,PSRAM=enabled EXTRA=--output-dir=flix/build/esp32.esp32.esp32s3.qspi
|
run: make BOARD=esp32:esp32:esp32s3:PSRAM=enabled EXTRA=--output-dir=flix/build/esp32.esp32.esp32s3.qspi
|
||||||
- name: Build firmware for ESP32-S3 with OPI PSRAM
|
- name: Build firmware for ESP32-S3 with OPI PSRAM
|
||||||
run: make BOARD=esp32:esp32:esp32s3:CDCOnBoot=cdc,PSRAM=opi EXTRA=--output-dir=flix/build/esp32.esp32.esp32s3.opi
|
run: make BOARD=esp32:esp32:esp32s3:PSRAM=opi EXTRA=--output-dir=flix/build/esp32.esp32.esp32s3.opi
|
||||||
- name: Build firmware for Flix2
|
- name: Build firmware for Flix2
|
||||||
run: make BOARD=esp32:esp32:esp32s3:FlashSize=4M,CDCOnBoot=cdc,PSRAM=opi EXTRA='--build-property "compiler.cpp.extra_flags=-DFLIX2" --output-dir=flix/build/esp32.esp32.flix2'
|
run: make BOARD=esp32:esp32:esp32s3:PSRAM=opi EXTRA='--build-property "compiler.cpp.extra_flags=-DFLIX2" --output-dir=flix/build/esp32.esp32.flix2'
|
||||||
- name: Upload binaries
|
- name: Upload binaries
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
|
|||||||
Vendored
+3
-3
@@ -18,7 +18,7 @@
|
|||||||
"${workspaceFolder}/.vscode/intellisense.h",
|
"${workspaceFolder}/.vscode/intellisense.h",
|
||||||
"~/.arduino15/packages/esp32/hardware/esp32/3.3.10/cores/esp32/Arduino.h",
|
"~/.arduino15/packages/esp32/hardware/esp32/3.3.10/cores/esp32/Arduino.h",
|
||||||
"~/.arduino15/packages/esp32/hardware/esp32/3.3.10/variants/d1_mini32/pins_arduino.h",
|
"~/.arduino15/packages/esp32/hardware/esp32/3.3.10/variants/d1_mini32/pins_arduino.h",
|
||||||
"${workspaceFolder}/flix/cli.ino",
|
"${workspaceFolder}/flix/console.ino",
|
||||||
"${workspaceFolder}/flix/control.ino",
|
"${workspaceFolder}/flix/control.ino",
|
||||||
"${workspaceFolder}/flix/estimate.ino",
|
"${workspaceFolder}/flix/estimate.ino",
|
||||||
"${workspaceFolder}/flix/flix.ino",
|
"${workspaceFolder}/flix/flix.ino",
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
"~/Library/Arduino15/packages/esp32/hardware/esp32/3.3.10/cores/esp32/Arduino.h",
|
"~/Library/Arduino15/packages/esp32/hardware/esp32/3.3.10/cores/esp32/Arduino.h",
|
||||||
"~/Library/Arduino15/packages/esp32/hardware/esp32/3.3.10/variants/d1_mini32/pins_arduino.h",
|
"~/Library/Arduino15/packages/esp32/hardware/esp32/3.3.10/variants/d1_mini32/pins_arduino.h",
|
||||||
"${workspaceFolder}/flix/flix.ino",
|
"${workspaceFolder}/flix/flix.ino",
|
||||||
"${workspaceFolder}/flix/cli.ino",
|
"${workspaceFolder}/flix/console.ino",
|
||||||
"${workspaceFolder}/flix/control.ino",
|
"${workspaceFolder}/flix/control.ino",
|
||||||
"${workspaceFolder}/flix/estimate.ino",
|
"${workspaceFolder}/flix/estimate.ino",
|
||||||
"${workspaceFolder}/flix/imu.ino",
|
"${workspaceFolder}/flix/imu.ino",
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
"${workspaceFolder}/.vscode/intellisense.h",
|
"${workspaceFolder}/.vscode/intellisense.h",
|
||||||
"~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/3.3.10/cores/esp32/Arduino.h",
|
"~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/3.3.10/cores/esp32/Arduino.h",
|
||||||
"~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/3.3.10/variants/d1_mini32/pins_arduino.h",
|
"~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/3.3.10/variants/d1_mini32/pins_arduino.h",
|
||||||
"${workspaceFolder}/flix/cli.ino",
|
"${workspaceFolder}/flix/console.ino",
|
||||||
"${workspaceFolder}/flix/control.ino",
|
"${workspaceFolder}/flix/control.ino",
|
||||||
"${workspaceFolder}/flix/estimate.ino",
|
"${workspaceFolder}/flix/estimate.ino",
|
||||||
"${workspaceFolder}/flix/flix.ino",
|
"${workspaceFolder}/flix/flix.ino",
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ Firmware source files are located in `flix` directory.
|
|||||||
* [`control.ino`](../flix/control.ino) — control subsystem, three-dimensional two-level cascade PID controller.
|
* [`control.ino`](../flix/control.ino) — control subsystem, three-dimensional two-level cascade PID controller.
|
||||||
* [`motors.ino`](../flix/motors.ino) — PWM motor output control.
|
* [`motors.ino`](../flix/motors.ino) — PWM motor output control.
|
||||||
* [`mavlink.ino`](../flix/mavlink.ino) — interaction with QGroundControl or [pyflix](../tools/pyflix) via MAVLink protocol.
|
* [`mavlink.ino`](../flix/mavlink.ino) — interaction with QGroundControl or [pyflix](../tools/pyflix) via MAVLink protocol.
|
||||||
* [`cli.ino`](../flix/cli.ino) — serial and MAVLink console.
|
* [`console.ino`](../flix/console.ino) — serial and MAVLink console.
|
||||||
|
|
||||||
Utility files:
|
Utility files:
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ To write into the console, `print()` function is used. This function sends data
|
|||||||
print("Test value: %.2f\n", testValue);
|
print("Test value: %.2f\n", testValue);
|
||||||
```
|
```
|
||||||
|
|
||||||
In order to add a console command, modify the `doCommand()` function in `cli.ino` file.
|
In order to add a console command, modify the `doCommand()` function in `console.ino` file.
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> Avoid using delays in in-flight commands, it will **crash** the drone! (The design is one-threaded.)
|
> Avoid using delays in in-flight commands, it will **crash** the drone! (The design is one-threaded.)
|
||||||
|
|||||||
+2
-2
@@ -54,7 +54,7 @@ Beginners can [download the sources as a ZIP archive](https://github.com/okalach
|
|||||||
* `MAVLink`, version 2.0.25.
|
* `MAVLink`, version 2.0.25.
|
||||||
5. Open the `flix/flix.ino` sketch from downloaded firmware sources in Arduino IDE.
|
5. Open the `flix/flix.ino` sketch from downloaded firmware sources in Arduino IDE.
|
||||||
6. Connect your ESP32 board to the computer and choose correct board type in Arduino IDE (*WEMOS D1 MINI ESP32* for ESP32 Mini, *ESP32S3 Dev Module* for ESP32-S3 Super Mini) and the port.
|
6. Connect your ESP32 board to the computer and choose correct board type in Arduino IDE (*WEMOS D1 MINI ESP32* for ESP32 Mini, *ESP32S3 Dev Module* for ESP32-S3 Super Mini) and the port.
|
||||||
7. Set *Tools* ⇒ *Core Debug Level* to *Error* to see the errors in the serial console. Set *Tools* ⇒ *USB CDC on Boot* to *Enabled* for ESP32-S3/ESP32-C3 boards.
|
7. Set *Tools* ⇒ *Core Debug Level* to *Error* to see the errors in the serial console.
|
||||||
8. [Build and upload](https://docs.arduino.cc/software/ide-v2/tutorials/getting-started/ide-v2-uploading-a-sketch) the firmware using Arduino IDE.
|
8. [Build and upload](https://docs.arduino.cc/software/ide-v2/tutorials/getting-started/ide-v2-uploading-a-sketch) the firmware using Arduino IDE.
|
||||||
|
|
||||||
#### Command line (Windows, Linux, macOS)
|
#### Command line (Windows, Linux, macOS)
|
||||||
@@ -89,7 +89,7 @@ Beginners can [download the sources as a ZIP archive](https://github.com/okalach
|
|||||||
For ESP32-S3/ESP32-C3 boards, set the appropriate [FQBN](https://docs.arduino.cc/arduino-cli/FAQ/#whats-the-fqbn-string) using `BOARD` parameter:
|
For ESP32-S3/ESP32-C3 boards, set the appropriate [FQBN](https://docs.arduino.cc/arduino-cli/FAQ/#whats-the-fqbn-string) using `BOARD` parameter:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make BOARD=esp32:esp32:esp32s3:FlashSize=4M,CDCOnBoot=cdc upload
|
make BOARD=esp32:esp32:esp32s3 upload
|
||||||
```
|
```
|
||||||
|
|
||||||
See other available Make commands in [Makefile](../Makefile).
|
See other available Make commands in [Makefile](../Makefile).
|
||||||
|
|||||||
@@ -56,6 +56,19 @@ const char* motd =
|
|||||||
"reset - reset drone's state\n"
|
"reset - reset drone's state\n"
|
||||||
"reboot - reboot the drone\n";
|
"reboot - reboot the drone\n";
|
||||||
|
|
||||||
|
// Always redirect Serial to USB on ESP32-S3/ESP32-C3
|
||||||
|
#if SOC_USB_SERIAL_JTAG_SUPPORTED && ARDUINO_USB_MODE
|
||||||
|
#if !ARDUINO_USB_CDC_ON_BOOT
|
||||||
|
HWCDC HWCDCSerial;
|
||||||
|
#endif
|
||||||
|
#undef Serial
|
||||||
|
#define Serial HWCDCSerial
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void setupConsole() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
}
|
||||||
|
|
||||||
void print(const char* format, ...) {
|
void print(const char* format, ...) {
|
||||||
char buf[3000];
|
char buf[3000];
|
||||||
va_list args;
|
va_list args;
|
||||||
@@ -70,7 +83,7 @@ void pause(float duration) {
|
|||||||
float start = t;
|
float start = t;
|
||||||
while (t - start < duration) {
|
while (t - start < duration) {
|
||||||
step();
|
step();
|
||||||
handleInput();
|
handleConsole();
|
||||||
processMavlink();
|
processMavlink();
|
||||||
delay(50);
|
delay(50);
|
||||||
}
|
}
|
||||||
@@ -199,7 +212,7 @@ void doCommand(String str, bool echo = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleInput() {
|
void handleConsole() {
|
||||||
static bool showMotd = true;
|
static bool showMotd = true;
|
||||||
static String input;
|
static String input;
|
||||||
|
|
||||||
+2
-2
@@ -16,7 +16,7 @@ extern bool landed;
|
|||||||
extern float motors[4];
|
extern float motors[4];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
setupConsole();
|
||||||
print("Initializing Flix\n");
|
print("Initializing Flix\n");
|
||||||
setupParameters();
|
setupParameters();
|
||||||
setupPower();
|
setupPower();
|
||||||
@@ -37,7 +37,7 @@ void loop() {
|
|||||||
estimate();
|
estimate();
|
||||||
control();
|
control();
|
||||||
sendMotors();
|
sendMotors();
|
||||||
handleInput();
|
handleConsole();
|
||||||
processMavlink();
|
processMavlink();
|
||||||
readVoltage();
|
readVoltage();
|
||||||
logData();
|
logData();
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ void testMotor(int, float);
|
|||||||
void print(const char* format, ...);
|
void print(const char* format, ...);
|
||||||
void pause(float duration);
|
void pause(float duration);
|
||||||
void doCommand(String str, bool echo);
|
void doCommand(String str, bool echo);
|
||||||
void handleInput();
|
void handleConsole();
|
||||||
void setupRC();
|
void setupRC();
|
||||||
void normalizeRC();
|
void normalizeRC();
|
||||||
void calibrateRC();
|
void calibrateRC();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "flix.h"
|
#include "flix.h"
|
||||||
|
|
||||||
#include "cli.ino"
|
#include "console.ino"
|
||||||
#include "control.ino"
|
#include "control.ino"
|
||||||
#include "estimate.ino"
|
#include "estimate.ino"
|
||||||
#include "safety.ino"
|
#include "safety.ino"
|
||||||
@@ -83,7 +83,7 @@ public:
|
|||||||
attitude.setYaw(this->model->WorldPose().Yaw());
|
attitude.setYaw(this->model->WorldPose().Yaw());
|
||||||
|
|
||||||
control();
|
control();
|
||||||
handleInput();
|
handleConsole();
|
||||||
processMavlink();
|
processMavlink();
|
||||||
|
|
||||||
applyMotorForces();
|
applyMotorForces();
|
||||||
|
|||||||
Reference in New Issue
Block a user