mirror of
https://github.com/okalachev/flix.git
synced 2026-08-16 00:38:56 +00:00
Compare commits
30
Commits
d64bf24c6d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d825652a71 | ||
|
|
37f267ecc9 | ||
|
|
3450932dce | ||
|
|
149c891cfc | ||
|
|
0512f5ce68 | ||
|
|
f12b239af9 | ||
|
|
0a377cfe6f | ||
|
|
fd8bf03cc7 | ||
|
|
3ea680605a | ||
|
|
5edac09473 | ||
|
|
7312aeff32 | ||
|
|
d65c5c0eb1 | ||
|
|
76456b778b | ||
|
|
f79c444f07 | ||
|
|
2a96f4795d | ||
|
|
6c55ab3625 | ||
|
|
97edb8e65b | ||
|
|
bfeee7a00a | ||
|
|
3f4577bb2c | ||
|
|
070eb8a0de | ||
|
|
aee43c6548 | ||
|
|
8e276bde38 | ||
|
|
a5991930d1 | ||
|
|
406f7a4af5 | ||
|
|
5ee6d91440 | ||
|
|
38925d7885 | ||
|
|
5c81181221 | ||
|
|
fd249fcaa6 | ||
|
|
8917849711 | ||
|
|
1cdc7a8641 |
+33
-16
@@ -10,30 +10,38 @@ on:
|
||||
jobs:
|
||||
build_linux:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES: 1
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install Arduino CLI
|
||||
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
|
||||
- name: Build firmware
|
||||
env:
|
||||
ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES: 1
|
||||
- name: Build firmware for ESP32
|
||||
run: make
|
||||
- name: Upload binaries
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: firmware-binary
|
||||
path: flix/build
|
||||
- name: Build firmware for ESP32-C3
|
||||
run: make BOARD=esp32:esp32:esp32c3
|
||||
- name: Build firmware for ESP32-S3
|
||||
run: make BOARD=esp32:esp32:esp32s3
|
||||
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 EXTRA='--build-property "compiler.cpp.extra_flags=-DFLIX2" --output-dir=flix/build/esp32.esp32.flix2'
|
||||
- name: Upload binaries
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: firmware-binary
|
||||
path: flix/build
|
||||
- name: Build espnow-proxy
|
||||
run: arduino-cli compile --fqbn esp32:esp32:esp32 tools/espnow-proxy
|
||||
- name: Check c_cpp_properties.json
|
||||
run: tools/check_c_cpp_properties.py
|
||||
|
||||
build_macos:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install Arduino CLI
|
||||
run: brew install arduino-cli
|
||||
- name: Build firmware
|
||||
@@ -44,7 +52,7 @@ jobs:
|
||||
build_windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install Arduino CLI
|
||||
run: choco install arduino-cli
|
||||
- name: Install Make
|
||||
@@ -64,8 +72,8 @@ jobs:
|
||||
apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget build-essential cmake g++ pkg-config gnupg2 lsb-release sudo
|
||||
- name: Install Arduino CLI
|
||||
uses: arduino/setup-arduino-cli@v1.1.1
|
||||
- uses: actions/checkout@v4
|
||||
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install Gazebo
|
||||
run: |
|
||||
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
|
||||
@@ -76,7 +84,16 @@ jobs:
|
||||
run: sudo apt-get install -y libsdl2-dev
|
||||
- name: Build simulator
|
||||
run: make build_simulator
|
||||
- uses: actions/upload-artifact@v4
|
||||
- name: Run simulator
|
||||
env:
|
||||
GAZEBO_MODEL_PATH: ${{ github.workspace }}/gazebo/models
|
||||
GAZEBO_PLUGIN_PATH: ${{ github.workspace }}/gazebo/build
|
||||
run: |
|
||||
OUT=$(timeout -k 10s 120s gzserver --verbose gazebo/flix.world 2>&1 | tee /dev/stderr)
|
||||
if echo "$OUT" | grep -Pq "\[Err\](?! \[RenderEngine)"; then
|
||||
exit 1
|
||||
fi
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: gazebo-plugin-binary
|
||||
path: gazebo/build/*.so
|
||||
@@ -88,7 +105,7 @@ jobs:
|
||||
steps:
|
||||
- name: Install Arduino CLI
|
||||
run: brew install arduino-cli
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Clean up python binaries # Workaround for https://github.com/actions/setup-python/issues/577
|
||||
run: |
|
||||
rm -f /usr/local/bin/2to3*
|
||||
|
||||
@@ -8,6 +8,7 @@ on:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
@@ -15,7 +16,7 @@ jobs:
|
||||
markdownlint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install markdownlint
|
||||
run: npm install -g markdownlint-cli2
|
||||
- name: Run markdownlint
|
||||
@@ -24,19 +25,57 @@ jobs:
|
||||
build_book:
|
||||
runs-on: ubuntu-latest
|
||||
needs: markdownlint
|
||||
env:
|
||||
BINARIES: ${{ github.event_name == 'push' && (github.ref_name == 'master' || github.ref_name == 'dev') && github.repository == 'okalachev/flix' }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install mdBook
|
||||
run: cargo install mdbook --vers 0.4.43 --locked
|
||||
- name: Build book
|
||||
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@v7
|
||||
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
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
uses: actions/upload-pages-artifact@v5
|
||||
with:
|
||||
path: docs/build
|
||||
|
||||
deploy:
|
||||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||
if: ${{ github.event_name == 'push' && github.ref_name == 'master' }}
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: true
|
||||
@@ -48,4 +87,4 @@ jobs:
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
uses: actions/deploy-pages@v5
|
||||
|
||||
@@ -10,7 +10,7 @@ jobs:
|
||||
csv_to_ulog:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Build csv_to_ulog
|
||||
run: cd tools/csv_to_ulog && mkdir build && cd build && cmake .. && make
|
||||
- name: Test csv_to_ulog
|
||||
@@ -22,13 +22,13 @@ jobs:
|
||||
pyflix:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install Python build tools
|
||||
run: pip install build
|
||||
- name: Build pyflix
|
||||
run: python3 -m build tools
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: pyflix
|
||||
path: |
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
python_tools:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install Python dependencies
|
||||
run: pip install -r tools/requirements.txt
|
||||
- name: Test csv_to_mcap tool
|
||||
@@ -46,3 +46,23 @@ jobs:
|
||||
echo -e "t,x,y,z\n0,1,2,3\n1,4,5,6" > log.csv
|
||||
./csv_to_mcap.py log.csv
|
||||
test $(stat -c %s log.mcap) -eq 883
|
||||
sloc:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: sudo apt-get install -y cloc jq
|
||||
- name: Print source lines of code
|
||||
run: cloc --by-file-by-lang flix
|
||||
- name: Checkout previous revision
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
|
||||
path: prev
|
||||
- name: Annotate total source lines
|
||||
run: |
|
||||
SLOC_CURR=$(cloc flix --json | jq -r '.SUM.code')
|
||||
SLOC_PREV=$(cloc prev/flix --json | jq -r '.SUM.code')
|
||||
DIFF=$(printf '%+d' "$((SLOC_CURR - SLOC_PREV))")
|
||||
echo "* Current SLOC: $SLOC_CURR" >> $GITHUB_STEP_SUMMARY
|
||||
echo "* Previous SLOC: $SLOC_PREV" >> $GITHUB_STEP_SUMMARY
|
||||
echo "* Diff: $DIFF" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
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*))
|
||||
|
||||
export ARDUINO_NETWORK_CONNECTION_TIMEOUT := 1h
|
||||
|
||||
build: .core .libs
|
||||
arduino-cli compile --fqbn $(BOARD) flix
|
||||
arduino-cli compile flix --fqbn $(BOARD) --build-property "build.core_debug_level=1" $(EXTRA)
|
||||
|
||||
upload: build
|
||||
arduino-cli upload --fqbn $(BOARD) -p "$(PORT)" flix
|
||||
arduino-cli upload flix --fqbn $(BOARD) -p "$(PORT)"
|
||||
|
||||
erase:
|
||||
arduino-cli burn-bootloader --fqbn $(BOARD) -p "$(PORT)" -P esptool
|
||||
@@ -27,8 +27,8 @@ libs .libs:
|
||||
touch .libs
|
||||
|
||||
upload_proxy: .core .libs
|
||||
arduino-cli compile --fqbn $(BOARD) tools/espnow-proxy
|
||||
arduino-cli upload --fqbn $(BOARD) -p "$(PORT)" tools/espnow-proxy
|
||||
arduino-cli compile tools/espnow-proxy --fqbn $(BOARD)
|
||||
arduino-cli upload tools/espnow-proxy --fqbn $(BOARD) -p "$(PORT)"
|
||||
|
||||
gazebo/build cmake: gazebo/CMakeLists.txt
|
||||
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>
|
||||
|
||||
### 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
|
||||
|
||||
The simulator is implemented using Gazebo and runs the original Arduino code:
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
* [`vector.h`](https://github.com/okalachev/flix/blob/master/flix/vector.h), [`quaternion.h`](https://github.com/okalachev/flix/blob/master/flix/quaternion.h) — библиотеки векторов и кватернионов.
|
||||
* [`pid.h`](https://github.com/okalachev/flix/blob/master/flix/pid.h) — ПИД-регулятор.
|
||||
* [`lpf.h`](https://github.com/okalachev/flix/blob/master/flix/lpf.h) — фильтр нижних частот.
|
||||
* [`filter.h`](https://github.com/okalachev/flix/blob/master/flix/filter.h) — фильтр нижних частот.
|
||||
|
||||
### Подсистема управления
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ Utility files:
|
||||
|
||||
* [`vector.h`](../flix/vector.h), [`quaternion.h`](../flix/quaternion.h) — vector and quaternion libraries.
|
||||
* [`pid.h`](../flix/pid.h) — generic PID controller.
|
||||
* [`lpf.h`](../flix/lpf.h) — generic low-pass filter.
|
||||
* [`filter.h`](../flix/filter.h) — generic low-pass filter.
|
||||
|
||||
### Control subsystem
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
+59
-26
@@ -1,20 +1,48 @@
|
||||
# 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
|
||||
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
|
||||
|
||||
You can build and upload the firmware using either **Arduino IDE** (easier for beginners) or **command line**.
|
||||
|
||||
### Arduino IDE (Windows, Linux, macOS)
|
||||
#### Arduino IDE (Windows, Linux, macOS)
|
||||
|
||||
<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.
|
||||
* `MAVLink`, version 2.0.25.
|
||||
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.
|
||||
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/).
|
||||
|
||||
@@ -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:
|
||||
|
||||
```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).
|
||||
@@ -71,15 +99,6 @@ See other available Make commands in [Makefile](../Makefile).
|
||||
|
||||
## 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
|
||||
|
||||
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:
|
||||
|
||||
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">
|
||||
|
||||
@@ -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.
|
||||
|
||||
### 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
|
||||
|
||||
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).
|
||||
|
||||
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).
|
||||
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]
|
||||
> **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:
|
||||
|
||||
@@ -333,7 +363,7 @@ 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`.
|
||||
|
||||
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
|
||||
@@ -352,7 +382,10 @@ To setup ESP-NOW communication:
|
||||
* Type: Serial.
|
||||
* Serial Port: choose the port of the proxy ESP32 board, e. g. `/dev/cu.usbserial-0001`.
|
||||
* 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
|
||||
|
||||
|
||||
@@ -4,6 +4,15 @@ 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.
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
#include "pid.h"
|
||||
#include "vector.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 RAW, ACRO, STAB, AUTO;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+9
-34
@@ -6,34 +6,9 @@
|
||||
#include "vector.h"
|
||||
#include "quaternion.h"
|
||||
#include "pid.h"
|
||||
#include "lpf.h"
|
||||
#include "filter.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
|
||||
int mode = STAB;
|
||||
bool armed = false;
|
||||
@@ -44,14 +19,14 @@ Vector ratesExtra; // feedforward rates
|
||||
Vector torqueTarget;
|
||||
float thrustTarget;
|
||||
|
||||
PID rollRatePID(ROLLRATE_P, ROLLRATE_I, ROLLRATE_D, ROLLRATE_I_LIM, RATES_D_LPF_ALPHA);
|
||||
PID pitchRatePID(PITCHRATE_P, PITCHRATE_I, PITCHRATE_D, PITCHRATE_I_LIM, RATES_D_LPF_ALPHA);
|
||||
PID yawRatePID(YAWRATE_P, YAWRATE_I, YAWRATE_D);
|
||||
PID rollPID(ROLL_P, ROLL_I, ROLL_D);
|
||||
PID pitchPID(PITCH_P, PITCH_I, PITCH_D);
|
||||
PID yawPID(YAW_P, 0, 0);
|
||||
Vector maxRate(ROLLRATE_MAX, PITCHRATE_MAX, YAWRATE_MAX);
|
||||
float tiltMax = TILT_MAX;
|
||||
PID rollRatePID(0.05, 0.2, 0.001, 0.3, 0.2);
|
||||
PID pitchRatePID(0.05, 0.2, 0.001, 0.3, 0.2);
|
||||
PID yawRatePID(0.3, 0, 0, 0.3);
|
||||
PID rollPID(6);
|
||||
PID pitchPID(6);
|
||||
PID yawPID(3);
|
||||
Vector maxRate(radians(360), radians(360), radians(360));
|
||||
float tiltMax = radians(30);
|
||||
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;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "quaternion.h"
|
||||
#include "vector.h"
|
||||
#include "lpf.h"
|
||||
#include "filter.h"
|
||||
#include "util.h"
|
||||
|
||||
Vector rates; // estimated angular rates, rad/s
|
||||
|
||||
+40
-21
@@ -4,12 +4,17 @@
|
||||
// Work with the IMU sensor
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <FlixPeriph.h>
|
||||
#include "vector.h"
|
||||
#include "lpf.h"
|
||||
#include "filter.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 gyro; // gyroscope output, rad/s
|
||||
@@ -23,22 +28,35 @@ LowPassFilter<Vector> gyroBiasFilter(0.001);
|
||||
|
||||
void setupIMU() {
|
||||
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();
|
||||
}
|
||||
|
||||
void configureIMU() {
|
||||
imu.setAccelRange(imu.ACCEL_RANGE_4G);
|
||||
imu.setGyroRange(imu.GYRO_RANGE_2000DPS);
|
||||
imu.setDLPF(imu.DLPF_MAX);
|
||||
imu.setRate(imu.RATE_1KHZ_APPROX);
|
||||
imu.setupInterrupt();
|
||||
imu->setAccelRange(IMU::ACCEL_RANGE_4G);
|
||||
imu->setGyroRange(IMU::GYRO_RANGE_2000DPS);
|
||||
imu->setDLPF(IMU::DLPF_MAX);
|
||||
imu->setRate(IMU::RATE_1KHZ_APPROX);
|
||||
imu->setupInterrupt();
|
||||
}
|
||||
|
||||
void readIMU() {
|
||||
imu.waitForData();
|
||||
imu.getGyro(gyro.x, gyro.y, gyro.z);
|
||||
imu.getAccel(acc.x, acc.y, acc.z);
|
||||
imu->waitForData();
|
||||
imu->getGyro(gyro.x, gyro.y, gyro.z);
|
||||
imu->getAccel(acc.x, acc.y, acc.z);
|
||||
calibrateGyroOnce();
|
||||
|
||||
// Apply scale and bias
|
||||
@@ -60,7 +78,7 @@ void calibrateGyroOnce() {
|
||||
|
||||
void calibrateAccel() {
|
||||
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");
|
||||
pause(8);
|
||||
@@ -94,9 +112,9 @@ void calibrateAccelOnce() {
|
||||
// Compute the average of the accelerometer readings
|
||||
acc = Vector(0, 0, 0);
|
||||
for (int i = 0; i < samples; i++) {
|
||||
imu.waitForData();
|
||||
imu->waitForData();
|
||||
Vector sample;
|
||||
imu.getAccel(sample.x, sample.y, sample.z);
|
||||
imu->getAccel(sample.x, sample.y, sample.z);
|
||||
acc = acc + sample;
|
||||
}
|
||||
acc = acc / samples;
|
||||
@@ -121,17 +139,18 @@ void printIMUCalibration() {
|
||||
}
|
||||
|
||||
void printIMUInfo() {
|
||||
imu.status() ? print("status: ERROR %d\n", imu.status()) : print("status: OK\n");
|
||||
print("model: %s\n", imu.getModel());
|
||||
print("who am I: 0x%02X\n", imu.whoAmI());
|
||||
imu->status() ? print("status: ERROR %d\n", imu->status()) : print("status: OK\n");
|
||||
print("model: %s\n", imu->getModel());
|
||||
print("who am I: 0x%02X\n", imu->whoAmI());
|
||||
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("acc: %f %f %f\n", acc.x, acc.y, acc.z);
|
||||
imu.waitForData();
|
||||
imu->waitForData();
|
||||
Vector rawGyro, rawAcc;
|
||||
imu.getGyro(rawGyro.x, rawGyro.y, rawGyro.z);
|
||||
imu.getAccel(rawAcc.x, rawAcc.y, rawAcc.z);
|
||||
imu->getGyro(rawGyro.x, rawGyro.y, rawGyro.z);
|
||||
imu->getAccel(rawAcc.x, rawAcc.y, rawAcc.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);
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ Rate telemetryRC(10);
|
||||
Rate telemetryMotors(10);
|
||||
Rate telemetryIMU(15);
|
||||
|
||||
bool mavlinkConnected = false;
|
||||
float mavlinkTime = NAN; // time of last received message
|
||||
String mavlinkPrintBuffer;
|
||||
|
||||
void processMavlink() {
|
||||
@@ -40,7 +40,7 @@ void sendMavlink() {
|
||||
sendMessage(&msg);
|
||||
}
|
||||
|
||||
if (!mavlinkConnected) return; // send only heartbeat until connected
|
||||
if (!valid(mavlinkTime)) return; // send only heartbeat until connected
|
||||
|
||||
if (telemetrySlow) {
|
||||
mavlink_msg_extended_sys_state_pack(mavlinkSysId, MAV_COMP_ID_AUTOPILOT1, &msg,
|
||||
@@ -101,7 +101,7 @@ void receiveMavlink() {
|
||||
mavlink_status_t status;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (mavlink_parse_char(MAVLINK_COMM_0, buf[i], &msg, &status)) {
|
||||
mavlinkConnected = true;
|
||||
mavlinkTime = t;
|
||||
handleMavlink(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-6
@@ -9,18 +9,20 @@
|
||||
extern int channelZero[16], channelMax[16];
|
||||
extern int rollChannel, pitchChannel, throttleChannel, yawChannel, armedChannel, modeChannel;
|
||||
extern int rcRxPin, voltagePin;
|
||||
extern int wifiMode, wifiLongRange, udpLocalPort, udpRemotePort, espnowChannel;
|
||||
extern float rcLossTimeout, descendTime;
|
||||
extern int wifiMode, wifiLongRange, wifiBroadcast, udpLocalPort, udpRemotePort, espnowChannel;
|
||||
extern float rcLossTimeout, descendTime, disarmTilt;
|
||||
extern float voltageScale;
|
||||
extern LowPassFilter<float> voltageFilter;
|
||||
|
||||
#include "config.h"
|
||||
|
||||
Preferences storage;
|
||||
|
||||
struct Parameter {
|
||||
const char *name; // max length is 15
|
||||
bool integer;
|
||||
union { float *f; int *i; }; // pointer to the variable
|
||||
float inital; // default value
|
||||
float initial; // default value
|
||||
float cache; // what's stored in flash
|
||||
void (*callback)(); // called after parameter change
|
||||
Parameter(const char *name, float *variable, void (*callback)() = nullptr) : name(name), integer(false), f(variable), callback(callback) {};
|
||||
@@ -44,6 +46,7 @@ Parameter parameters[] = {
|
||||
{"CTL_Y_RATE_P", &yawRatePID.p},
|
||||
{"CTL_Y_RATE_I", &yawRatePID.i},
|
||||
{"CTL_Y_RATE_D", &yawRatePID.d},
|
||||
{"CTL_Y_RATE_WU", &yawRatePID.windup},
|
||||
{"CTL_Y_RATE_D_A", &yawRatePID.lpf.alpha},
|
||||
{"CTL_R_P", &rollPID.p},
|
||||
{"CTL_R_I", &rollPID.i},
|
||||
@@ -60,6 +63,15 @@ Parameter parameters[] = {
|
||||
{"CTL_FLT_MODE_1", &flightModes[1]},
|
||||
{"CTL_FLT_MODE_2", &flightModes[2]},
|
||||
// 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_PITCH", &imuRotation.y},
|
||||
{"IMU_ROT_YAW", &imuRotation.z},
|
||||
@@ -112,6 +124,7 @@ Parameter parameters[] = {
|
||||
{"WIFI_PORT_LOC", &udpLocalPort},
|
||||
{"WIFI_PORT_REM", &udpRemotePort},
|
||||
{"WIFI_LONG_RANGE", &wifiLongRange},
|
||||
{"WIFI_BROADCAST", &wifiBroadcast},
|
||||
// espnow
|
||||
{"ESPNOW_CHANNEL", &espnowChannel},
|
||||
// mavlink
|
||||
@@ -128,14 +141,16 @@ Parameter parameters[] = {
|
||||
// safety
|
||||
{"SF_RC_LOSS_TIME", &rcLossTimeout},
|
||||
{"SF_DESCEND_TIME", &descendTime},
|
||||
{"SF_DISARM_TILT", &disarmTilt},
|
||||
};
|
||||
|
||||
void setupParameters() {
|
||||
print("Setup parameters\n");
|
||||
setDefaults();
|
||||
storage.begin("flix");
|
||||
// Read parameters from storage
|
||||
for (auto ¶meter : parameters) {
|
||||
parameter.inital = parameter.getValue();
|
||||
parameter.initial = parameter.getValue();
|
||||
if (storage.isKey(parameter.name)) {
|
||||
parameter.setValue(storage.getFloat(parameter.name));
|
||||
}
|
||||
@@ -196,10 +211,10 @@ void printParameters(const char *filter) {
|
||||
for (auto ¶meter : parameters) {
|
||||
if (strncasecmp(parameter.name, filter, strlen(filter))) continue;
|
||||
|
||||
if (floatEquals(parameter.getValue(), parameter.inital)) { // parameter changed
|
||||
if (floatEquals(parameter.getValue(), parameter.initial)) { // parameter changed
|
||||
print("%-15s %-13g\n", parameter.name, parameter.getValue());
|
||||
} else {
|
||||
print("%-15s %-13g [%g]\n", parameter.name, parameter.getValue(), parameter.inital);
|
||||
print("%-15s %-13g [%g]\n", parameter.name, parameter.getValue(), parameter.initial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lpf.h"
|
||||
#include "filter.h"
|
||||
|
||||
class PID {
|
||||
public:
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
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 = INFINITY, float dAlpha = 1, float dtMax = 0.1) :
|
||||
p(p), i(i), d(d), windup(windup), lpf(dAlpha), dtMax(dtMax) {}
|
||||
|
||||
float update(float error) {
|
||||
|
||||
+2
-2
@@ -5,11 +5,11 @@
|
||||
|
||||
#include <soc/soc.h>
|
||||
#include <soc/rtc_cntl_reg.h>
|
||||
#include "lpf.h"
|
||||
#include "filter.h"
|
||||
#include "util.h"
|
||||
|
||||
float voltage = NAN;
|
||||
LowPassFilter<float> voltageFilter(0.2);
|
||||
LowPassFilter<float> voltageFilter(1);
|
||||
int voltagePin = -1;
|
||||
float voltageScale = 2;
|
||||
|
||||
|
||||
+15
-1
@@ -8,10 +8,12 @@ extern float controlRoll, controlPitch, controlThrottle, controlYaw;
|
||||
|
||||
float rcLossTimeout = 1;
|
||||
float descendTime = 10;
|
||||
float disarmTilt = radians(120);
|
||||
|
||||
void failsafe() {
|
||||
rcLossFailsafe();
|
||||
autoFailsafe();
|
||||
tiltFailsafe();
|
||||
}
|
||||
|
||||
// RC loss failsafe
|
||||
@@ -36,7 +38,7 @@ void descend() {
|
||||
// Allow pilot to interrupt automatic flight
|
||||
void autoFailsafe() {
|
||||
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
|
||||
if (mode == AUTO && invalid(controlMode)) mode = STAB; // regain control by the pilot
|
||||
}
|
||||
@@ -45,3 +47,15 @@ void autoFailsafe() {
|
||||
yaw = controlYaw;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public:
|
||||
class Rate {
|
||||
public:
|
||||
float rate;
|
||||
float last = 0;
|
||||
float last = -INFINITY;
|
||||
Rate(float rate) : rate(rate) {}
|
||||
|
||||
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 wifiLongRange = 0;
|
||||
int wifiBroadcast = 0; // 0 - broadcast until connected, 1 - always broadcast
|
||||
int udpLocalPort = 14550;
|
||||
int udpRemotePort = 14550;
|
||||
IPAddress udpRemoteIP = "255.255.255.255";
|
||||
@@ -58,13 +59,14 @@ void sendWiFi(const uint8_t *buf, int len) {
|
||||
espnow.write(buf, len);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.endPacket();
|
||||
}
|
||||
@@ -113,7 +115,7 @@ void printWiFiInfo() {
|
||||
} else {
|
||||
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) {
|
||||
|
||||
+5
-2
@@ -9,7 +9,7 @@
|
||||
#include "quaternion.h"
|
||||
#include "Arduino.h"
|
||||
#include "wifi.h"
|
||||
#include "lpf.h"
|
||||
#include "filter.h"
|
||||
|
||||
extern float t, dt;
|
||||
extern float controlRoll, controlPitch, controlYaw, controlThrottle, controlMode;
|
||||
@@ -21,6 +21,9 @@ extern float motors[4];
|
||||
Vector gyro, acc, imuRotation;
|
||||
Vector accBias, gyroBias, accScale(1, 1, 1);
|
||||
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
|
||||
void step();
|
||||
@@ -63,6 +66,7 @@ void failsafe();
|
||||
void rcLossFailsafe();
|
||||
void descend();
|
||||
void autoFailsafe();
|
||||
void tiltFailsafe();
|
||||
int parametersCount();
|
||||
const char *getParameterName(int index);
|
||||
float getParameter(int index);
|
||||
@@ -73,7 +77,6 @@ void resetParameters();
|
||||
|
||||
// mocks
|
||||
void setLED(bool on) {};
|
||||
void calibrateGyro() { print("Skip gyro calibrating\n"); };
|
||||
void calibrateAccel() { print("Skip accel calibrating\n"); };
|
||||
void printIMUCalibration() { print("cal: N/A\n"); };
|
||||
void printIMUInfo() {};
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "estimate.ino"
|
||||
#include "safety.ino"
|
||||
#include "log.ino"
|
||||
#include "lpf.h"
|
||||
#include "filter.h"
|
||||
#include "mavlink.ino"
|
||||
#include "motors.ino"
|
||||
#include "parameters.ino"
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
initNode();
|
||||
Serial.begin(0);
|
||||
setupParameters();
|
||||
rcRxPin = 1; // set rc pin to enable rc reading
|
||||
gzmsg << "Flix plugin loaded" << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
// Mocks
|
||||
int wifiMode = 1;
|
||||
int wifiLongRange = 0;
|
||||
int wifiBroadcast = 0;
|
||||
int espnowChannel = 6;
|
||||
const int W_DISABLED = 0, W_AP = 1, W_STA = 2, W_ESPNOW = 3;
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ class Flix:
|
||||
time.sleep(1)
|
||||
|
||||
@staticmethod
|
||||
def _mavlink_to_flu(v: List[float]) -> List[float]:
|
||||
def _mavlink_to_flu(v: Sequence[float]) -> List[float]:
|
||||
if len(v) == 3: # vector
|
||||
return [v[0], -v[1], -v[2]]
|
||||
elif len(v) == 4: # quaternion
|
||||
@@ -252,8 +252,8 @@ class Flix:
|
||||
raise ValueError(f'List must have 3 (vector) or 4 (quaternion) elements')
|
||||
|
||||
@staticmethod
|
||||
def _flu_to_mavlink(v: List[float]) -> List[float]:
|
||||
return Flix._mavlink_to_flu(v)
|
||||
def _flu_to_mavlink(v: Sequence[float]) -> List[float]:
|
||||
return Flix._mavlink_to_flu(v) # flu to mavlink is the same as mavlink to flu
|
||||
|
||||
def _command_send(self, command: int, params: Sequence[float]):
|
||||
if len(params) != 7:
|
||||
@@ -320,13 +320,13 @@ class Flix:
|
||||
def set_armed(self, armed: bool):
|
||||
self._command_send(mavlink.MAV_CMD_COMPONENT_ARM_DISARM, (1 if armed else 0, 0, 0, 0, 0, 0, 0))
|
||||
|
||||
def set_position(self, position: List[float], yaw: Optional[float] = None, wait: bool = False, tolerance: float = 0.1):
|
||||
def set_position(self, position: Sequence[float], yaw: Optional[float] = None, wait: bool = False, tolerance: float = 0.1):
|
||||
raise NotImplementedError('Position control is not implemented yet')
|
||||
|
||||
def set_velocity(self, velocity: List[float], yaw: Optional[float] = None):
|
||||
def set_velocity(self, velocity: Sequence[float], yaw: Optional[float] = None):
|
||||
raise NotImplementedError('Velocity control is not implemented yet')
|
||||
|
||||
def set_attitude(self, attitude: List[float], thrust: float):
|
||||
def set_attitude(self, attitude: Sequence[float], thrust: float):
|
||||
if len(attitude) == 3:
|
||||
attitude = Quaternion([attitude[0], attitude[1], attitude[2]]).q # type: ignore
|
||||
elif len(attitude) != 4:
|
||||
@@ -339,7 +339,7 @@ class Flix:
|
||||
[attitude[0], attitude[1], attitude[2], attitude[3]],
|
||||
0, 0, 0, thrust)
|
||||
|
||||
def set_rates(self, rates: List[float], thrust: float):
|
||||
def set_rates(self, rates: Sequence[float], thrust: float):
|
||||
if len(rates) != 3:
|
||||
raise ValueError('Rates must be [roll_rate, pitch_rate, yaw_rate]')
|
||||
if not (0 <= thrust <= 1):
|
||||
@@ -351,7 +351,7 @@ class Flix:
|
||||
[1, 0, 0, 0],
|
||||
rates[0], rates[1], rates[2], thrust)
|
||||
|
||||
def set_motors(self, motors: List[float]):
|
||||
def set_motors(self, motors: Sequence[float]):
|
||||
if len(motors) != 4:
|
||||
raise ValueError('motors must have 4 values')
|
||||
if not all(0 <= m <= 1 for m in motors):
|
||||
|
||||
Reference in New Issue
Block a user