mirror of
https://github.com/okalachev/flix.git
synced 2026-08-16 00:38:56 +00:00
Compare commits
64
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f355cc2938 | ||
|
|
0139d71b12 | ||
|
|
58da0b9959 | ||
|
|
355f4ad49d | ||
|
|
55398a660d | ||
|
|
63bbea4d8b | ||
|
|
5543a363b3 | ||
|
|
363c756c00 | ||
|
|
57b853361c | ||
|
|
ce37e5b724 | ||
|
|
36b050a896 | ||
|
|
93ebf75a44 | ||
|
|
a60c84ce7a | ||
|
|
ae8931cb25 | ||
|
|
e6072b0bc4 | ||
|
|
67e772a23f | ||
|
|
04a24c4939 | ||
|
|
f62e176313 | ||
|
|
8ae06eef85 | ||
|
|
9a17ca848d | ||
|
|
b8f93becca | ||
|
|
5fc2143994 | ||
|
|
b7102d395c | ||
|
|
58ea75d335 | ||
|
|
93b3077fa7 | ||
|
|
4c74768131 | ||
|
|
9880eeccd3 | ||
|
|
a26d096dc0 | ||
|
|
8a91201cf4 | ||
|
|
51ca049b97 | ||
|
|
2decd2d6dd | ||
|
|
abb2e9f79b | ||
|
|
6c907b77f6 | ||
|
|
0a53170097 | ||
|
|
6b36488245 | ||
|
|
f30a182b20 | ||
|
|
90b506e084 | ||
|
|
5f9aae62b9 | ||
|
|
0e0867ceab | ||
|
|
8e276bde38 | ||
|
|
83aac78cf7 | ||
|
|
eb93b0b29d | ||
|
|
a5991930d1 | ||
|
|
406f7a4af5 | ||
|
|
5ee6d91440 | ||
|
|
38925d7885 | ||
|
|
5c81181221 | ||
|
|
fd249fcaa6 | ||
|
|
9289b042af | ||
|
|
1203a3ae8f | ||
|
|
d48b71fb1a | ||
|
|
8917849711 | ||
|
|
1cdc7a8641 | ||
|
|
0439407d76 | ||
|
|
c2005a2ca2 | ||
|
|
6a804862da | ||
|
|
590bfe10b0 | ||
|
|
70af1a1c09 | ||
|
|
9e9dafbdfb | ||
|
|
86a4418813 | ||
|
|
d64bf24c6d | ||
|
|
7c53e88963 | ||
|
|
fabd5e072d | ||
|
|
1ae85ff118 |
@@ -10,23 +10,31 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build_linux:
|
build_linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES: 1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install Arduino CLI
|
- name: Install Arduino CLI
|
||||||
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
|
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
|
||||||
- name: Build firmware
|
- name: Build firmware for ESP32
|
||||||
env:
|
|
||||||
ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES: 1
|
|
||||||
run: make
|
run: make
|
||||||
|
- name: Build firmware for ESP32-C3
|
||||||
|
run: make BOARD=esp32:esp32:esp32c3
|
||||||
|
- name: Build firmware for ESP32-S3
|
||||||
|
run: make BOARD=esp32:esp32:esp32s3:CDCOnBoot=cdc
|
||||||
|
- 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
|
||||||
|
- 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
|
||||||
|
- name: Build firmware for Flix2
|
||||||
|
run: make BOARD=esp32:esp32:esp32s3:FlashSize=4M,CDCOnBoot=cdc,PSRAM=opi FLAGS=-DFLIX2 EXTRA=--output-dir=flix/build/esp32.esp32.flix2
|
||||||
- name: Upload binaries
|
- name: Upload binaries
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: firmware-binary
|
name: firmware-binary
|
||||||
path: flix/build
|
path: flix/build
|
||||||
- name: Build firmware for ESP32-C3
|
- name: Build espnow-proxy
|
||||||
run: make BOARD=esp32:esp32:esp32c3
|
run: arduino-cli compile --fqbn esp32:esp32:esp32 tools/espnow-proxy
|
||||||
- name: Build firmware for ESP32-S3
|
|
||||||
run: make BOARD=esp32:esp32:esp32s3
|
|
||||||
- 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
|
||||||
|
|
||||||
@@ -64,7 +72,7 @@ jobs:
|
|||||||
apt-get update
|
apt-get update
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget build-essential cmake g++ pkg-config gnupg2 lsb-release sudo
|
DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget build-essential cmake g++ pkg-config gnupg2 lsb-release sudo
|
||||||
- name: Install Arduino CLI
|
- name: Install Arduino CLI
|
||||||
uses: arduino/setup-arduino-cli@v1.1.1
|
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install Gazebo
|
- name: Install Gazebo
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ on:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
actions: read
|
||||||
pages: write
|
pages: write
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
@@ -24,12 +25,50 @@ jobs:
|
|||||||
build_book:
|
build_book:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: markdownlint
|
needs: markdownlint
|
||||||
|
env:
|
||||||
|
BINARIES: ${{ github.event_name == 'push' && (github.ref_name == 'master' || github.ref_name == 'dev') && github.repository == 'okalachev/flix' }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install mdBook
|
- name: Install mdBook
|
||||||
run: cargo install mdbook --vers 0.4.43 --locked
|
run: cargo install mdbook --vers 0.4.43 --locked
|
||||||
- name: Build book
|
- name: Build book
|
||||||
run: cd docs && mdbook build
|
run: cd docs && mdbook build
|
||||||
|
- name: Wait for Build to complete
|
||||||
|
if: ${{ env.BINARIES }}
|
||||||
|
uses: lewagon/wait-on-check-action@v1.9.1
|
||||||
|
with:
|
||||||
|
ref: ${{ github.sha }}
|
||||||
|
check-name: build_linux
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
wait-interval: 30
|
||||||
|
- name: Find firmware binaries
|
||||||
|
if: ${{ env.BINARIES }}
|
||||||
|
id: build_run
|
||||||
|
run: |
|
||||||
|
RUN_ID=$(gh api "repos/${{ github.repository }}/actions/workflows/build.yml/runs?head_sha=${{ github.sha }}&per_page=1" --jq '.workflow_runs[0].id')
|
||||||
|
echo "id=$RUN_ID" >> $GITHUB_OUTPUT
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Download firmware binaries
|
||||||
|
if: ${{ env.BINARIES }}
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
repository: ${{ github.repository }}
|
||||||
|
run-id: ${{ steps.build_run.outputs.id }}
|
||||||
|
name: firmware-binary
|
||||||
|
path: docs/build
|
||||||
|
- name: Create shortcuts for firmware binaries
|
||||||
|
if: ${{ env.BINARIES }}
|
||||||
|
working-directory: docs/build
|
||||||
|
run: |
|
||||||
|
for FQBN in esp32.esp32.*; do
|
||||||
|
zip -r $FQBN.zip $FQBN
|
||||||
|
BOARD="${FQBN#esp32.esp32.}"
|
||||||
|
ln -s "$FQBN/flix.ino.merged.bin" "flix.$BOARD.merged.bin"
|
||||||
|
ln -s "$FQBN/flix.ino.bin" "flix.$BOARD.bin"
|
||||||
|
ln -s "$FQBN/flix.ino.bootloader.bin" "flix.$BOARD.bootloader.bin"
|
||||||
|
done
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/upload-pages-artifact@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
BOARD = esp32:esp32:d1_mini32:DebugLevel=error
|
BOARD = esp32:esp32:esp32
|
||||||
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*))
|
||||||
|
VERSION = $(shell git describe --always --dirty)
|
||||||
|
|
||||||
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 flix \
|
||||||
|
--fqbn $(BOARD) \
|
||||||
|
--build-property "build.core_debug_level=1" \
|
||||||
|
--build-property "compiler.cpp.extra_flags=-DVERSION=$(VERSION) $(FLAGS)" $(EXTRA)
|
||||||
|
|
||||||
upload: build
|
upload: build
|
||||||
arduino-cli upload --fqbn $(BOARD) -p "$(PORT)" flix
|
arduino-cli upload flix --fqbn $(BOARD) -p "$(PORT)"
|
||||||
|
|
||||||
erase:
|
erase:
|
||||||
arduino-cli burn-bootloader --fqbn $(BOARD) -p "$(PORT)" -P esptool
|
arduino-cli burn-bootloader --fqbn $(BOARD) -p "$(PORT)" -P esptool
|
||||||
@@ -22,13 +26,13 @@ core .core:
|
|||||||
|
|
||||||
libs .libs:
|
libs .libs:
|
||||||
arduino-cli lib update-index
|
arduino-cli lib update-index
|
||||||
arduino-cli lib install "FlixPeriph"
|
ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=1 arduino-cli lib install --git-url 'https://github.com/okalachev/flixperiph.git#dev'
|
||||||
arduino-cli lib install "MAVLink"@2.0.25
|
arduino-cli lib install "MAVLink"@2.0.25
|
||||||
touch .libs
|
touch .libs
|
||||||
|
|
||||||
upload_proxy: .core .libs
|
upload_proxy: .core .libs
|
||||||
arduino-cli compile --fqbn $(BOARD) tools/espnow-proxy
|
arduino-cli compile tools/espnow-proxy --fqbn $(BOARD)
|
||||||
arduino-cli upload --fqbn $(BOARD) -p "$(PORT)" tools/espnow-proxy
|
arduino-cli upload tools/espnow-proxy --fqbn $(BOARD) -p "$(PORT)"
|
||||||
|
|
||||||
gazebo/build cmake: gazebo/CMakeLists.txt
|
gazebo/build cmake: gazebo/CMakeLists.txt
|
||||||
mkdir -p gazebo/build
|
mkdir -p gazebo/build
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ Outdoor flights demo video of the current prototype:
|
|||||||
|
|
||||||
<a href="https://youtu.be/KXlNmvUTi4g"><img width=300 src="https://i3.ytimg.com/vi/KXlNmvUTi4g/maxresdefault.jpg"></a>
|
<a href="https://youtu.be/KXlNmvUTi4g"><img width=300 src="https://i3.ytimg.com/vi/KXlNmvUTi4g/maxresdefault.jpg"></a>
|
||||||
|
|
||||||
|
### Position control
|
||||||
|
|
||||||
|
The position control feature is in development. RoboCamp 2026 demo (using an overhead camera, [sources](https://github.com/xTimop/flix-poscontrol/compare/robolager2026...xTimop:flix-poscontrol:poscontrol)):
|
||||||
|
|
||||||
|
<a href="https://youtu.be/369Xowm4HcU"><img width=300 src="https://i3.ytimg.com/vi/369Xowm4HcU/maxresdefault.jpg"></a>
|
||||||
|
|
||||||
## Simulation
|
## Simulation
|
||||||
|
|
||||||
The simulator is implemented using Gazebo and runs the original Arduino code:
|
The simulator is implemented using Gazebo and runs the original Arduino code:
|
||||||
@@ -84,7 +90,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 |
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
+63
-30
@@ -1,20 +1,48 @@
|
|||||||
# Usage: build, setup and flight
|
# Usage: build, setup and flight
|
||||||
|
|
||||||
To fly Flix quadcopter, you need to build the firmware, upload it to the ESP32 board, and set up the drone for flight.
|
To fly Flix quadcopter, you need to upload the firmware to the ESP32 board, and set up the drone for flight.
|
||||||
|
|
||||||
To get the firmware sources, clone the repository using git:
|
## Uploading the firmware
|
||||||
|
|
||||||
|
You can either use the **prebuilt binaries** or **build the firmware** from sources — this will let you modify the firmware and add new features.
|
||||||
|
|
||||||
|
### Prebuilt binaries (the easiest way)
|
||||||
|
|
||||||
|
1. Download the latest firmware file using the following links:
|
||||||
|
|
||||||
|
<!-- markdownlint-disable MD044 -->
|
||||||
|
|Type|Boards|Link|
|
||||||
|
|-|-|-|
|
||||||
|
|ESP32|DevKit, D1 Mini|[`quadcopter.dev/flix.esp32.merged.bin`](https://quadcopter.dev/flix.esp32.merged.bin)|
|
||||||
|
|ESP32-S3|Most S3 based|[`quadcopter.dev/flix.esp32s3.merged.bin`](https://quadcopter.dev/flix.esp32s3.merged.bin)|
|
||||||
|
|ESP32-S3 (2MB PSRAM)|S3 Super Mini, S3 Zero (2MB PSRAM)|[`quadcopter.dev/flix.esp32s3.qspi.merged.bin`](https://quadcopter.dev/flix.esp32s3.qspi.merged.bin)|
|
||||||
|
|ESP32-S3 (8/16MB PSRAM)|S3 Zero (8MB PSRAM)|[`quadcopter.dev/flix.esp32s3.opi.merged.bin`](https://quadcopter.dev/flix.esp32s3.opi.merged.bin)|
|
||||||
|
|ESP32-C3|C3 Super Mini|[`quadcopter.dev/flix.esp32c3.merged.bin`](https://quadcopter.dev/flix.esp32c3.merged.bin)|
|
||||||
|
|Flix2|Flix2 board|[`quadcopter.dev/flix.flix2.merged.bin`](https://quadcopter.dev/flix.flix2.merged.bin)|
|
||||||
|
<!-- markdownlint-enable MD044 -->
|
||||||
|
|
||||||
|
2. Flash your ESP32 board using [ESP32 Web Flasher](https://www.espboards.dev/tools/program/):
|
||||||
|
|
||||||
|
<img src="img/web-flasher.png" width="400">
|
||||||
|
|
||||||
|
* Connect the board to your computer, press *Connect to ESP*, choose the serial port.
|
||||||
|
* Go to the *Flash* tab.
|
||||||
|
* Choose the downloaded firmware file, set *Flash address* to *0* (important).
|
||||||
|
* Click *Program* button and wait until the process is finished.
|
||||||
|
|
||||||
|
### Building from sources (flexible)
|
||||||
|
|
||||||
|
You can build and upload the firmware using either **Arduino IDE** (easier for beginners) or **command line**.
|
||||||
|
|
||||||
|
Get the sources using git:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/okalachev/flix.git && cd flix
|
git clone https://github.com/okalachev/flix.git && cd flix
|
||||||
```
|
```
|
||||||
|
|
||||||
Beginners can [download the source code as a ZIP archive](https://github.com/okalachev/flix/archive/refs/heads/master.zip).
|
Beginners can [download the sources as a ZIP archive](https://github.com/okalachev/flix/archive/refs/heads/master.zip).
|
||||||
|
|
||||||
## Building the firmware
|
#### Arduino IDE (Windows, Linux, macOS)
|
||||||
|
|
||||||
You can build and upload the firmware using either **Arduino IDE** (easier for beginners) or **command line**.
|
|
||||||
|
|
||||||
### Arduino IDE (Windows, Linux, macOS)
|
|
||||||
|
|
||||||
<img src="img/arduino-ide.png" width="400" alt="Flix firmware open in Arduino IDE">
|
<img src="img/arduino-ide.png" width="400" alt="Flix firmware open in Arduino IDE">
|
||||||
|
|
||||||
@@ -25,11 +53,11 @@ 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.
|
||||||
|
|
||||||
### Command line (Windows, Linux, macOS)
|
#### Command line (Windows, Linux, macOS)
|
||||||
|
|
||||||
1. [Install Arduino CLI](https://arduino.github.io/arduino-cli/installation/).
|
1. [Install Arduino CLI](https://arduino.github.io/arduino-cli/installation/).
|
||||||
|
|
||||||
@@ -61,7 +89,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).
|
||||||
@@ -71,15 +99,6 @@ See other available Make commands in [Makefile](../Makefile).
|
|||||||
|
|
||||||
## Before first flight
|
## Before first flight
|
||||||
|
|
||||||
### Choose the IMU model
|
|
||||||
|
|
||||||
In case if using different IMU model than MPU9250, change `imu` variable declaration in the `imu.ino`:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
ICM20948 imu(SPI); // For ICM-20948
|
|
||||||
MPU6050 imu(Wire); // For MPU-6050
|
|
||||||
```
|
|
||||||
|
|
||||||
### Connect using QGroundControl
|
### Connect using QGroundControl
|
||||||
|
|
||||||
QGroundControl is a ground control station software that can be used to monitor and control the drone.
|
QGroundControl is a ground control station software that can be used to monitor and control the drone.
|
||||||
@@ -105,7 +124,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">
|
||||||
|
|
||||||
@@ -120,6 +139,17 @@ The drone is configured using parameters. To access and modify them, go to the Q
|
|||||||
|
|
||||||
You can also work with parameters using `p` command in the console. Parameter names are case-insensitive.
|
You can also work with parameters using `p` command in the console. Parameter names are case-insensitive.
|
||||||
|
|
||||||
|
### Configure the IMU
|
||||||
|
|
||||||
|
1. Configure the following parameters for the IMU:
|
||||||
|
* `IMU_MODEL` — IMU model (1 for MPU-9250/MPU-6500, 2 for ICM-20948, 3 for MPU-6050, 4 for ICM-40609-D).
|
||||||
|
* `IMU_BUS` — communication bus (0 for SPI, 1 for I²C).
|
||||||
|
* `IMU_PIN_SCK`, `IMU_PIN_MISO`, `IMU_PIN_MOSI`, `IMU_PIN_CS` — SPI pin numbers.
|
||||||
|
* `IMU_PIN_SCL`, `IMU_PIN_SDA` — I²C pin numbers.
|
||||||
|
* `IMU_PIN_INT` — IMU data ready pin number (-1 if not used).
|
||||||
|
2. Reboot the drone.
|
||||||
|
3. Check the IMU is working using `imu` command in the console (should print `status: OK`).
|
||||||
|
|
||||||
### Define IMU orientation
|
### Define IMU orientation
|
||||||
|
|
||||||
The IMU orientation (relative to the drone's axes) is defined using the parameters: `IMU_ROT_ROLL`, `IMU_ROT_PITCH`, and `IMU_ROT_YAW`.
|
The IMU orientation (relative to the drone's axes) is defined using the parameters: `IMU_ROT_ROLL`, `IMU_ROT_PITCH`, and `IMU_ROT_YAW`.
|
||||||
@@ -148,9 +178,9 @@ Before flight you need to calibrate the accelerometer:
|
|||||||
|
|
||||||
If using non-default motor pins, set the pin numbers using the parameters: `MOTOR_PIN_FL`, `MOTOR_PIN_FR`, `MOTOR_PIN_RL`, `MOTOR_PIN_RR` (front-left, front-right, rear-left, rear-right respectively).
|
If using non-default motor pins, set the pin numbers using the parameters: `MOTOR_PIN_FL`, `MOTOR_PIN_FR`, `MOTOR_PIN_RL`, `MOTOR_PIN_RR` (front-left, front-right, rear-left, rear-right respectively).
|
||||||
|
|
||||||
Certain ESP32 models (such as ESP32-S3 and ESP32-C3) support a lower maximum PWM frequency; on these boards the parameter `MOT_PWM_FREQ` should be set to 38000 Hz.
|
#### Brushless motors
|
||||||
|
|
||||||
If using brushless motors and ESCs:
|
If using brushless motors with ESCs:
|
||||||
|
|
||||||
1. Set the appropriate PWM using the parameters: `MOT_PWM_STOP`, `MOT_PWM_MIN`, and `MOT_PWM_MAX` (1000, 1000, and 2000 is typical).
|
1. Set the appropriate PWM using the parameters: `MOT_PWM_STOP`, `MOT_PWM_MIN`, and `MOT_PWM_MAX` (1000, 1000, and 2000 is typical).
|
||||||
2. Decrease the PWM frequency using the `MOT_PWM_FREQ` parameter (400 is typical).
|
2. Decrease the PWM frequency using the `MOT_PWM_FREQ` parameter (400 is typical).
|
||||||
@@ -158,7 +188,7 @@ If using brushless motors and ESCs:
|
|||||||
> [!CAUTION]
|
> [!CAUTION]
|
||||||
> **Remove the props when configuring the motors!** If improperly configured, you may not be able to stop them.
|
> **Remove the props when configuring the motors!** If improperly configured, you may not be able to stop them.
|
||||||
|
|
||||||
### Battery voltage monitoring
|
### Battery voltage monitoring (optional)
|
||||||
|
|
||||||
ESP32 ADC can measure only up to 3.3 V, so you need to use a voltage divider to monitor the battery voltage. To enable voltage measurement, set the following parameters:
|
ESP32 ADC can measure only up to 3.3 V, so you need to use a voltage divider to monitor the battery voltage. To enable voltage measurement, set the following parameters:
|
||||||
|
|
||||||
@@ -198,7 +228,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 +273,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 +363,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 +382,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 the serial port.
|
||||||
|
|
||||||
## 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,24 @@ This page contains user-built drones based on the Flix project. Publish your pro
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Author: [Oleg1405](https://t.me/Oleg1405).<br>
|
||||||
|
Description: ESP32 Mini, MPU-6500 IMU, boost converter, BT2.0 power connector, 65 mm props, BetaFPV ELRS Lite Receiver, Radiomaster Pocket + Mavlink Joystick (Android) control.
|
||||||
|
|
||||||
|
<img src="img/user/oleg1405/1.jpg" height=300>
|
||||||
|
|
||||||
|
[Flight video](https://www.youtube.com/shorts/rbXV4sHbpso).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
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).
|
||||||
|
|||||||
+10
-7
@@ -6,7 +6,7 @@
|
|||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
|
|
||||||
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
|
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
|
||||||
extern const int RAW, ACRO, STAB, AUTO;
|
extern const int RAW, ACRO, STAB, AUTO;
|
||||||
@@ -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());
|
||||||
@@ -191,7 +191,10 @@ void doCommand(String str, bool echo = false) {
|
|||||||
print("Free heap: %d KB\n", ESP.getFreeHeap() / 1024);
|
print("Free heap: %d KB\n", ESP.getFreeHeap() / 1024);
|
||||||
print("PSRAM: %d KB\n", ESP.getPsramSize() / 1024);
|
print("PSRAM: %d KB\n", ESP.getPsramSize() / 1024);
|
||||||
print("Free PSRAM: %d KB\n", ESP.getFreePsram() / 1024);
|
print("Free PSRAM: %d KB\n", ESP.getFreePsram() / 1024);
|
||||||
print("Firmware: " __DATE__ " " __TIME__ "\n");
|
#ifdef VERSION
|
||||||
|
print("Version: %s\n", STRINGIFY(VERSION));
|
||||||
|
#endif
|
||||||
|
print("Build date: " __DATE__ " " __TIME__ "\n");
|
||||||
// Print tasks table
|
// Print tasks table
|
||||||
print("Num Task MinSt Prio Core CPU%%\n");
|
print("Num Task MinSt Prio Core CPU%%\n");
|
||||||
int taskCount = uxTaskGetNumberOfTasks();
|
int taskCount = uxTaskGetNumberOfTasks();
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) 2026 Oleg Kalachev <okalachev@gmail.com>
|
||||||
|
// Repository: https://github.com/okalachev/flix
|
||||||
|
|
||||||
|
// Parameter defaults
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void setDefaults() {
|
||||||
|
// Set defaults here
|
||||||
|
|
||||||
|
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
|
pwmFrequency = 38000;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FLIX2
|
||||||
|
imuModel = 4; // ICM-40609-D
|
||||||
|
imuIntPin = 10;
|
||||||
|
imuCsPin = 14;
|
||||||
|
|
||||||
|
motorPins[MOTOR_REAR_LEFT] = 41;
|
||||||
|
motorPins[MOTOR_REAR_RIGHT] = 7;
|
||||||
|
motorPins[MOTOR_FRONT_RIGHT] = 18;
|
||||||
|
motorPins[MOTOR_FRONT_LEFT] = 38;
|
||||||
|
|
||||||
|
voltagePin = 3;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+10
-35
@@ -6,34 +6,9 @@
|
|||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "quaternion.h"
|
#include "quaternion.h"
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define PITCHRATE_P 0.05
|
|
||||||
#define PITCHRATE_I 0.2
|
|
||||||
#define PITCHRATE_D 0.001
|
|
||||||
#define PITCHRATE_I_LIM 0.3
|
|
||||||
#define ROLLRATE_P PITCHRATE_P
|
|
||||||
#define ROLLRATE_I PITCHRATE_I
|
|
||||||
#define ROLLRATE_D PITCHRATE_D
|
|
||||||
#define ROLLRATE_I_LIM PITCHRATE_I_LIM
|
|
||||||
#define YAWRATE_P 0.3
|
|
||||||
#define YAWRATE_I 0.0
|
|
||||||
#define YAWRATE_D 0.0
|
|
||||||
#define YAWRATE_I_LIM 0.3
|
|
||||||
#define ROLL_P 6
|
|
||||||
#define ROLL_I 0
|
|
||||||
#define ROLL_D 0
|
|
||||||
#define PITCH_P ROLL_P
|
|
||||||
#define PITCH_I ROLL_I
|
|
||||||
#define PITCH_D ROLL_D
|
|
||||||
#define YAW_P 3
|
|
||||||
#define PITCHRATE_MAX radians(360)
|
|
||||||
#define ROLLRATE_MAX radians(360)
|
|
||||||
#define YAWRATE_MAX radians(300)
|
|
||||||
#define TILT_MAX radians(30)
|
|
||||||
#define RATES_D_LPF_ALPHA 0.2 // cutoff frequency ~ 40 Hz
|
|
||||||
|
|
||||||
const int RAW = 0, ACRO = 1, STAB = 2, AUTO = 3; // flight modes
|
const int RAW = 0, ACRO = 1, STAB = 2, AUTO = 3; // flight modes
|
||||||
int mode = STAB;
|
int mode = STAB;
|
||||||
bool armed = false;
|
bool armed = false;
|
||||||
@@ -41,17 +16,17 @@ bool armed = false;
|
|||||||
Quaternion attitudeTarget;
|
Quaternion attitudeTarget;
|
||||||
Vector ratesTarget;
|
Vector ratesTarget;
|
||||||
Vector ratesExtra; // feedforward rates
|
Vector ratesExtra; // feedforward rates
|
||||||
Vector torqueTarget;
|
Vector torqueTarget; // 0 - no torque, 1 - maximum torque
|
||||||
float thrustTarget;
|
float thrustTarget;
|
||||||
|
|
||||||
PID rollRatePID(ROLLRATE_P, ROLLRATE_I, ROLLRATE_D, ROLLRATE_I_LIM, RATES_D_LPF_ALPHA);
|
PID rollRatePID(0.05, 0.2, 0.001, 0.3, 0.2);
|
||||||
PID pitchRatePID(PITCHRATE_P, PITCHRATE_I, PITCHRATE_D, PITCHRATE_I_LIM, RATES_D_LPF_ALPHA);
|
PID pitchRatePID(0.05, 0.2, 0.001, 0.3, 0.2);
|
||||||
PID yawRatePID(YAWRATE_P, YAWRATE_I, YAWRATE_D);
|
PID yawRatePID(0.3, 0, 0, 0.3);
|
||||||
PID rollPID(ROLL_P, ROLL_I, ROLL_D);
|
PID rollPID(6);
|
||||||
PID pitchPID(PITCH_P, PITCH_I, PITCH_D);
|
PID pitchPID(6);
|
||||||
PID yawPID(YAW_P, 0, 0);
|
PID yawPID(3);
|
||||||
Vector maxRate(ROLLRATE_MAX, PITCHRATE_MAX, YAWRATE_MAX);
|
Vector maxRate(radians(360), radians(360), radians(360));
|
||||||
float tiltMax = TILT_MAX;
|
float tiltMax = radians(30);
|
||||||
int flightModes[] = {STAB, STAB, STAB}; // map for rc mode switch
|
int flightModes[] = {STAB, STAB, STAB}; // map for rc mode switch
|
||||||
|
|
||||||
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
|
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
|
||||||
|
|||||||
+8
-1
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "quaternion.h"
|
#include "quaternion.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
Vector rates; // estimated angular rates, rad/s
|
Vector rates; // estimated angular rates, rad/s
|
||||||
@@ -15,6 +15,12 @@ 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);
|
||||||
|
|
||||||
|
void setupEstimate() {
|
||||||
|
print("Setup estimation\n");
|
||||||
|
ratesNotch.reset();
|
||||||
|
}
|
||||||
|
|
||||||
void estimate() {
|
void estimate() {
|
||||||
applyGyro();
|
applyGyro();
|
||||||
@@ -25,6 +31,7 @@ void estimate() {
|
|||||||
void applyGyro() {
|
void applyGyro() {
|
||||||
// filter gyro to get angular rates
|
// filter gyro to get angular rates
|
||||||
rates = ratesFilter.update(gyro);
|
rates = ratesFilter.update(gyro);
|
||||||
|
rates = ratesNotch.update(rates);
|
||||||
|
|
||||||
// apply rates to attitude
|
// apply rates to attitude
|
||||||
attitude = Quaternion::rotate(attitude, Quaternion::fromRotationVector(rates * dt));
|
attitude = Quaternion::rotate(attitude, Quaternion::fromRotationVector(rates * dt));
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
||||||
|
// Repository: https://github.com/okalachev/flix
|
||||||
|
|
||||||
|
// Low pass and notch filters
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
template <typename T> // Using template to make the filter usable for scalar and vector values
|
||||||
|
class LowPassFilter {
|
||||||
|
public:
|
||||||
|
float alpha; // smoothing constant, 1 means filter disabled
|
||||||
|
T output;
|
||||||
|
|
||||||
|
LowPassFilter(float alpha): alpha(alpha) {};
|
||||||
|
|
||||||
|
T update(const T input) {
|
||||||
|
if (!init) {
|
||||||
|
init = true;
|
||||||
|
return output = input;
|
||||||
|
}
|
||||||
|
return output += alpha * (input - output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCutOffFrequency(float cutOffFreq, float dt) {
|
||||||
|
alpha = 1 - exp(-2 * PI * cutOffFreq * dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
init = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool init = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class NotchFilter {
|
||||||
|
public:
|
||||||
|
float frequency;
|
||||||
|
float bandwidth;
|
||||||
|
T output;
|
||||||
|
|
||||||
|
NotchFilter(float frequency, float bandwidth): frequency(frequency), bandwidth(bandwidth) {
|
||||||
|
reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
T update(const T input) {
|
||||||
|
if (frequency <= 0 || bandwidth <= 0) return input;
|
||||||
|
|
||||||
|
if (!init) {
|
||||||
|
init = true;
|
||||||
|
x1 = x2 = input;
|
||||||
|
y1 = y2 = input;
|
||||||
|
return output = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
output = b0 * input + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
|
||||||
|
|
||||||
|
x2 = x1;
|
||||||
|
x1 = input;
|
||||||
|
y2 = y1;
|
||||||
|
y1 = output;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
const float dt = 0.001f;
|
||||||
|
float f = frequency;
|
||||||
|
float bw = bandwidth;
|
||||||
|
if (f < 0) f = 0;
|
||||||
|
if (bw < 1e-6f) bw = 1e-6f;
|
||||||
|
|
||||||
|
float q = f / bw;
|
||||||
|
if (q < 1e-3f) q = 1e-3f;
|
||||||
|
|
||||||
|
const float w0 = 2.0f * PI * f * dt;
|
||||||
|
const float c = cos(w0);
|
||||||
|
const float s = sin(w0);
|
||||||
|
const float alpha = s / (2.0f * q);
|
||||||
|
|
||||||
|
const float a0 = 1.0f + alpha;
|
||||||
|
const float invA0 = 1.0f / a0;
|
||||||
|
|
||||||
|
b0 = 1.0f * invA0;
|
||||||
|
b1 = -2.0f * c * invA0;
|
||||||
|
b2 = 1.0f * invA0;
|
||||||
|
a1 = -2.0f * c * invA0;
|
||||||
|
a2 = (1.0f - alpha) * invA0;
|
||||||
|
|
||||||
|
init = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
float b0, b1, b2, a1, a2;
|
||||||
|
T x1, x2, y1, y2;
|
||||||
|
bool init = false;
|
||||||
|
};
|
||||||
@@ -26,6 +26,7 @@ void setup() {
|
|||||||
setupWiFi();
|
setupWiFi();
|
||||||
setupIMU();
|
setupIMU();
|
||||||
setupRC();
|
setupRC();
|
||||||
|
setupEstimate();
|
||||||
setupLog();
|
setupLog();
|
||||||
setLED(false);
|
setLED(false);
|
||||||
print("Initializing complete\n");
|
print("Initializing complete\n");
|
||||||
|
|||||||
+40
-21
@@ -4,12 +4,17 @@
|
|||||||
// Work with the IMU sensor
|
// Work with the IMU sensor
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
#include <FlixPeriph.h>
|
#include <FlixPeriph.h>
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
MPU9250 imu(SPI);
|
IMU *imu;
|
||||||
|
int imuModel = -1; // 1 - MPU9250, 2 - ICM20948, 3 - MPU6050, 4 - ICM40609D
|
||||||
|
int imuBus = 0; // 0 - SPI, 1 - I2C
|
||||||
|
int imuSckPin = SCK, imuMisoPin = MISO, imuMosiPin = MOSI, imuCsPin = SS, imuIntPin = -1;
|
||||||
|
int imuSdaPin = SDA, imuSclPin = SCL;
|
||||||
Vector imuRotation(0, 0, PI / 2); // imu orientation as Euler angles
|
Vector imuRotation(0, 0, PI / 2); // imu orientation as Euler angles
|
||||||
|
|
||||||
Vector gyro; // gyroscope output, rad/s
|
Vector gyro; // gyroscope output, rad/s
|
||||||
@@ -23,22 +28,35 @@ LowPassFilter<Vector> gyroBiasFilter(0.001);
|
|||||||
|
|
||||||
void setupIMU() {
|
void setupIMU() {
|
||||||
print("Setup IMU\n");
|
print("Setup IMU\n");
|
||||||
imu.begin();
|
free(imu);
|
||||||
|
if (imuModel == 3) imuBus = 1; // MPU6050 is I2C only
|
||||||
|
|
||||||
|
if (imuBus == 0) {
|
||||||
|
// SPI connection
|
||||||
|
SPI.begin(imuSckPin, imuMisoPin, imuMosiPin);
|
||||||
|
imu = IMU::create(imuModel, SPI, imuCsPin, imuIntPin);
|
||||||
|
} else {
|
||||||
|
// I2C connection
|
||||||
|
Wire.setPins(imuSdaPin, imuSclPin);
|
||||||
|
imu = IMU::create(imuModel, Wire, imuIntPin);
|
||||||
|
}
|
||||||
|
|
||||||
|
imu->begin();
|
||||||
configureIMU();
|
configureIMU();
|
||||||
}
|
}
|
||||||
|
|
||||||
void configureIMU() {
|
void configureIMU() {
|
||||||
imu.setAccelRange(imu.ACCEL_RANGE_4G);
|
imu->setAccelRange(IMU::ACCEL_RANGE_4G);
|
||||||
imu.setGyroRange(imu.GYRO_RANGE_2000DPS);
|
imu->setGyroRange(IMU::GYRO_RANGE_2000DPS);
|
||||||
imu.setDLPF(imu.DLPF_MAX);
|
imu->setDLPF(IMU::DLPF_MAX);
|
||||||
imu.setRate(imu.RATE_1KHZ_APPROX);
|
imu->setRate(IMU::RATE_1KHZ_APPROX);
|
||||||
imu.setupInterrupt();
|
imu->setupInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void readIMU() {
|
void readIMU() {
|
||||||
imu.waitForData();
|
imu->waitForData();
|
||||||
imu.getGyro(gyro.x, gyro.y, gyro.z);
|
imu->getGyro(gyro.x, gyro.y, gyro.z);
|
||||||
imu.getAccel(acc.x, acc.y, acc.z);
|
imu->getAccel(acc.x, acc.y, acc.z);
|
||||||
calibrateGyroOnce();
|
calibrateGyroOnce();
|
||||||
|
|
||||||
// Apply scale and bias
|
// Apply scale and bias
|
||||||
@@ -60,7 +78,7 @@ void calibrateGyroOnce() {
|
|||||||
|
|
||||||
void calibrateAccel() {
|
void calibrateAccel() {
|
||||||
print("Calibrating accelerometer\n");
|
print("Calibrating accelerometer\n");
|
||||||
imu.setAccelRange(imu.ACCEL_RANGE_2G); // the most sensitive mode
|
imu->setAccelRange(IMU::ACCEL_RANGE_2G); // the most sensitive mode
|
||||||
|
|
||||||
print("1/6 Place level [8 sec]\n");
|
print("1/6 Place level [8 sec]\n");
|
||||||
pause(8);
|
pause(8);
|
||||||
@@ -94,9 +112,9 @@ void calibrateAccelOnce() {
|
|||||||
// Compute the average of the accelerometer readings
|
// Compute the average of the accelerometer readings
|
||||||
acc = Vector(0, 0, 0);
|
acc = Vector(0, 0, 0);
|
||||||
for (int i = 0; i < samples; i++) {
|
for (int i = 0; i < samples; i++) {
|
||||||
imu.waitForData();
|
imu->waitForData();
|
||||||
Vector sample;
|
Vector sample;
|
||||||
imu.getAccel(sample.x, sample.y, sample.z);
|
imu->getAccel(sample.x, sample.y, sample.z);
|
||||||
acc = acc + sample;
|
acc = acc + sample;
|
||||||
}
|
}
|
||||||
acc = acc / samples;
|
acc = acc / samples;
|
||||||
@@ -121,17 +139,18 @@ void printIMUCalibration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printIMUInfo() {
|
void printIMUInfo() {
|
||||||
imu.status() ? print("status: ERROR %d\n", imu.status()) : print("status: OK\n");
|
imu->status() ? print("status: ERROR %d\n", imu->status()) : print("status: OK\n");
|
||||||
print("model: %s\n", imu.getModel());
|
print("model: %s\n", imu->getModel());
|
||||||
print("who am I: 0x%02X\n", imu.whoAmI());
|
print("who am I: 0x%02X\n", imu->whoAmI());
|
||||||
print("rate: %.0f\n", loopRate);
|
print("rate: %.0f\n", loopRate);
|
||||||
print("temperature: %.1f °C\n", imu.getTemp());
|
print("interrupt mode: %s\n", imuIntPin != -1 ? "pin" : "timer");
|
||||||
|
print("temperature: %.1f °C\n", imu->getTemp());
|
||||||
print("gyro: %f %f %f\n", gyro.x, gyro.y, gyro.z);
|
print("gyro: %f %f %f\n", gyro.x, gyro.y, gyro.z);
|
||||||
print("acc: %f %f %f\n", acc.x, acc.y, acc.z);
|
print("acc: %f %f %f\n", acc.x, acc.y, acc.z);
|
||||||
imu.waitForData();
|
imu->waitForData();
|
||||||
Vector rawGyro, rawAcc;
|
Vector rawGyro, rawAcc;
|
||||||
imu.getGyro(rawGyro.x, rawGyro.y, rawGyro.z);
|
imu->getGyro(rawGyro.x, rawGyro.y, rawGyro.z);
|
||||||
imu.getAccel(rawAcc.x, rawAcc.y, rawAcc.z);
|
imu->getAccel(rawAcc.x, rawAcc.y, rawAcc.z);
|
||||||
print("raw gyro: %f %f %f\n", rawGyro.x, rawGyro.y, rawGyro.z);
|
print("raw gyro: %f %f %f\n", rawGyro.x, rawGyro.y, rawGyro.z);
|
||||||
print("raw acc: %f %f %f\n", rawAcc.x, rawAcc.y, rawAcc.z);
|
print("raw acc: %f %f %f\n", rawAcc.x, rawAcc.y, rawAcc.z);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -100,7 +100,7 @@ LogTopic logTopics[] = {
|
|||||||
LogTopic(5,
|
LogTopic(5,
|
||||||
{"voltage", &voltage},
|
{"voltage", &voltage},
|
||||||
{"temp", &temperatureRead},
|
{"temp", &temperatureRead},
|
||||||
{"imuTemp", []() { return imu.getTemp(); }}),
|
{"imuTemp", []() { return imu->getTemp(); }}),
|
||||||
};
|
};
|
||||||
|
|
||||||
void *logBuffer; // buffer for log data
|
void *logBuffer; // buffer for log data
|
||||||
|
|||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
|
||||||
// Repository: https://github.com/okalachev/flix
|
|
||||||
|
|
||||||
// Low pass filter implementation
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
template <typename T> // Using template to make the filter usable for scalar and vector values
|
|
||||||
class LowPassFilter {
|
|
||||||
public:
|
|
||||||
float alpha; // smoothing constant, 1 means filter disabled
|
|
||||||
T output;
|
|
||||||
|
|
||||||
LowPassFilter(float alpha): alpha(alpha) {};
|
|
||||||
|
|
||||||
T update(const T input) {
|
|
||||||
if (!init) {
|
|
||||||
init = true;
|
|
||||||
return output = input;
|
|
||||||
}
|
|
||||||
return output += alpha * (input - output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCutOffFrequency(float cutOffFreq, float dt) {
|
|
||||||
alpha = 1 - exp(-2 * PI * cutOffFreq * dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset() {
|
|
||||||
init = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool init = false;
|
|
||||||
};
|
|
||||||
+16
-10
@@ -18,7 +18,7 @@ Rate telemetryMotors(10);
|
|||||||
Rate telemetryIMU(15);
|
Rate telemetryIMU(15);
|
||||||
Rate telemetryTopic(10);
|
Rate telemetryTopic(10);
|
||||||
|
|
||||||
bool mavlinkConnected = false;
|
float mavlinkTime = NAN; // time of last received message
|
||||||
String mavlinkPrintBuffer;
|
String mavlinkPrintBuffer;
|
||||||
|
|
||||||
void processMavlink() {
|
void processMavlink() {
|
||||||
@@ -41,7 +41,7 @@ void sendMavlink() {
|
|||||||
sendMessage(&msg);
|
sendMessage(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mavlinkConnected) return; // send only heartbeat until connected
|
if (!valid(mavlinkTime)) return; // send only heartbeat until connected
|
||||||
|
|
||||||
if (telemetrySlow) {
|
if (telemetrySlow) {
|
||||||
mavlink_msg_extended_sys_state_pack(mavlinkSysId, MAV_COMP_ID_AUTOPILOT1, &msg,
|
mavlink_msg_extended_sys_state_pack(mavlinkSysId, MAV_COMP_ID_AUTOPILOT1, &msg,
|
||||||
@@ -128,7 +128,7 @@ void receiveMavlink() {
|
|||||||
mavlink_status_t status;
|
mavlink_status_t status;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (mavlink_parse_char(MAVLINK_COMM_0, buf[i], &msg, &status)) {
|
if (mavlink_parse_char(MAVLINK_COMM_0, buf[i], &msg, &status)) {
|
||||||
mavlinkConnected = true;
|
mavlinkTime = t;
|
||||||
handleMavlink(&msg);
|
handleMavlink(&msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -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);
|
||||||
|
|||||||
+19
-2
@@ -9,11 +9,13 @@
|
|||||||
extern int channelZero[16], channelMax[16];
|
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, wifiBroadcast, 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;
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
Preferences storage;
|
Preferences storage;
|
||||||
|
|
||||||
struct Parameter {
|
struct Parameter {
|
||||||
@@ -44,6 +46,7 @@ Parameter parameters[] = {
|
|||||||
{"CTL_Y_RATE_P", &yawRatePID.p},
|
{"CTL_Y_RATE_P", &yawRatePID.p},
|
||||||
{"CTL_Y_RATE_I", &yawRatePID.i},
|
{"CTL_Y_RATE_I", &yawRatePID.i},
|
||||||
{"CTL_Y_RATE_D", &yawRatePID.d},
|
{"CTL_Y_RATE_D", &yawRatePID.d},
|
||||||
|
{"CTL_Y_RATE_WU", &yawRatePID.windup},
|
||||||
{"CTL_Y_RATE_D_A", &yawRatePID.lpf.alpha},
|
{"CTL_Y_RATE_D_A", &yawRatePID.lpf.alpha},
|
||||||
{"CTL_R_P", &rollPID.p},
|
{"CTL_R_P", &rollPID.p},
|
||||||
{"CTL_R_I", &rollPID.i},
|
{"CTL_R_I", &rollPID.i},
|
||||||
@@ -60,6 +63,15 @@ Parameter parameters[] = {
|
|||||||
{"CTL_FLT_MODE_1", &flightModes[1]},
|
{"CTL_FLT_MODE_1", &flightModes[1]},
|
||||||
{"CTL_FLT_MODE_2", &flightModes[2]},
|
{"CTL_FLT_MODE_2", &flightModes[2]},
|
||||||
// imu
|
// imu
|
||||||
|
{"IMU_MODEL", &imuModel},
|
||||||
|
{"IMU_BUS", &imuBus},
|
||||||
|
{"IMU_PIN_SCK", &imuSckPin},
|
||||||
|
{"IMU_PIN_MISO", &imuMisoPin},
|
||||||
|
{"IMU_PIN_MOSI", &imuMosiPin},
|
||||||
|
{"IMU_PIN_CS", &imuCsPin},
|
||||||
|
{"IMU_PIN_SDA", &imuSdaPin},
|
||||||
|
{"IMU_PIN_SCL", &imuSclPin},
|
||||||
|
{"IMU_PIN_INT", &imuIntPin},
|
||||||
{"IMU_ROT_ROLL", &imuRotation.x},
|
{"IMU_ROT_ROLL", &imuRotation.x},
|
||||||
{"IMU_ROT_PITCH", &imuRotation.y},
|
{"IMU_ROT_PITCH", &imuRotation.y},
|
||||||
{"IMU_ROT_YAW", &imuRotation.z},
|
{"IMU_ROT_YAW", &imuRotation.z},
|
||||||
@@ -74,6 +86,8 @@ Parameter parameters[] = {
|
|||||||
{"EST_ACC_WEIGHT", &accWeight},
|
{"EST_ACC_WEIGHT", &accWeight},
|
||||||
{"EST_LVL_WEIGHT", &levelWeight},
|
{"EST_LVL_WEIGHT", &levelWeight},
|
||||||
{"EST_RATES_LPF_A", &ratesFilter.alpha},
|
{"EST_RATES_LPF_A", &ratesFilter.alpha},
|
||||||
|
{"EST_RATES_NF_F", &ratesNotch.frequency, setupEstimate},
|
||||||
|
{"EST_RATES_NF_BW", &ratesNotch.bandwidth, setupEstimate},
|
||||||
// motors
|
// motors
|
||||||
{"MOT_PIN_FL", &motorPins[MOTOR_FRONT_LEFT], setupMotors},
|
{"MOT_PIN_FL", &motorPins[MOTOR_FRONT_LEFT], setupMotors},
|
||||||
{"MOT_PIN_FR", &motorPins[MOTOR_FRONT_RIGHT], setupMotors},
|
{"MOT_PIN_FR", &motorPins[MOTOR_FRONT_RIGHT], setupMotors},
|
||||||
@@ -112,6 +126,7 @@ Parameter parameters[] = {
|
|||||||
{"WIFI_PORT_LOC", &udpLocalPort},
|
{"WIFI_PORT_LOC", &udpLocalPort},
|
||||||
{"WIFI_PORT_REM", &udpRemotePort},
|
{"WIFI_PORT_REM", &udpRemotePort},
|
||||||
{"WIFI_LONG_RANGE", &wifiLongRange},
|
{"WIFI_LONG_RANGE", &wifiLongRange},
|
||||||
|
{"WIFI_BROADCAST", &wifiBroadcast},
|
||||||
// espnow
|
// espnow
|
||||||
{"ESPNOW_CHANNEL", &espnowChannel},
|
{"ESPNOW_CHANNEL", &espnowChannel},
|
||||||
// mavlink
|
// mavlink
|
||||||
@@ -144,10 +159,12 @@ 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() {
|
||||||
print("Setup parameters\n");
|
print("Setup parameters\n");
|
||||||
|
setDefaults();
|
||||||
storage.begin("flix");
|
storage.begin("flix");
|
||||||
// Read parameters from storage
|
// Read parameters from storage
|
||||||
for (auto ¶meter : parameters) {
|
for (auto ¶meter : parameters) {
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
|
|
||||||
class PID {
|
class PID {
|
||||||
public:
|
public:
|
||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
LowPassFilter<float> lpf; // low pass filter for derivative term
|
LowPassFilter<float> lpf; // low pass filter for derivative term
|
||||||
|
|
||||||
PID(float p, float i, float d, float windup = 0, float dAlpha = 1, float dtMax = 0.1) :
|
PID(float p, float i = 0, float d = 0, float windup = 0, float dAlpha = 1, float dtMax = 0.1) :
|
||||||
p(p), i(i), d(d), windup(windup), lpf(dAlpha), dtMax(dtMax) {}
|
p(p), i(i), d(d), windup(windup), lpf(dAlpha), dtMax(dtMax) {}
|
||||||
|
|
||||||
float update(float error) {
|
float update(float error) {
|
||||||
|
|||||||
+2
-2
@@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
#include <soc/soc.h>
|
#include <soc/soc.h>
|
||||||
#include <soc/rtc_cntl_reg.h>
|
#include <soc/rtc_cntl_reg.h>
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+3
-1
@@ -11,6 +11,8 @@
|
|||||||
const float ONE_G = 9.80665;
|
const float ONE_G = 9.80665;
|
||||||
extern float t;
|
extern float t;
|
||||||
|
|
||||||
|
#define STRINGIFY(x) __STRINGIFY(x)
|
||||||
|
|
||||||
float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
|
float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
}
|
}
|
||||||
@@ -111,7 +113,7 @@ struct Value {
|
|||||||
class Rate {
|
class Rate {
|
||||||
public:
|
public:
|
||||||
float rate;
|
float rate;
|
||||||
float last = 0;
|
float last = -INFINITY;
|
||||||
Rate(float rate) : rate(rate) {}
|
Rate(float rate) : rate(rate) {}
|
||||||
|
|
||||||
operator bool() {
|
operator bool() {
|
||||||
|
|||||||
+5
-3
@@ -17,6 +17,7 @@ const int W_DISABLED = 0, W_AP = 1, W_STA = 2, W_ESPNOW = 3;
|
|||||||
int wifiMode = W_AP;
|
int wifiMode = W_AP;
|
||||||
|
|
||||||
int wifiLongRange = 0;
|
int wifiLongRange = 0;
|
||||||
|
int wifiBroadcast = 0; // 0 - broadcast until connected, 1 - always broadcast
|
||||||
int udpLocalPort = 14550;
|
int udpLocalPort = 14550;
|
||||||
int udpRemotePort = 14550;
|
int udpRemotePort = 14550;
|
||||||
IPAddress udpRemoteIP = "255.255.255.255";
|
IPAddress udpRemoteIP = "255.255.255.255";
|
||||||
@@ -58,13 +59,14 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WiFi.softAPgetStationNum() == 0 && !WiFi.isConnected()) return;
|
if (WiFi.softAPgetStationNum() == 0 && !WiFi.isConnected()) return;
|
||||||
|
|
||||||
udp.beginPacket(udpRemoteIP, udpRemotePort);
|
bool broadcast = wifiBroadcast || !(t - mavlinkTime < 5); // broadcast if lost connection
|
||||||
|
udp.beginPacket(broadcast ? IPAddress(255, 255, 255, 255) : udpRemoteIP, udpRemotePort);
|
||||||
udp.write(buf, len);
|
udp.write(buf, len);
|
||||||
udp.endPacket();
|
udp.endPacket();
|
||||||
}
|
}
|
||||||
@@ -113,7 +115,7 @@ void printWiFiInfo() {
|
|||||||
} else {
|
} else {
|
||||||
print("Mode: Disabled\n");
|
print("Mode: Disabled\n");
|
||||||
}
|
}
|
||||||
print("MAVLink connected: %d\n", mavlinkConnected);
|
print("MAVLink connected: %d\n", valid(mavlinkTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
void configWiFi(int mode, const char *first, const char *second) {
|
void configWiFi(int mode, const char *first, const char *second) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
+11
-3
@@ -9,7 +9,7 @@
|
|||||||
#include "quaternion.h"
|
#include "quaternion.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
|
|
||||||
extern float t, dt;
|
extern float t, dt;
|
||||||
extern float controlRoll, controlPitch, controlYaw, controlThrottle, controlMode;
|
extern float controlRoll, controlPitch, controlYaw, controlThrottle, controlMode;
|
||||||
@@ -21,6 +21,9 @@ extern float motors[4];
|
|||||||
Vector gyro, acc, imuRotation;
|
Vector gyro, acc, imuRotation;
|
||||||
Vector accBias, gyroBias, accScale(1, 1, 1);
|
Vector accBias, gyroBias, accScale(1, 1, 1);
|
||||||
LowPassFilter<Vector> gyroBiasFilter(0);
|
LowPassFilter<Vector> gyroBiasFilter(0);
|
||||||
|
int imuModel = 1, imuBus = 0;
|
||||||
|
int imuSckPin = 0, imuMisoPin = 0, imuMosiPin = 0, imuCsPin = -1, imuIntPin = -1;
|
||||||
|
int imuSdaPin = 0, imuSclPin = 0;
|
||||||
|
|
||||||
// declarations
|
// declarations
|
||||||
void step();
|
void step();
|
||||||
@@ -38,7 +41,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 +75,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 +86,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;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "estimate.ino"
|
#include "estimate.ino"
|
||||||
#include "safety.ino"
|
#include "safety.ino"
|
||||||
#include "log.ino"
|
#include "log.ino"
|
||||||
#include "lpf.h"
|
#include "filter.h"
|
||||||
#include "mavlink.ino"
|
#include "mavlink.ino"
|
||||||
#include "motors.ino"
|
#include "motors.ino"
|
||||||
#include "parameters.ino"
|
#include "parameters.ino"
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user