CineRat 04 Software Installation and Setup - tudelft/CineRatDrone GitHub Wiki

I'll start with RPi setup, then FC installation, then RC setup, then Groundstation. ONLY UBUNTU 22.04 SUPPORTED.

Raspberry Pi installation

Just flash the latest image of Racebian from https://surfdrive.surf.nl/files/index.php/s/kndkZOelKWptZtV as normal (image is generated from https://github.com/tblaha/racebian). It provides most software packages necessary to interface with UART and Wifi. However, it doesn't include the custom software to relay optitrack data yet; we'll have to install that manually for now. The concept is to make the Raspberry-pi as stateless as possible, that means that you should never have to login to it and do stuff. Everything should be automated from scripts of the ground-station laptop.

Everything below is lifted from the README.md. There are some additional cool features in the repo like seamlessly cross-compiling c-make projects using docker, and deploying them on the PI using rsync. This can probably also be used to deploy simulink applications on the PI in case the native mechanisms somehow don't work (zero 2W does not seem officially supported).

Flash image

For instance, if your SD card is /dev/mmcblk1

sudo umount /dev/mmcblk1*
sudo dd bs=4M if=<path/to/the/image.img> of=/dev/mmcblk1 status=progress

Configure Wifi Access Point

Re-insert the SD card into your Laptop, then change the configuration of the wifi access point at /etc/hostapd/hostapd.conf:

channel=11 # or 9, or 10. results in better performance in our typical environment

ssid=<change accespoint name to whatever you like>

Then unmount the SD card and boot the PI. You can connect to the Wifi with password betaflight.

SSH Access to the pi

Just do ssh [email protected] with password pi. In normal operation this shouldnt be needed.

If you need to pi to have internet access (for instance to install additional packages), you'll need to enable forwarding through your laptop with a script in the racebian repo, that you need to run on your laptop (see README.md):

cd racebian
sudo make install-pi-tools
sudo pi-routing-up 10.0.0.1

Ground Station installation

The ground-station is a serial of commandline tools that use an Optitrack Client to receive data from the Optitrack Motive computer via LAN, process it (coordinate frames, frequency, filtering, velocity calculation, logging, ...) and send it to the pi. It also includes a utility to then forward it from the pi to the flight controller.

Recently, there have been efforts to make a single-source Optitrack Client for multiple transport- and application-layer protocols (ROS, Paparazzi). This client (github.com/tudelft/UnifiedOptitrackClients) is used here as well.

Install all of the above by following the README at https://github.com/tudelft/indiflight_groundstation.

INDIflight configurator

I made a few changes to the configurator to support the new logging fields, the new uart interface and (in the future) a new INDI configuration page.

Download from https://github.com/tblaha/indiflight-configurator/tags. Use the .deb for Ubuntu, and the .apk for Android. Windows/MAC untested.

sudo dpkg -i path/to/package.deb

Flashing INDIflight

INDIflight firmware provides:

  • INDI controller, similar to paparazzi
  • Position/Velocity controller for multirotors
    • Estimation of pos/vel fuses IMU and Optitrack is done with a simple PI observer; quite handwavy.
    • Note: This mode could probably also be implemented with the standard PID controllers (bypassing the new INDI controller), but as of yet, it only works with INDI attitude/thrust control because it allows tracking a body-acceleration setpoint.
  • Provides uplink/downlink interface via UART, using a custom high-speed protocol github.com/tblaha/pi-protocol
    • existing interface MSP didn't seem fast or flexible enough, so something clean and standalone was made. However, it would have been better to use Alessandro's UART protocol which is similarly fast, but also supports a checksum to flag broken data.
    • #todo This could still be done with relatively little effort.
  • in near future: EKF for state estimation. Current state estimation is inaccurate for attitude for trajectories with non-zero acceleration DC component. PI observer for velocity and position is also inaccurate sometimes.

