SITL
SITL in Gazebo
SITL (software in the loop) simulator allows you to run Betaflight without any hardware.
Install Gazebo
Official Installation
Please also check Vehicle Gateway
Build Betaflight
Run make TARGET=SITL
Betaflight Web App
Starting from Betaflight 4.6 online configurator is required which uses websockets for communication with SITL.
To setup and configure a proxy use the following instructions in a new terminal session:
git clone git@github.com:novnc/websockify-other.git
cd websockify-other/c
make
./websockify 127.0.0.1:6761 127.0.0.1:5761
Establish a connection using address ws://127.0.0.1:6761
.
Settings
To avoid the simulation speed slowing down, it is suggested to set some settings, shown below:
In configuration
page:
ESC/Motor
:PWM
, disableMotor PWM speed Sparted from PID speed
PID loop frequency
as high as it can.
Start and Run
- Start Betaflight:
./obj/main/betaflight_SITL.elf
- Start Gazebo:
gazebo --verbose ./iris_arducopter_demo.world
- Connect your transmitter and fly/test, used app to send
MSP_SET_RAW_RC
, see code.
Betaflight -> Gazebo udp://127.0.0.1:9002
Gazebo -> Betaflight udp://127.0.0.1:9003
UARTx will bind on tcp://127.0.0.1:576x
when the port has been opened.
eeprom.bin
, size 8192 Byte, is for config saving.
Size can be changed in src/main/target/SITL/pg.ld
>> __FLASH_CONFIG_Size
SITL in RealFlight 9
RealFlight is one of the best commercial RC simulators with accurate airplane, helicopter, and multirotor simulations. ArduPilot also offers RealFlight SITL. To use it you may need to purchase it on Steam or official website.
Setup
To let Betaflight SITL work with RealFlight, you need Windows 10 or Windows 11 with WSL. Ubuntu 20.04 in WSL2 on Windows 11 x64 is tested. RealFlightBridge is also required.
On WSL2, you need to configure the Betaflight following document here.
Build Betaflight with
$ make TARGET=SITL
On Windows, download RealFlightBridge by
$ git clone https://github.com/xuhao1/RealFlightBridge.git
Import the quadcopter for RealFlight and Betaflight at models/Quadcopter X Betaflight - flightaxis_AV.RFX in RealFlightBridge. A detailed guide for improtanting can be found here. Moreover, update the setting of RealFlight to allow API.
You also need to prepare a controller for running SITL. We recommend to use transmitter with OpenTX/EdgeTX as a game controller. In addition, mixers of channel 5 and 6 should be mapped to two switches for arming and changing mode.
SITL
To running SITL, you may need to:
-
Open and select the newly improted model Quadcopter X Betaflight - flightaxis in RealFlight.
You need to restart RealFlight after you edit the model in RealFlight!
-
Starting the RealFlightBridge in Windows by
$ python betaflight_bridge.py
You must start RealFlightBridge in Windows before start the Betaflight SITL.
-
Start the Betaflight SITL. First you need to get the Windows' IP in WSL. In WSL enter
$ (ipconfig.exe | grep 'vEthernet (WSL)' -A4 | cut -d":" -f 2 | tail -n1 | sed -e 's/\s*//g')
172.19.32.1
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.19.41.192 netmask 255.255.240.0 broadcast 172.19.47.255
inet6 fe80::215:5dff:fea4:215d prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:a4:21:5d txqueuelen 1000 (Ethernet)
RX packets 219079 bytes 32440158 (32.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 145744 bytes 10533796 (10.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0172.19.32.1 is the example output of your Windows IP and 172.19.41.192 is your WSL IP. These IPs change every time you reboot the computer.
Then go to the Betaflight root and start the SITL with this IP.
$ cd ~/develop/betaflight/
$ ./obj/main/betaflight_SITL.elf 172.19.32.1
The SITL will output to IP 172.19.32.1:9002 (Gazebo) and 172.19.32.1:9001 (RealFlightBridge)
[system]Init...
init PwmOut UDP link to gazebo 172.19.32.1:9002...0
init PwmOut UDP link to RF9 172.19.32.1:9001...0
start UDP server @9003...0
start UDP server for RC input @9004...0
[FLASH_Unlock] loaded 'eeprom.bin', size = 32768 / 32768
[timer]Init...
[data]new fdm 136 t:182.834571 from 0.0.0.0:0
[data]new rc 40: t:182.834571 AETR: 1498 1501 1105 1501 AUX1-4: 1100 1899 1899 1100
bind port 5761 for UART1
unusedPinsInitThen you can open the Betaflight Configurator on Windows to connect to RealFlight via WSL IP.
After connect to Betaflight you need to apply this DIFF file and set the arming switch with your controller.
-
Finally, you can arm and take-off the Quadcopter with Betaflight SITL in RealFlight with your controller.
Customize
If you want to create your own model and extend the SITL, please refer to this guide and this document.