mirror of
https://github.com/okalachev/flix.git
synced 2026-08-16 00:38:56 +00:00
Compare commits
35
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74b082957e | ||
|
|
4582942919 | ||
|
|
df14a5678f | ||
|
|
81721abf91 | ||
|
|
1276d220a6 | ||
|
|
79c7e282cb | ||
|
|
f031cf3046 | ||
|
|
60f389a289 | ||
|
|
5c24ce113d | ||
|
|
b58c2e7c7a | ||
|
|
2137730a8d | ||
|
|
309d2d2e29 | ||
|
|
0c91ccfab5 | ||
|
|
26d53d4ce1 | ||
|
|
0366b24ff3 | ||
|
|
3de4e9ab9a | ||
|
|
f1e024b19a | ||
|
|
d9be26c5be | ||
|
|
f8a4cbfee1 | ||
|
|
658040e652 | ||
|
|
70459df8dd | ||
|
|
61213bb8a1 | ||
|
|
d48b71fb1a | ||
|
|
8917849711 | ||
|
|
1cdc7a8641 | ||
|
|
0439407d76 | ||
|
|
c2005a2ca2 | ||
|
|
6a804862da | ||
|
|
590bfe10b0 | ||
|
|
70af1a1c09 | ||
|
|
9e9dafbdfb | ||
|
|
86a4418813 | ||
|
|
d64bf24c6d | ||
|
|
fabd5e072d | ||
|
|
1ae85ff118 |
@@ -27,6 +27,8 @@ jobs:
|
|||||||
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
|
run: make BOARD=esp32:esp32:esp32s3
|
||||||
|
- name: Build espnow-proxy
|
||||||
|
run: arduino-cli compile --fqbn esp32:esp32:esp32 tools/espnow-proxy
|
||||||
- name: Check c_cpp_properties.json
|
- name: Check c_cpp_properties.json
|
||||||
run: tools/check_c_cpp_properties.py
|
run: tools/check_c_cpp_properties.py
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
BOARD = esp32:esp32:d1_mini32:DebugLevel=error
|
BOARD = esp32:esp32:d1_mini32
|
||||||
PORT := $(strip $(wildcard /dev/serial/by-id/usb-Silicon_Labs_CP21* /dev/serial/by-id/usb-1a86_USB_Single_Serial_* /dev/cu.usbserial-* /dev/cu.usbmodem*))
|
PORT := $(strip $(wildcard /dev/serial/by-id/usb-Silicon_Labs_CP21* /dev/serial/by-id/usb-1a86_USB_Single_Serial_* /dev/cu.usbserial-* /dev/cu.usbmodem*))
|
||||||
|
|
||||||
export ARDUINO_NETWORK_CONNECTION_TIMEOUT := 1h
|
export ARDUINO_NETWORK_CONNECTION_TIMEOUT := 1h
|
||||||
|
|
||||||
build: .core .libs
|
build: .core .libs
|
||||||
arduino-cli compile --fqbn $(BOARD) flix
|
arduino-cli compile --fqbn $(BOARD) --build-property "build.core_debug_level=1" flix
|
||||||
|
|
||||||
upload: build
|
upload: build
|
||||||
arduino-cli upload --fqbn $(BOARD) -p "$(PORT)" flix
|
arduino-cli upload --fqbn $(BOARD) -p "$(PORT)" flix
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ Additional articles:
|
|||||||
|*Boost converter (optional, for more stable power supply)*|*5V output*|<img src="docs/img/buck-boost.jpg" width=100>|1|
|
|*Boost converter (optional, for more stable power supply)*|*5V output*|<img src="docs/img/buck-boost.jpg" width=100>|1|
|
||||||
|Motor|8520 3.7V brushed motor.<br>Motor with exact 3.7V voltage is needed, not ranged working voltage (3.7V — 6V).<br>Make sure the motor shaft diameter and propeller hole diameter match!|<img src="docs/img/motor.jpeg" width=100>|4|
|
|Motor|8520 3.7V brushed motor.<br>Motor with exact 3.7V voltage is needed, not ranged working voltage (3.7V — 6V).<br>Make sure the motor shaft diameter and propeller hole diameter match!|<img src="docs/img/motor.jpeg" width=100>|4|
|
||||||
|Propeller|55 mm or 65 mm|<img src="docs/img/prop.jpg" width=100>|4|
|
|Propeller|55 mm or 65 mm|<img src="docs/img/prop.jpg" width=100>|4|
|
||||||
|MOSFET (transistor)|100N03A or [analog](https://t.me/opensourcequadcopter/33)|<img src="docs/img/100n03a.jpg" width=100>|4|
|
|MOSFET (transistor)|UMW 100N03A or [analog](https://t.me/opensourcequadcopter/33).<br>Warning: don't use KIA 100N03A or other manufacturers, they might not work!|<img src="docs/img/100n03a.jpg" width=100>|4|
|
||||||
|Pull-down resistor<br>Voltage measurement resistor|10 kΩ|<img src="docs/img/resistor10k.jpg" width=100>|6|
|
|Pull-down resistor<br>Voltage measurement resistor|10 kΩ|<img src="docs/img/resistor10k.jpg" width=100>|6|
|
||||||
|3.7V Li-Po battery|LW 952540 (or any compatible by the size).<br>Make sure the battery has enough discharge rate — 25C or more!|<img src="docs/img/battery.jpg" width=100>|1|
|
|3.7V Li-Po battery|LW 952540 (or any compatible by the size).<br>Make sure the battery has enough discharge rate — 25C or more!|<img src="docs/img/battery.jpg" width=100>|1|
|
||||||
|Battery connector cable|MX2.0 2P female|<img src="docs/img/mx.png" width=100>|1|
|
|Battery connector cable|MX2.0 2P female|<img src="docs/img/mx.png" width=100>|1|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
+31
-11
@@ -25,7 +25,7 @@ You can build and upload the firmware using either **Arduino IDE** (easier for b
|
|||||||
* `FlixPeriph`, the latest version.
|
* `FlixPeriph`, the latest version.
|
||||||
* `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) 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. Set *Tools* ⇒ *USB CDC on Boot* to *Enabled* for ESP32-S3/ESP32-C3 boards.
|
||||||
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.
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ You can build and upload the firmware using either **Arduino IDE** (easier for b
|
|||||||
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:DebugLevel=error,FlashSize=4M,CDCOnBoot=cdc upload
|
make BOARD=esp32:esp32:esp32s3:FlashSize=4M,CDCOnBoot=cdc upload
|
||||||
```
|
```
|
||||||
|
|
||||||
See other available Make commands in [Makefile](../Makefile).
|
See other available Make commands in [Makefile](../Makefile).
|
||||||
@@ -76,8 +76,25 @@ See other available Make commands in [Makefile](../Makefile).
|
|||||||
In case if using different IMU model than MPU9250, change `imu` variable declaration in the `imu.ino`:
|
In case if using different IMU model than MPU9250, change `imu` variable declaration in the `imu.ino`:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
ICM20948 imu(SPI); // For ICM-20948
|
ICM20948 imu(SPI); // For ICM-20948 via SPI
|
||||||
MPU6050 imu(Wire); // For MPU-6050
|
// or
|
||||||
|
MPU6050 imu(Wire); // For MPU-6050 via I2C
|
||||||
|
```
|
||||||
|
|
||||||
|
If using non-default SPI pins, pass SCK, MISO, and MOSI pin numbers to `SPI.begin` call and SS pin to `imu` constructor like that:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
ICM20948(SPI, <SS>);
|
||||||
|
// ...
|
||||||
|
SPI.begin(<SCK>, <MISO>, <MOSI>);
|
||||||
|
imu.begin();
|
||||||
|
```
|
||||||
|
|
||||||
|
If using non-default I2C pins, pass SDA and SCL pin numbers to `Wire.setPins` call like that:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
Wire.begin(<SDA>, <SCL>);
|
||||||
|
imu.begin();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Connect using QGroundControl
|
### Connect using QGroundControl
|
||||||
@@ -105,7 +122,7 @@ To access the console using serial port:
|
|||||||
To access the console using QGroundControl:
|
To access the console using QGroundControl:
|
||||||
|
|
||||||
1. Connect to the drone using QGroundControl app.
|
1. Connect to the drone using QGroundControl app.
|
||||||
2. Go to the QGroundControl menu ⇒ *Vehicle Setup* ⇒ *Analyze Tools* ⇒ *MAVLink Console*.
|
2. Go to the QGroundControl menu ⇒ *Analyze Tools* ⇒ *MAVLink Console*.
|
||||||
|
|
||||||
<img src="img/cli.png" width="400">
|
<img src="img/cli.png" width="400">
|
||||||
|
|
||||||
@@ -198,7 +215,7 @@ After this setup, you should see the battery voltage in QGroundControl top panel
|
|||||||
|
|
||||||
## Setup remote control
|
## Setup remote control
|
||||||
|
|
||||||
There are several ways to control the drone's flight: using **smartphone** (Wi-Fi), using **SBUS remote control**, or using **USB remote control** (Wi-Fi).
|
There are several ways to control the drone's flight: using **smartphone** (Wi-Fi), using **SBUS remote control**, or using **USB remote control** (Wi-Fi/ESP-NOW).
|
||||||
|
|
||||||
### Control with a smartphone
|
### Control with a smartphone
|
||||||
|
|
||||||
@@ -243,7 +260,7 @@ If your drone doesn't have RC receiver installed, you can use USB remote control
|
|||||||
3. Power up the drone.
|
3. Power up the drone.
|
||||||
4. Connect your computer to the appeared `flix` Wi-Fi network (password: `flixwifi`).
|
4. Connect your computer to the appeared `flix` Wi-Fi network (password: `flixwifi`).
|
||||||
5. Launch QGroundControl app. It should connect and begin showing the drone's telemetry automatically.
|
5. Launch QGroundControl app. It should connect and begin showing the drone's telemetry automatically.
|
||||||
6. Go the the QGroundControl menu ⇒ *Vehicle Setup* ⇒ *Joystick*. Calibrate you USB remote control there.
|
6. Go to the QGroundControl menu ⇒ *Vehicle Setup* ⇒ *Joystick*. Calibrate your USB remote control there.
|
||||||
7. Use the USB remote control to fly the drone!
|
7. Use the USB remote control to fly the drone!
|
||||||
|
|
||||||
## Flight
|
## Flight
|
||||||
@@ -333,13 +350,13 @@ To setup ESP-NOW communication:
|
|||||||
|
|
||||||
1. Flash the second ESP32 board with ESP-NOW proxy sketch: [`tools/espnow-proxy/espnow-proxy.ino`](../tools/espnow-proxy/espnow-proxy.ino). Use Arduino IDE or command line: `make upload_proxy`.
|
1. Flash the second ESP32 board with ESP-NOW proxy sketch: [`tools/espnow-proxy/espnow-proxy.ino`](../tools/espnow-proxy/espnow-proxy.ino). Use Arduino IDE or command line: `make upload_proxy`.
|
||||||
|
|
||||||
2. Open Serial Monitor or use `make monitor` command. The ESP32 will print its MAC address and generated encryption key, for example:
|
2. Open Serial Monitor in Arduino IDE or use `make monitor` command. The ESP32 will print its MAC address and generated encryption key, for example:
|
||||||
|
|
||||||
```
|
```
|
||||||
espnow 7a:c8:e3:eb:bf:e9 &PiuSysxP9+$L&5E
|
espnow 7a:c8:e3:eb:bf:e9 &PiuSysxP9+$L&5E
|
||||||
```
|
```
|
||||||
|
|
||||||
Run this line as a console command on each drone you want to bind to this proxy board. [The maximum number](https://github.com/espressif/esp-idf/blob/e95cab4be8fd293e3f3323181e7a2280874da6f7/components/esp_wifi/include/esp_now.h#L32-L33) of simultaneously connected drones is 20 (unencrypted) io 6 (encrypted).
|
Run this line as a console command on each drone you want to bind to this proxy board. [The maximum number](https://github.com/espressif/esp-idf/blob/e95cab4be8fd293e3f3323181e7a2280874da6f7/components/esp_wifi/include/esp_now.h#L32-L33) of simultaneously connected drones is 20 (unencrypted) or 6 (encrypted).
|
||||||
|
|
||||||
3. Set the `WIFI_MODE` parameter to `3` on the drone:
|
3. Set the `WIFI_MODE` parameter to `3` on the drone:
|
||||||
|
|
||||||
@@ -352,11 +369,14 @@ To setup ESP-NOW communication:
|
|||||||
* Type: Serial.
|
* Type: Serial.
|
||||||
* Serial Port: choose the port of the proxy ESP32 board, e. g. `/dev/cu.usbserial-0001`.
|
* Serial Port: choose the port of the proxy ESP32 board, e. g. `/dev/cu.usbserial-0001`.
|
||||||
* Baud Rate: 115200.
|
* Baud Rate: 115200.
|
||||||
5. Click *Save*. QGroundControl should connect to the drone using ESP-NOW and begin showing the telemetry.
|
5. Click *Save*, click *Connect*. QGroundControl should connect to the drone using ESP-NOW and begin showing the telemetry.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> Make sure Arduino IDE is not running when using ESP-NOW proxy board, as it may block it.
|
||||||
|
|
||||||
## Flight log
|
## Flight log
|
||||||
|
|
||||||
After the flight, you can download the flight log for analysis wirelessly. Use the following command on your computer for that:
|
After the flight, you can download the flight log wirelessly for analysis. Use the following command on your computer for that:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make log
|
make log
|
||||||
|
|||||||
@@ -4,6 +4,15 @@ This page contains user-built drones based on the Flix project. Publish your pro
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Author: Alican Erüst.<br>
|
||||||
|
Description: QX95 mm frame, 55 mm propellers, 3.7 V 25C 1050 mAh LiPo battery, MPU6050 IMU, Logitech F310 gamepad controller, with a total quadcopter weight of 66 g.
|
||||||
|
|
||||||
|
<img src="img/user/alicanerus/1.jpg" height=200> <img src="img/user/alicanerus/2.jpg" height=200> <img src="img/user/alicanerus/3.jpg" height=200>
|
||||||
|
|
||||||
|
[Flight video](https://drive.google.com/file/d/1k0WeWTKnCAfaugkX7LcmNxsUuq79RL8Z/view?usp=sharing).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
Author: [Неруш Михаил](https://t.me/NerushMV).<br>
|
Author: [Неруш Михаил](https://t.me/NerushMV).<br>
|
||||||
Description: custom frame made of 4 mm plywood, 8520 brushed motors, 75 mm propellers, MPU-6500. FlySky FS-i6X with ESP32-based adapter for ESP-NOW communication (using PPM output).<br>
|
Description: custom frame made of 4 mm plywood, 8520 brushed motors, 75 mm propellers, MPU-6500. FlySky FS-i6X with ESP32-based adapter for ESP-NOW communication (using PPM output).<br>
|
||||||
Sources and materials: [link](https://drive.google.com/drive/folders/1uWiDcuorLrtVs_IIR7Y13omij-7Q1nx8).
|
Sources and materials: [link](https://drive.google.com/drive/folders/1uWiDcuorLrtVs_IIR7Y13omij-7Q1nx8).
|
||||||
|
|||||||
+5
-5
@@ -50,8 +50,8 @@ const char* motd =
|
|||||||
"sta <ssid> <password> - configure Wi-Fi client mode\n"
|
"sta <ssid> <password> - configure Wi-Fi client mode\n"
|
||||||
"espnow <mac> [<key>] - configure ESP-NOW peer\n"
|
"espnow <mac> [<key>] - configure ESP-NOW peer\n"
|
||||||
"mot - show motor output\n"
|
"mot - show motor output\n"
|
||||||
|
"mfr/mfl/mrr/mrl [<thrust>] - test motor (remove props)\n"
|
||||||
"log [dump] - print log header [and data]\n"
|
"log [dump] - print log header [and data]\n"
|
||||||
"mfr, mfl, mrr, mrl - test motor (remove props)\n"
|
|
||||||
"log - show log info\n"
|
"log - show log info\n"
|
||||||
"log header - show log header\n"
|
"log header - show log header\n"
|
||||||
"log reset - reset log\n"
|
"log reset - reset log\n"
|
||||||
@@ -176,13 +176,13 @@ void doCommand(String str, bool echo = false) {
|
|||||||
} else if (command == "ca") {
|
} else if (command == "ca") {
|
||||||
calibrateAccel();
|
calibrateAccel();
|
||||||
} else if (command == "mfr") {
|
} else if (command == "mfr") {
|
||||||
testMotor(MOTOR_FRONT_RIGHT);
|
testMotor(MOTOR_FRONT_RIGHT, arg0.isEmpty() ? 0.2 : arg0.toFloat());
|
||||||
} else if (command == "mfl") {
|
} else if (command == "mfl") {
|
||||||
testMotor(MOTOR_FRONT_LEFT);
|
testMotor(MOTOR_FRONT_LEFT, arg0.isEmpty() ? 0.2 : arg0.toFloat());
|
||||||
} else if (command == "mrr") {
|
} else if (command == "mrr") {
|
||||||
testMotor(MOTOR_REAR_RIGHT);
|
testMotor(MOTOR_REAR_RIGHT, arg0.isEmpty() ? 0.2 : arg0.toFloat());
|
||||||
} else if (command == "mrl") {
|
} else if (command == "mrl") {
|
||||||
testMotor(MOTOR_REAR_LEFT);
|
testMotor(MOTOR_REAR_LEFT, arg0.isEmpty() ? 0.2 : arg0.toFloat());
|
||||||
} else if (command == "sys") {
|
} else if (command == "sys") {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
print("Chip: %s\n", ESP.getChipModel());
|
print("Chip: %s\n", ESP.getChipModel());
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ bool landed;
|
|||||||
float accWeight = 0.003;
|
float accWeight = 0.003;
|
||||||
float levelWeight = 0.0002;
|
float levelWeight = 0.0002;
|
||||||
LowPassFilter<Vector> ratesFilter(0.2); // cutoff frequency ~ 40 Hz
|
LowPassFilter<Vector> ratesFilter(0.2); // cutoff frequency ~ 40 Hz
|
||||||
NotchFilter<Vector> ratesNotch(382, 40);
|
NotchFilter<Vector> ratesNotch(382, 0);
|
||||||
|
|
||||||
void setupEstimate() {
|
void setupEstimate() {
|
||||||
print("Setup estimation\n");
|
print("Setup estimation\n");
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int logMemory = 0; // 0 - RAM, 1 - PSRAM, -1 - disabled
|
int logMemory = -1; // 0 - RAM, 1 - PSRAM, -1 - disabled
|
||||||
float logUsage = 0.5; // fraction of free memory to use for log
|
float logUsage = 0.5; // fraction of free memory to use for log
|
||||||
|
|
||||||
struct LogValue {
|
struct LogValue {
|
||||||
|
|||||||
+13
-7
@@ -223,18 +223,24 @@ void handleMavlink(const void *_msg) {
|
|||||||
mavlink_msg_set_attitude_target_decode(&msg, &m);
|
mavlink_msg_set_attitude_target_decode(&msg, &m);
|
||||||
if (m.target_system && m.target_system != mavlinkSysId) return;
|
if (m.target_system && m.target_system != mavlinkSysId) return;
|
||||||
|
|
||||||
// copy attitude, rates and thrust targets
|
if (!(m.type_mask & ATTITUDE_TARGET_TYPEMASK_ATTITUDE_IGNORE)) {
|
||||||
ratesTarget.x = m.body_roll_rate;
|
// Attitude control
|
||||||
ratesTarget.y = -m.body_pitch_rate; // convert to flu
|
|
||||||
ratesTarget.z = -m.body_yaw_rate;
|
|
||||||
attitudeTarget.w = m.q[0];
|
attitudeTarget.w = m.q[0];
|
||||||
attitudeTarget.x = m.q[1];
|
attitudeTarget.x = m.q[1];
|
||||||
attitudeTarget.y = -m.q[2];
|
attitudeTarget.y = -m.q[2];
|
||||||
attitudeTarget.z = -m.q[3];
|
attitudeTarget.z = -m.q[3];
|
||||||
thrustTarget = m.thrust;
|
ratesExtra.x = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_ROLL_RATE_IGNORE ? 0 : m.body_roll_rate;
|
||||||
ratesExtra = Vector(0, 0, 0);
|
ratesExtra.y = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_PITCH_RATE_IGNORE ? 0 : -m.body_pitch_rate; // convert to flu
|
||||||
|
ratesExtra.z = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_YAW_RATE_IGNORE ? 0 : -m.body_yaw_rate;
|
||||||
|
} else {
|
||||||
|
// Rates control
|
||||||
|
attitudeTarget.invalidate();
|
||||||
|
ratesTarget.x = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_ROLL_RATE_IGNORE ? ratesTarget.x : m.body_roll_rate;
|
||||||
|
ratesTarget.y = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_PITCH_RATE_IGNORE ? ratesTarget.y : -m.body_pitch_rate;
|
||||||
|
ratesTarget.z = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_YAW_RATE_IGNORE ? ratesTarget.z : -m.body_yaw_rate;
|
||||||
|
}
|
||||||
|
|
||||||
if (m.type_mask & ATTITUDE_TARGET_TYPEMASK_ATTITUDE_IGNORE) attitudeTarget.invalidate();
|
thrustTarget = valid(m.thrust) ? m.thrust : thrustTarget;
|
||||||
armed = m.thrust > 0;
|
armed = m.thrust > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
float motors[4]; // normalized motor thrusts in range [0..1]
|
float motors[4]; // normalized motor thrusts in range [0..1]
|
||||||
|
|
||||||
int motorPins[4] = {12, 13, 14, 15}; // default pin numbers
|
int motorPins[4] = {-1, -1, -1, -1}; // default pin numbers
|
||||||
int pwmFrequency = 78000;
|
int pwmFrequency = 78000;
|
||||||
int pwmResolution = 10;
|
int pwmResolution = 10;
|
||||||
int pwmStop = 0;
|
int pwmStop = 0;
|
||||||
@@ -51,9 +51,9 @@ bool motorsActive() {
|
|||||||
return motors[0] != 0 || motors[1] != 0 || motors[2] != 0 || motors[3] != 0;
|
return motors[0] != 0 || motors[1] != 0 || motors[2] != 0 || motors[3] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testMotor(int n) {
|
void testMotor(int n, float thrust) {
|
||||||
print("Testing motor %d\n", n);
|
print("Testing motor %d\n", n);
|
||||||
motors[n] = 0.2;
|
motors[n] = thrust;
|
||||||
delay(50); // ESP32 may need to wait until the end of the current cycle to change duty https://github.com/espressif/arduino-esp32/issues/5306
|
delay(50); // ESP32 may need to wait until the end of the current cycle to change duty https://github.com/espressif/arduino-esp32/issues/5306
|
||||||
sendMotors();
|
sendMotors();
|
||||||
pause(3);
|
pause(3);
|
||||||
|
|||||||
+2
-1
@@ -10,7 +10,7 @@ extern int channelZero[16], channelMax[16];
|
|||||||
extern int rollChannel, pitchChannel, throttleChannel, yawChannel, armedChannel, modeChannel;
|
extern int rollChannel, pitchChannel, throttleChannel, yawChannel, armedChannel, modeChannel;
|
||||||
extern int rcRxPin, voltagePin;
|
extern int rcRxPin, voltagePin;
|
||||||
extern int wifiMode, wifiLongRange, udpLocalPort, udpRemotePort, espnowChannel;
|
extern int wifiMode, wifiLongRange, udpLocalPort, udpRemotePort, espnowChannel;
|
||||||
extern float rcLossTimeout, descendTime;
|
extern float rcLossTimeout, descendTime, disarmTilt;
|
||||||
extern float voltageScale;
|
extern float voltageScale;
|
||||||
extern LowPassFilter<float> voltageFilter;
|
extern LowPassFilter<float> voltageFilter;
|
||||||
|
|
||||||
@@ -146,6 +146,7 @@ Parameter parameters[] = {
|
|||||||
// safety
|
// safety
|
||||||
{"SF_RC_LOSS_TIME", &rcLossTimeout},
|
{"SF_RC_LOSS_TIME", &rcLossTimeout},
|
||||||
{"SF_DESCEND_TIME", &descendTime},
|
{"SF_DESCEND_TIME", &descendTime},
|
||||||
|
{"SF_DISARM_TILT", &disarmTilt}
|
||||||
};
|
};
|
||||||
|
|
||||||
void setupParameters() {
|
void setupParameters() {
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
float voltage = NAN;
|
float voltage = NAN;
|
||||||
LowPassFilter<float> voltageFilter(0.2);
|
LowPassFilter<float> voltageFilter(1);
|
||||||
int voltagePin = -1;
|
int voltagePin = -1;
|
||||||
float voltageScale = 2;
|
float voltageScale = 2;
|
||||||
|
|
||||||
|
|||||||
+15
-1
@@ -8,10 +8,12 @@ extern float controlRoll, controlPitch, controlThrottle, controlYaw;
|
|||||||
|
|
||||||
float rcLossTimeout = 1;
|
float rcLossTimeout = 1;
|
||||||
float descendTime = 10;
|
float descendTime = 10;
|
||||||
|
float disarmTilt = radians(120);
|
||||||
|
|
||||||
void failsafe() {
|
void failsafe() {
|
||||||
rcLossFailsafe();
|
rcLossFailsafe();
|
||||||
autoFailsafe();
|
autoFailsafe();
|
||||||
|
tiltFailsafe();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RC loss failsafe
|
// RC loss failsafe
|
||||||
@@ -36,7 +38,7 @@ void descend() {
|
|||||||
// Allow pilot to interrupt automatic flight
|
// Allow pilot to interrupt automatic flight
|
||||||
void autoFailsafe() {
|
void autoFailsafe() {
|
||||||
static float roll, pitch, yaw, throttle;
|
static float roll, pitch, yaw, throttle;
|
||||||
if (roll != controlRoll || pitch != controlPitch || yaw != controlYaw || abs(throttle - controlThrottle) > 0.05) {
|
if (abs(roll - controlRoll) > 0.05 || abs(pitch - controlPitch) > 0.05 || abs(yaw - controlYaw) > 0.05 || abs(throttle - controlThrottle) > 0.05) {
|
||||||
// controls changed and mode switch is not configured
|
// controls changed and mode switch is not configured
|
||||||
if (mode == AUTO && invalid(controlMode)) mode = STAB; // regain control by the pilot
|
if (mode == AUTO && invalid(controlMode)) mode = STAB; // regain control by the pilot
|
||||||
}
|
}
|
||||||
@@ -45,3 +47,15 @@ void autoFailsafe() {
|
|||||||
yaw = controlYaw;
|
yaw = controlYaw;
|
||||||
throttle = controlThrottle;
|
throttle = controlThrottle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disarm if tilted too much
|
||||||
|
void tiltFailsafe() {
|
||||||
|
if (!armed) return;
|
||||||
|
if (mode != STAB) return;
|
||||||
|
|
||||||
|
Vector up = Quaternion::rotateVector(Vector(0, 0, 1), attitude);
|
||||||
|
float tilt = acos(up.z);
|
||||||
|
if (disarmTilt && tilt > disarmTilt) {
|
||||||
|
armed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -58,7 +58,7 @@ void sendWiFi(const uint8_t *buf, int len) {
|
|||||||
espnow.write(buf, len);
|
espnow.write(buf, len);
|
||||||
|
|
||||||
static Rate discovery(2);
|
static Rate discovery(2);
|
||||||
if (discovery) espnowBroadcast.write((const uint8_t *)"flix", 4); // broadcast message to help finding this device
|
if (espnow.isEncrypted() && discovery) espnowBroadcast.write((const uint8_t *)"flix", 4); // broadcast message to help finding this device
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ void printWiFiInfo() {
|
|||||||
print("MAC: %s\n", WiFi.softAPmacAddress().c_str());
|
print("MAC: %s\n", WiFi.softAPmacAddress().c_str());
|
||||||
print("Peer MAC: %s\n", MacAddress(espnow.addr()).toString().c_str());
|
print("Peer MAC: %s\n", MacAddress(espnow.addr()).toString().c_str());
|
||||||
print("Encrypted: %d\n", espnow.isEncrypted());
|
print("Encrypted: %d\n", espnow.isEncrypted());
|
||||||
print("Channel: %d\n", espnow.getChannel());
|
print("Channel: %d\n", WiFi.channel());
|
||||||
print("Lost packets: %d\n", espnow.lost);
|
print("Lost packets: %d\n", espnow.lost);
|
||||||
} else if (WiFi.getMode() == WIFI_MODE_AP) {
|
} else if (WiFi.getMode() == WIFI_MODE_AP) {
|
||||||
print("Mode: Access Point (AP)\n");
|
print("Mode: Access Point (AP)\n");
|
||||||
|
|||||||
@@ -20,6 +20,10 @@
|
|||||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||||
|
|
||||||
|
#define MALLOC_CAP_SPIRAM (1<<10)
|
||||||
|
#define MALLOC_CAP_8BIT (1<<2)
|
||||||
|
#define ESP_NOW_MAX_DATA_LEN_V2 1470
|
||||||
|
|
||||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||||
template<typename T> T max(T a, T b) { return a > b ? a : b; }
|
template<typename T> T max(T a, T b) { return a > b ? a : b; }
|
||||||
template<typename T> T min(T a, T b) { return a < b ? a : b; }
|
template<typename T> T min(T a, T b) { return a < b ? a : b; }
|
||||||
@@ -157,6 +161,7 @@ class EspClass {
|
|||||||
public:
|
public:
|
||||||
void restart() { Serial.println("Ignore reboot in simulation"); }
|
void restart() { Serial.println("Ignore reboot in simulation"); }
|
||||||
uint32_t getFreeHeap() { return 300 * 1024; } // assume 300 KB free heap
|
uint32_t getFreeHeap() { return 300 * 1024; } // assume 300 KB free heap
|
||||||
|
uint32_t getFreePsram() { return 8 * 1024 * 1024; } // assume 8 MB free PSRAM
|
||||||
} ESP;
|
} ESP;
|
||||||
|
|
||||||
unsigned long __delayTime = 0;
|
unsigned long __delayTime = 0;
|
||||||
@@ -166,11 +171,16 @@ void delay(uint32_t ms) {
|
|||||||
__delayTime += ms * 1000;
|
__delayTime += ms * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *heap_caps_calloc(size_t n, size_t size, uint32_t caps) {
|
||||||
|
return calloc(n, size);
|
||||||
|
}
|
||||||
|
|
||||||
bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) { return true; }
|
bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) { return true; }
|
||||||
bool ledcWrite(uint8_t pin, uint32_t duty) { return true; }
|
bool ledcWrite(uint8_t pin, uint32_t duty) { return true; }
|
||||||
uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) { return freq; }
|
uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) { return freq; }
|
||||||
int8_t digitalPinToAnalogChannel(uint8_t pin) { return -1; }
|
int8_t digitalPinToAnalogChannel(uint8_t pin) { return -1; }
|
||||||
uint32_t analogReadMilliVolts(uint8_t pin) { return 0; }
|
uint32_t analogReadMilliVolts(uint8_t pin) { return 0; }
|
||||||
|
float temperatureRead() { return 0; }
|
||||||
|
|
||||||
unsigned long __micros;
|
unsigned long __micros;
|
||||||
unsigned long __resetTime = 0;
|
unsigned long __resetTime = 0;
|
||||||
|
|||||||
+7
-2
@@ -38,7 +38,7 @@ const char* getModeName();
|
|||||||
void sendMotors();
|
void sendMotors();
|
||||||
int getDutyCycle(float value);
|
int getDutyCycle(float value);
|
||||||
bool motorsActive();
|
bool motorsActive();
|
||||||
void testMotor(int n);
|
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);
|
||||||
@@ -72,6 +72,7 @@ void failsafe();
|
|||||||
void rcLossFailsafe();
|
void rcLossFailsafe();
|
||||||
void descend();
|
void descend();
|
||||||
void autoFailsafe();
|
void autoFailsafe();
|
||||||
|
void tiltFailsafe();
|
||||||
int parametersCount();
|
int parametersCount();
|
||||||
const char *getParameterName(int index);
|
const char *getParameterName(int index);
|
||||||
float getParameter(int index);
|
float getParameter(int index);
|
||||||
@@ -82,10 +83,14 @@ void resetParameters();
|
|||||||
|
|
||||||
// mocks
|
// mocks
|
||||||
void setLED(bool on) {};
|
void setLED(bool on) {};
|
||||||
void calibrateGyro() { print("Skip gyro calibrating\n"); };
|
|
||||||
void calibrateAccel() { print("Skip accel calibrating\n"); };
|
void calibrateAccel() { print("Skip accel calibrating\n"); };
|
||||||
void printIMUCalibration() { print("cal: N/A\n"); };
|
void printIMUCalibration() { print("cal: N/A\n"); };
|
||||||
void printIMUInfo() {};
|
void printIMUInfo() {};
|
||||||
void printWiFiInfo() {};
|
void printWiFiInfo() {};
|
||||||
void configWiFi(bool, const char*, const char*) { print("Skip WiFi config\n"); };
|
void configWiFi(bool, const char*, const char*) { print("Skip WiFi config\n"); };
|
||||||
void setWiFiMode(const String& mode) { print("Skip WiFi mode set\n"); };
|
void setWiFiMode(const String& mode) { print("Skip WiFi mode set\n"); };
|
||||||
|
|
||||||
|
class IMU {
|
||||||
|
public:
|
||||||
|
float getTemp() { return 0; }
|
||||||
|
} imu;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
Serial.begin(0);
|
Serial.begin(0);
|
||||||
setupParameters();
|
setupParameters();
|
||||||
setupLog();
|
setupLog();
|
||||||
|
rcRxPin = 1; // set rc pin to enable rc reading
|
||||||
gzmsg << "Flix plugin loaded" << endl;
|
gzmsg << "Flix plugin loaded" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@ public:
|
|||||||
|
|
||||||
applyMotorForces();
|
applyMotorForces();
|
||||||
publishTopics();
|
publishTopics();
|
||||||
logData();
|
loopLog();
|
||||||
syncParameters();
|
syncParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,18 +11,22 @@
|
|||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include "../../flix/util.h"
|
#include "../../flix/util.h"
|
||||||
|
|
||||||
const int CHANNEL = 6;
|
const bool DISABLE_SWARM = true;
|
||||||
|
const int CHANNEL = -1; // -1 means auto search
|
||||||
char key[ESP_NOW_KEY_LEN + 1] = {0}; // with trailing null
|
char key[ESP_NOW_KEY_LEN + 1] = {0}; // with trailing null
|
||||||
|
|
||||||
Preferences storage;
|
Preferences storage;
|
||||||
|
|
||||||
std::vector<ESPNOWSerial *> peers;
|
std::vector<ESPNOWSerial *> peers;
|
||||||
|
bool stop = false;
|
||||||
|
|
||||||
void onNewPeer(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) {
|
void onNewPeer(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) {
|
||||||
if (len != 4 || memcmp(data, "flix", 4) != 0) return; // check if discovery message
|
if (len != 4 || memcmp(data, "flix", 4) != 0) return; // check if discovery message
|
||||||
|
|
||||||
|
if (stop) return;
|
||||||
|
|
||||||
Serial.printf("New peer: " MACSTR "\n", MAC2STR(info->src_addr));
|
Serial.printf("New peer: " MACSTR "\n", MAC2STR(info->src_addr));
|
||||||
ESPNOWSerial *link = new ESPNOWSerial(info->src_addr, CHANNEL, WIFI_IF_AP);
|
ESPNOWSerial *link = new ESPNOWSerial(info->src_addr, WiFi.channel(), WIFI_IF_STA);
|
||||||
link->begin();
|
link->begin();
|
||||||
link->setKey((const uint8_t *)key);
|
link->setKey((const uint8_t *)key);
|
||||||
peers.push_back(link);
|
peers.push_back(link);
|
||||||
@@ -30,9 +34,8 @@ void onNewPeer(const esp_now_recv_info_t *info, const uint8_t *data, int len, vo
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
WiFi.setChannel(CHANNEL);
|
|
||||||
|
|
||||||
ESP_NOW.onNewPeer(onNewPeer, NULL);
|
ESP_NOW.onNewPeer(onNewPeer, NULL);
|
||||||
ESP_NOW.begin();
|
ESP_NOW.begin();
|
||||||
@@ -43,12 +46,6 @@ void setup() {
|
|||||||
storage.putString("key", key);
|
storage.putString("key", key);
|
||||||
}
|
}
|
||||||
strcpy(key, storage.getString("key").c_str());
|
strcpy(key, storage.getString("key").c_str());
|
||||||
|
|
||||||
// Discover the first peer
|
|
||||||
while (peers.empty()) {
|
|
||||||
Serial.printf("espnow %s %s\n", WiFi.softAPmacAddress().c_str(), key);
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateRandomKey() {
|
void generateRandomKey() {
|
||||||
@@ -61,6 +58,20 @@ void generateRandomKey() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
uint8_t buf[5000];
|
uint8_t buf[5000];
|
||||||
|
|
||||||
|
static int channelIndex = 0;
|
||||||
|
static const int channels[] = {6, 11, 1, 2, 6, 11, 3, 4, 5, 6, 1, 11, 8, 6, 9, 10, 11, 6, 1, 12, 13}; // 6, 1 and 11 are most common
|
||||||
|
|
||||||
|
static unsigned long last = 0;
|
||||||
|
if (!stop && millis() - last > 500) {
|
||||||
|
// Change search channel
|
||||||
|
last = millis();
|
||||||
|
channelIndex = (channelIndex + 1) % (sizeof(channels) / sizeof(channels[0]));
|
||||||
|
int channel = CHANNEL < 0 ? channels[channelIndex] : CHANNEL;
|
||||||
|
Serial.printf("Run on Flix: espnow %s %s\n", WiFi.STA.macAddress().c_str(), key);
|
||||||
|
Serial.printf("Searching channel %d\n", channel);
|
||||||
|
WiFi.setChannel(channel);
|
||||||
|
}
|
||||||
|
|
||||||
// Send from Serial to ESP-NOW
|
// Send from Serial to ESP-NOW
|
||||||
while (Serial.available() > 0) {
|
while (Serial.available() > 0) {
|
||||||
int b = Serial.read();
|
int b = Serial.read();
|
||||||
@@ -81,6 +92,15 @@ void loop() {
|
|||||||
// Send from ESP-NOW to Serial
|
// Send from ESP-NOW to Serial
|
||||||
for (ESPNOWSerial *link : peers) {
|
for (ESPNOWSerial *link : peers) {
|
||||||
int len = link->read(buf, sizeof(buf));
|
int len = link->read(buf, sizeof(buf));
|
||||||
|
if (!stop) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (buf[i] == MAVLINK_STX) {
|
||||||
|
// Got MAVLink message, stop discovery
|
||||||
|
Serial.printf("Received MAVLink from " MACSTR "\n", MAC2STR(link->addr()));
|
||||||
|
if (DISABLE_SWARM) stop = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
Serial.write(buf, len);
|
Serial.write(buf, len);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user