However, this is still very experimental software. Make sure your disarm switch works and take appropriate safety measures. Most of the decade-long development of the PID logic in Betaflight has been thrown out the window and with it likely some robustness in edge-cases.

There isn't yet a nice build system. You will have to build manually (sounds worse than it is). ( #todo: we can probably adapt betaflight's cloud build system).

Prepare your computer

sudo apt install make build-essential gcc-arm-none-eabi binutils-arm-none-eabi tmux

Download the code from [email protected]:tudelft/indiflight.git

git clone -b indi --recurse-submodules -j8 [email protected]:tudelft/indiflight.git

Build

The build arguments (ie. which components should be compiled into the firmware) should be saved in ./make/local.mk, this file is personal (and gitignored) and should be tailored to your flight controller set-up. For the MATEKSYS H743 SLIM V3, it should contain:

### Basic config
TARGET = STM32H743
EXTRA_FLAGS = -D'BUILD_KEY=4880cd41e59e44642e41c3f6344b3993' -D'RELEASE_NAME=4.4.2' -D'BOARD_NAME=MATEKH743' -D'MANUFACTURER_ID=MTKS' -DCLOUD_BUILD -DUSE_GYRO -DUSE_GYRO_SPI_ICM42605 -DUSE_GYRO_SPI_ICM42688P -DUSE_GYRO_SPI_MPU6000 -DUSE_GYRO_SPI_MPU6500 -DUSE_ACC -DUSE_ACC_SPI_ICM42605 -DUSE_ACC_SPI_ICM42688P -DUSE_ACC_SPI_MPU6000 -DUSE_ACC_SPI_MPU6500 -DUSE_DSHOT -DUSE_GPS -DUSE_LED_STRIP -DUSE_MAX7456 -DUSE_OSD -DUSE_OSD_HD -DUSE_OSD_SD -DUSE_PINIO -DUSE_BLACKBOX -DUSE_SDCARD -DUSE_SERIALRX -DUSE_SERIALRX_SBUS -DUSE_SERIALRX_CRSF -DUSE_TELEMETRY -DUSE_TELEMETRY_SMARTPORT

# indi config:
EXTRA_FLAGS += -DUSE_INDI -DUSE_OMEGA_DOT_FEEDBACK
EXTRA_FLAGS += -DUSE_INDI_PROFILE_CINERAT

### Extra Options
# telemetry config:
EXTRA_FLAGS += -DUSE_TELEMETRY_PI -DPI_STATS -DPI_USE_PRINT_MSGS -DUSE_GPS_PI
# higher level controllers
EXTRA_FLAGS += -DUSE_POS_CTL -DUSE_VEL_CTL

Now, you can just build with the command make from the root of the indiflight repository.

Flash

Betaflight/INDIflight configurator -- USB on Ground Station Laptop

Go to the firmware flasher, click "Load Firmware (Local)" and grab the compiled ./obj/indiflight_5.0.0_STM32H743.hex. This should work like flashing any other version of betaflight.

Commandline -- via USB on Raspberry PI

  • Connect FC to Raspberry via USB
  • Connect to the raspberry pi wifi with your laptop
  • Run make remote_flash_dfu from indiflight repo

Commandline -- via SWD

Flashing over SWD is faster and more convenient. Also it doesn't require any USB.

  • Ensure that the raspberry pi has been connected to the SWD interface of the flight controller
  • Connect to the raspberry pi wifi with your laptop
  • Run make remote_flash_swd from the indiflight repo

INDIflight setup

For the MATEK743 on the CineRat, you can just load the file BTFL_cli_20240314_MATEKH743_CineRat.txt in the Presets tab of the configurator, after loading the "Custom defaults" if prompted. If you are not prompted when connecting the configurator, click "Reset Settings" in the Setup page before loading in the preset file, just to be sure. This should make your quad identical to my quad.

For verification and for configuring other flight controllers, here are some screenshots:

Ports

