Repository navigation
Development
Assets/_Project/Scripts/ DroneSim assembly, namespace DroneSim
Bridge/ Px4HilBridge (PX4 connection, lockstep), MavlinkCodec
Vehicle/ VehicleSpec (JSON format, checks, summary), VehicleBuilder, VehicleLoader,
Rotor, Wing, ControlSurface, VehicleActuators, ManualControl (keyboard flying)
Sensors/ ImuModel, SensorDelayBuffer, ROS publishers (cameras, ground truth)
World/ GeoOrigin (home, GPS), WorldMagneticModel, Wind
Core/ SimSettings, ROSSettings (sim-only topic names), SimConfig (sim_config.json), ROSClock,
ROSPublisher base, SimulationResetManager, CommandLineOptions (player options)
UserCamera/ Chase and free cameras
Utils/ Noise generators
Assets/Editor/DroneSim/ SceneBuilder (Flight.unity)
Assets/StreamingAssets/ sim_config.json (cameras), vehicles/ (vehicle specs)
Assets/Tests/EditMode/ Unit tests
Assets/Tests/PlayMode/ Flight scene and PX4 bridge tests (FakePx4 plays PX4's side)
tools/ px4_flight_test.py, px4_airframe.py, sim_smoke_test.py,
coverage_summary.py; tests/ has their unit tests
missions/ QGroundControl mission for the quadplane
Scene-wide components (SimSettings, ROSSettings, GeoOrigin, Wind) live on the Managers
object and are reached through a static Instance. The vehicle is built at startup from its spec
and reached through SimSettings.Vehicle; VehicleLoader.Loaded holds the spec.
Everything about the aircraft (mass properties, rotors with their motor lag and drag, wing, body drag, control surfaces, IMU and camera
mounts, PX4 airframe) is in its spec under Assets/StreamingAssets/vehicles/, documented in
Vehicles. The scene is not involved; see Scenes for what is.
Assets/StreamingAssets/sim_config.json, read at startup. In a build it is in
drone-sim_Data/StreamingAssets/ (Windows, Linux) or
drone-sim.app/Contents/Resources/Data/StreamingAssets/ (macOS), so it can be edited without
rebuilding. --config PATH uses another file (Standalone build).
One entry per camera, matched by name to a camera mount in the vehicle spec:
| Field | Meaning |
|---|---|
name |
Camera mount name in the spec: ForwardCamera or DownCamera in the shipped vehicles |
topic |
Image topic. sensor_msgs/CameraInfo goes on camera_info next to it |
frameId |
frame_id in the image and camera info headers |
width, height
|
Resolution in pixels |
rate |
Publish rate in Hz |
verticalFov |
Vertical field of view in degrees. Intrinsics follow from it, no distortion |
format |
jpeg: sensor_msgs/CompressedImage on <topic>/compressed. raw: sensor_msgs/Image (rgba8) on <topic>
|
jpegQuality |
1 to 100, for jpeg
|
A camera with no entry or a bad one isn't published, and the Unity console says why. Camera mounts (position, tilt) are in the vehicle spec (cameras).
The topic names are placeholders under /sim/. Set them to what the real drone's camera drivers
publish once that's decided, so the same code runs on both.
PX4 sends 16 channels in HIL_ACTUATOR_CONTROLS, motors as 0..1 and servos as -1..1.
VehicleActuators hands each channel to the rotor or control surface whose channel in the spec
is that index (0-based; PX4 calls it PWM_MAIN_FUNC<channel+1>). PX4's side of the mapping comes
from the airframe: a generated airframe sets PWM_MAIN_FUNC* from the spec, so the two agree by
construction; with a stock airframe the spec's channels have to follow that airframe's output
layout (PX4 airframe).
The shipped quadplane follows 1040_gazebo-classic_standard_vtol:
| Channel | Actuator | Range | Notes |
|---|---|---|---|
| 0 | Lift rotor front-right | 0..1 | CCW |
| 1 | Lift rotor rear-left | 0..1 | CCW |
| 2 | Lift rotor front-left | 0..1 | CW |
| 3 | Lift rotor rear-right | 0..1 | CW |
| 4 | Pusher | 0..1 | |
| 5 | Left aileron | -1..1 | Positive rolls left |
| 6 | Right aileron | -1..1 | Positive rolls right |
| 7 | Elevator | -1..1 | Positive pitches nose up |
The airframe has no rudder. The X500 uses channels 0 to 3 in the same order (none_iris). The
same layout is in code as StandardVtolChannels in Vehicle/VehicleActuators.cs, which only the
keyboard controls (ManualControl, fields on Managers) and the tests read. A spec with a
different layout flies under PX4 without code changes; keyboard flying needs the lift rotor and
pusher channels on ManualControl updated to match.
| Suite | Covers | Needs |
|---|---|---|
Edit mode, Assets/Tests/EditMode/
|
MAVLink encoding (checked against frames from pymavlink), frame conversions, geodetic math, the magnetic field table, actuators, the camera config, the vehicle spec (FRD to Unity, inertia, checks, defaults, thrust tables, hover throttle, shipped specs valid and building) | Unity |
Play mode, Assets/Tests/PlayMode/
|
Flight.unity with each shipped vehicle and no PX4: builds, starts without errors, settles upright on the ground. The PX4 bridge over a real socket with FakePx4 on the other end: sensors at rest, one HIL_SENSOR per step, lockstep, PX4 stopping and restarting, arming and lift-off |
Unity |
Tools, tools/tests/
|
px4_airframe.py (rotor geometry, output functions, hover throttle, checks, constants shared with the C# code), sim_smoke_test.py, coverage_summary.py
|
Python 3 |
tools/sim_smoke_test.py |
A running sim or player, from PX4's side of the link: sensors at rest, disarmed stays put, armed climbs | Python 3 |
tools/px4_flight_test.py |
Takeoff, hover, transition and landing through PX4 (Setup) | PX4 SITL, pymavlink |
The play-mode tests and the smoke test pick up every spec in StreamingAssets/vehicles/, so a new
vehicle is tested without touching them. Any logged error or exception fails a Unity test.
Unity tests:
-
In Unity: Window > General > Test Runner > EditMode or PlayMode > Run All.
-
From a terminal, with the editor closed, from the project folder (
PlayModefor play mode):/Applications/Unity/Hub/Editor/6000.6.0f1/Unity.app/Contents/MacOS/Unity -batchmode \ -projectPath . -runTests -testPlatform EditMode -testResults results.xml -logFile test.log
Coverage: add -enableCodeCoverage -coverageOptions "generateHtmlReport;assemblyFilters:+DroneSim"
to the command above (or use Window > Analysis > Code Coverage), then
python3 tools/coverage_summary.py CodeCoverage for the table per file.
Tool tests: python3 -m unittest discover -s tools/tests -v
Smoke test, against a player or the editor in play mode with no PX4 running:
./drone-sim.x86_64 -batchmode -nographics --no-ros --vehicle quadplane &
python3 tools/sim_smoke_test.py quadplaneGitHub Actions, using game-ci's Unity images:
| Workflow | Runs on | Does |
|---|---|---|
tests.yml |
Pull requests, pushes to main that touch the Unity project |
Edit- and play-mode tests. Line coverage of the DroneSim assembly per file in the job summary, HTML report as the coverage artifact |
tools.yml |
Pull requests and pushes to main that touch tools/, vehicle specs or vehicle scripts |
Tool tests, no Unity |
build.yml |
Manual (Actions tab, Build, Run workflow) or a tag such as v0.1.0
|
Linux, Windows and macOS players, then the smoke test on the Linux player for each vehicle. A tag also drafts a release with the three builds zipped, once the smoke test passes |
wiki.yml |
Pushes to main that touch docs/
|
Publishes docs/ to the wiki |
The Unity jobs need a Unity license in the repository secrets: UNITY_EMAIL, UNITY_PASSWORD and
either UNITY_SERIAL (Pro or Student license) or UNITY_LICENSE (contents of a Personal .ulf
file). Only one Unity job runs at a time so they don't compete for the license.
The Unity test job is still called Edit-mode tests, though it runs play mode too: that name is the
required status check in main's ruleset. Rename both together.
Full list with types, rates and ports: Interfaces.
- Camera topics, frames, resolution, rate and format are in
sim_config.json(Camera config). The other topic and frame names are onROSSettings. - Clock and ground truth rates are on their publisher components. The ROS master switch is on
SimSettings. -
/fmu/...topics come from PX4 through the XRCE-DDS agent, not from Unity.
| Setting | Where |
|---|---|
| Cameras: topics, frames, resolution, rate, format | Assets/StreamingAssets/sim_config.json |
| Wind: mean vector, gust amplitude, gust period |
Wind on Managers
|
| Randomize mass, thrust and wind on reset (off by default) |
SimulationResetManager on Managers
|
| IMU noise and latency |
ImuModel on the vehicle's IMU object. The vehicle is built at startup, so change the defaults in Sensors/ImuModel.cs or edit them in play mode |
| GPS, barometer, magnetometer and airspeed noise; lockstep timeout |
Px4HilBridge on Managers
|
| ROS endpoint address and port |
ROSConnection on Managers
|
With the Game view focused:
| Key | Action |
|---|---|
| R | Reset the vehicle to its start pose |
| M | Toggle keyboard flying (PX4 controls are ignored while on) |
| Shift / Ctrl | Lift rotor collective up / down |
| W / S | Pitch nose down / nose up |
| A / D | Roll left / right |
| Q / E | Yaw left / right |
| Up / Down | Pusher throttle |
| Space | Cut all motors |
| Right drag | Orbit the chase camera |
| Scroll | Zoom |
Published from docs/ in the repository. Edit the pages there through a pull request; edits made on the wiki are overwritten by the next publish.