Repository navigation
Development
Assets/_Project/Scripts/ DroneSim assembly, namespace DroneSim
Bridge/ Px4HilBridge (PX4 connection, lockstep), MavlinkCodec
Vehicle/ 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
Assets/StreamingAssets/ sim_config.json (cameras)
Assets/Tests/EditMode/ Unit tests
tools/ px4_flight_test.py
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.
Vehicle numbers (mass, inertia, rotor positions and thrust, wing coefficients, camera placement)
are in Assets/Editor/DroneSim/SceneBuilder.cs. To change a vehicle:
- Edit the builder.
- In Unity, run Drone Sim > Build Flight Scenes (or Build Quadplane Scene / Build X500 Scene).
- Commit the builder and the regenerated scenes together.
Changes made in the Inspector are overwritten by the next rebuild, so put them in the builder.
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 to the camera object in the scene by name:
| Field | Meaning |
|---|---|
name |
Camera object in the scene: ForwardCamera or DownCamera
|
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 SceneBuilder.cs with the rest of the vehicle.
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.
The quadplane follows PX4's 1040_gazebo-classic_standard_vtol airframe. The same mapping is in
code as StandardVtolChannels in Vehicle/VehicleActuators.cs.
| 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. When the team's
aircraft gets its own PX4 airframe, update StandardVtolChannels, the builder and this table
together.
Edit-mode unit tests cover MAVLink encoding (checked against frames from pymavlink), frame conversions, geodetic math, the magnetic field table and actuators.
-
In Unity: Window > General > Test Runner > EditMode > Run All.
-
From a terminal, with the editor closed, from the project folder:
/Applications/Unity/Hub/Editor/6000.6.0f1/Unity.app/Contents/MacOS/Unity -batchmode -nographics \ -projectPath . -runTests -testPlatform EditMode -testResults results.xml -logFile test.log
End-to-end: tools/px4_flight_test.py with PX4 connected (Setup).
GitHub Actions, using game-ci's Unity images:
-
.github/workflows/tests.ymlruns the edit-mode tests on every push tomainand every pull request. -
.github/workflows/build.ymlbuilds Linux, Windows and macOS players. Run it from the Actions tab, or push a tag such asv0.1.0; a tag also creates a draft release with the three builds zipped.
Both 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.
Published by Unity through the ROS TCP endpoint:
| Topic | Type | Rate |
|---|---|---|
/clock |
rosgraph_msgs/Clock | 10 Hz |
/sim/forward_cam/image_raw/compressed |
sensor_msgs/CompressedImage, 1280x720 JPEG | 10 Hz |
/sim/forward_cam/camera_info |
sensor_msgs/CameraInfo | 10 Hz |
/sim/down_cam/image_raw/compressed |
sensor_msgs/CompressedImage, 1280x720 JPEG | 10 Hz |
/sim/down_cam/camera_info |
sensor_msgs/CameraInfo | 10 Hz |
/sim/ground_truth/pose |
geometry_msgs/PoseStamped (ENU, relative to the Unity origin) | 50 Hz |
/sim/ground_truth/twist |
geometry_msgs/TwistStamped (body FLU) | 50 Hz |
/sim/ground_truth/gps |
sensor_msgs/NavSatFix | 50 Hz |
Subscribed: /simulation/reset (std_msgs/Bool) resets the vehicle to its start pose on true.
- 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 |
| 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.