10 KiB
Симуляція з апаратним забезпеченням в контурі (HITL)
:::warning HITL is community supported and maintained. Це може працювати або не працювати з поточними версіями PX4.
Дивіться Встановлення інструментарію для інформації про середовища та інструменти, що підтримуються основною командою розробників. :::
Апаратне забезпечення в контурі (HITL або HIL) режим симуляції в якому звичайна прошивка PX4 виконується на реальному пристрої польотного контролера. Цей підхід має перевагу у вигляді можливості тестування більшості коду для польоту на реальному апаратному забезпеченні.
PX4 supports HITL for multicopters (using jMAVSim or Gazebo Classic) and VTOL (using Gazebo Classic).
Планери сумісні з HITL
The set of compatible airframes vs simulators is:
| Планер | SYS_AUTOSTART |
Gazebo Classic | jMAVSim |
|---|---|---|---|
| HIL Quadcopter X | 1001 | Y | Y |
| HIL Standard VTOL QuadPlane | 1002 | Y |
Середовище симуляції HITL
У симуляції з апаратним забезпеченням у контурі (HITL) звичайна прошивка PX4 виконується на реальному обладнані. JMAVSim або Gazebo Classic (які працюють на комп'ютері розробки) підключені до пристрою польотного контролера через USB/UART. The simulator acts as gateway to share MAVLink data between PX4 and QGroundControl.
:::info The simulator can also be connected via UDP if the flight controller has networking support and uses a stable, low-latency connection (e.g. a wired Ethernet connection - WiFi is usually not sufficiently reliable). For example, this configuration has been tested with PX4 running on a Raspberry Pi connected via Ethernet to the computer (a startup configuration that includes the command for running jMAVSim can be found in px4_hil.config). :::
Діаграма нижче показує середовище симуляції:
- A HITL configuration is selected (via QGroundControl) that doesn't start any real sensors.
- jMAVSim or Gazebo Classic are connected to the flight controller via USB.
- The simulator is connected to QGroundControl via UDP and bridges its MAVLink messages to PX4.
- Gazebo Classic and jMAVSim can also connect to an offboard API and bridge MAVLink messages to PX4.
- (Optional) A serial connection can be used to connect Joystick/Gamepad hardware via QGroundControl.
HITL у порівнянні з SITL
SITL працює на комп'ютері розробки в модельованому середовищі та використовує прошивку спеціально створену для цього середовища. Крім драйверів симуляції для забезпечення підроблених даних середовища від симулятора система поводиться як зазвичай.
На противагу, HITL виконує звичайну прошивку PX4 в "режимі HITL" на звичайному обладнані. Дані симуляції потрапляють в систему в іншій точці ніж для SITL. Основні модулі на кшталт командного або датчиків мають режими HITL, що оминають частину звичайної функціональності при старті.
Підсумовуючи, HITL виконує PX4 на реальному обладнанні за допомогою стандартної прошивки, а SITL фактично більше виконує стандартний системний код.
Налаштування HITL
Check if HITL is in Firmware
The module required for HITL (pwm_out_sim) is not built into all PX4 firmware by default.
To check if the module is present on your Flight Controller:
-
Open QGroundControl
-
Open Analyze Tools > Mavlink Console.
-
Type the following command in the console:
pwm_out_sim status -
If the returned value is
nsh: pwm_out_sim: command not found, then you don't have the module installed.
If pwm_out_sim is not present you will need to add it to the firmware in order to use HITL simulation.
Adding HITL modules to the Firmware
Add the following key to the configuration file for your flight controller to include the required module (for an example see boards/px4/fmu-v6x/default.px4board). Then re-build the firmware and flash it to the board.
CONFIG_MODULES_SIMULATION_PWM_OUT_SIM=y
You can alternatively use the following command to launch a GUI configuration tool, and interactively enable them at the path: modules > Simulation > pwm_out_sim. For example, to update fmu-v6x you would use:
make px4_fmu-v6x boardconfig
Конфігурація PX4
-
Connect the autopilot directly to QGroundControl via USB.
-
Вибір планера
- Open Setup > Airframes
- Select a compatible airframe you want to test. Then click Apply and Restart on top-right of the Airframe Setup page.
-
Calibrate your Manual Controller (RC or Joystick), if needed.
-
Налаштування UDP
-
(Optional) Configure your manual controller priority and failsafe:
- Enable a mode in
COM_RC_IN_MODEthat enables and prioritises the controllers you want to use. The defaultRC or MAVLink keep firstshould work if you plan to only have a Joystick (no RC). - You can set NAV_RCL_ACT to disable manual control loss failsafe while flying in a simulation.
:::tip The QGroundControl User Guide also has instructions on Joystick and Virtual Joystick setup.
- Enable a mode in
:::
Once configuration is complete, close QGroundControl and disconnect the flight controller hardware from the computer.
Налаштування відповідних симуляторів
Дотримуйтесь відповідних кроків для певного симулятора в наступних розділах.
Gazebo Classic
:::info Make sure QGroundControl is not running! :::
-
Build PX4 with Gazebo Classic (in order to build the Gazebo Classic plugins).
cd <PX4-Autopilot clone> DONT_RUN=1 make px4_sitl_default gazebo-classic -
Open the vehicle model's sdf file (e.g. Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris_hitl/iris_hitl.sdf).
-
Replace the
serialDeviceparameter (/dev/ttyACM0) if necessary.::: info The serial device depends on what port is used to connect the vehicle to the computer (this is usually
/dev/ttyACM0). An easy way to check on Ubuntu is to plug in the autopilot, open up a terminal, and typedmesg | grep "tty". Останній показаний пристрій і буде тим що потрібно.
:::
-
Налаштуйте змінні середовища:
source Tools/simulation/gazebo-classic/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_defaultта запустіть Gazebo Classic в режимі HITL:
gazebo Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/hitl_iris.world -
Start QGroundControl. Воно повинно автоматично підключитися до PX4 та Gazebo Classic.
jMAVSim (тільки квадрокоптер)
:::info Make sure QGroundControl is not running! :::
-
Під'єднайте політний контролер до комп'ютера та дочекайтесь коли він завантажиться.
-
Запустіть jMAVSim в режимі HITL:
./Tools/simulation/jmavsim/jmavsim_run.sh -q -s -d /dev/ttyACM0 -b 921600 -r 250::: info Replace the serial port name
/dev/ttyACM0as appropriate. On macOS this port would be/dev/tty.usbmodem1. На Windows (включно з Cygwin) це буде COM1 або інший порт - перевірте з'єднання в менеджері пристроїв Windows.
:::
- Start QGroundControl. Воно повинно автоматично підключитися до PX4 та jMAVSim.
Політ за автономним завданням у HITL
You should be able to use QGroundControl to run missions and otherwise control the vehicle.