Note: "PI" will not show up if you are using Betaflight Configurator. If you loaded the preset file then it should still be configured, however, even if it doesn't show. GPS is optional, smartport telemetry is also optional.

Configuration

Beeper configuration to taste. If you use PID loop frequency (also INDI loop frequency) higher than 2kHz, check CPU load in CLI using command tasks and also reduce the Blackbox logging divider in the Blackbox tab (otherwise blackbox will also log faster).

Power & Batter

Amp scale unverified, probably inaccurate.

Failsafe

Stage 2 guard time 0.5 is pretty low, but i'd like to be more safe than sorry.

PID tuning

A couple of parameters here also affect INDIflight:

  • PID Profile
    • Throttle and Motor Settings
      • Motor Output Limit
      • Thrust Linearization
  • Rateprofile Settings
    • All are relevant, if flying in acro mode. None are relevant in any other mode.
    • Set to taste, otherwise leave Betaflight default ("actual" rates)
  • Filter Settings
    • All are relevant for INDI flight. I'm using quite low cutoff values for now, feel free to experiment

INDI

has no effect for now

Receiver

Modes

I'm using PREARM for added safety.

Adjustments --> nothing to see here

GPS

Motors

NOTE: remove all propellers and check ordering and direction of the motors (see preflight checklists)

OSD --> nothing to see here

Video Transmitter --> nothing to see here

Sensors --> nothing to see here

Tethered Logging --> nothing to see here

Blackbox

Logging above 500Hz may be spotty. You can try reducing the load by de-selecting some data. Non-critical data is e.g. GPS, Magneto, Battery, EKF, PID, setpoint, debug, RSSI, RC (if not flying manual), position (if not flying with position).

See list of known-good SD cards in CineRat -- 02 Parts List and 3D prints and instructions at #Optional -- INDIflight blackbox for logs.

RC remote setup

Only covering EdgeTX remote with FrSky R-XSR receiver here:

Create a new model and setup channels and switches as shown below. This is pretty close to the "Paparazzi" model found on some RCs in the MAVLAB, so that should be copied when setting up the new model. (CH1 Ail not shown, same as CH2 Ele). Make sure to select sticks marked by the symbol in front on Ele, Thr and Rud, and not inputs marked by "I". Also make sure to invert SF, SE and SC (as shown by the - signs)

(CH8 not shown, same as CH7)

If you connected and enabled smartport telemetry, make sure you have bound your RC to the receiver. Then, in Telemtry (page 10), click detect sensors. Then in DISPLAY:

Optional -- INDIflight blackbox for logs

To see the new fields in the right units, better attitude visualization and more, get the fork of blackbox viewer (Ubuntu only tested): https://github.com/tblaha/blackbox-log-viewer/releases/tag/v3.7.0-indi2

sudo dpkg -i path/to/package.deb
Important notes
  1. Use a known-good SD card to save you frustrations CineRat -- 02 Parts List and 3D prints.
  2. Format the SD card with the official SD card association formatting tool available for Windows and Linux (use sudo) https://www.sdcard.org/downloads/formatter/
  3. It is imperative that you follow this procedure when downloading logs. If you don't, then the SD card WILL be corrupted the next time you fly and you won't have logs (at least on the MATEKSYS with Ubuntu 22.04. We don't know why)
    1. Connect the flight controller via USB
    2. Bring device into MSC mode (blackbox tab in configurator)
    3. Mount the SD card and download logs
    4. Unmount/eject and do not remount
    5. Power-cycle the flight controller

This is also the procedure adopted in the CineRat -- 05 Flying Instructions and Checklists#After-flight checklist -- No USB or SWD connection

If you have a USB connection from the Flight Controller to the Raspberry Pi, then there is a script to automate points 3.3. through 3.5. which has fixed corruption issues for us completely.

Check the readme of indiflight_groundstation and CineRat -- 05 Flying Instructions and Checklists#After-flight checklist -- USB connection available

⚠️ **GitHub.com Fallback** ⚠️