From aae273f04e9412854951d29be70eed0cad901d6e Mon Sep 17 00:00:00 2001 From: Andrew Jong Date: Wed, 2 Dec 2026 19:03:41 -0500 Subject: [PATCH] fix(project-airsim): integrate JSBSim in 1 ms substeps so the quadrotor rests and flies With JSBSim physics, jsbsim-dt equalled the 3 ms simulator tick (as in upstream's quadrotor example). At that step quadrotor_x's landing-gear friction (mu = 5) solves unstably: the vehicle chatters on the ground (IMU spikes near 50 m/s^2, ground-truth rates +/-0.3 rad/s) and PX4 needs ~90 s before preflight passes. Project AirSim runs JSBSim in substeps of at most jsbsim-dt per tick, so capping it at 1 ms gives three substeps: at rest, ready in ~5 s, no measurable CPU or RTF cost. Spawn mode and Unreal collision were ruled out; the model is unchanged. - generate_scene.py: jsbsim-dt = min(tick, JSBSIM_MAX_DT_S = 1 ms) - harness: --physics fast-physics|jsbsim for Project AirSim runs (sets PROJECT_AIRSIM_PHYSICS; part of the campaign fingerprint); listed in `airstack help test` - contract test pins the cap; guide and release note drop "experimental" - VERSION 0.21.0-dev.21 Validated: liveliness + takeoff/hover/land at 0.5/1/2 m/s on --physics jsbsim, 20/20. Co-Authored-By: Claude Opus 5.5 --- .env | 2 +- airstack.sh | 2 ++ docs/release_notes/index.md | 5 +++-- docs/simulation/project-airsim/index.md | 8 ++++++-- .../project-airsim/config/generate_scene.py | 8 +++++++- tests/conftest.py | 11 ++++++++++- tests/harness/run_meta.py | 1 + tests/meta/test_project_airsim_scene_contract.py | 16 ++++++++++++++++ 8 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 396d32706..991399af1 100644 --- a/.env +++ b/.env @@ -12,7 +12,7 @@ PROJECT_NAME="airstack" # If you've run ./airstack.sh setup, then this will auto-generate from the git commit hash every time a change is made # to a Dockerfile or docker-compose.yaml file. Otherwise this can also be set explicitly to make a release version. # auto-generated from git commit hash -VERSION="0.21.0-dev.20" +VERSION="0.21.0-dev.21" # Image-tag discriminator ONLY (appears in the image tag suffix, e.g. ..._robot-x86-64_dev). # No Dockerfile consumes it: "prebuilt" does NOT bake the built ros_ws into the image today — # a real prebuilt (workspace-baked) stage is future work. Keep "dev" (mounted code, built live). diff --git a/airstack.sh b/airstack.sh index 706dd91ed..61d6867a7 100755 --- a/airstack.sh +++ b/airstack.sh @@ -411,6 +411,8 @@ function print_command_help { echo " the full_default dispatch)" echo " --fleet=NAME Fleet preset under config/fleets/ (derives the" echo " robot count, overriding --num-robots)" + echo " --physics=MODEL Project AirSim dynamics: fast-physics or jsbsim" + echo " (default: fast-physics; ignored by other sims)" echo " --stress-iterations=N Up/down cycles per config (default: 1)" echo " --stable-duration=SECS Seconds test_stable polls for (default: 120)" echo " --stable-interval=SECS Seconds between polls (default: 10)" diff --git a/docs/release_notes/index.md b/docs/release_notes/index.md index c375347b4..210955edc 100644 --- a/docs/release_notes/index.md +++ b/docs/release_notes/index.md @@ -33,8 +33,9 @@ its own notes. --> (`sensors/ouster/point_cloud_raw`). Unlike Microsoft AirSim (legacy), the default MIGHTY stack therefore runs on it, and cameras render headless. New flag `--physics fast-physics|jsbsim`, per robot via fleet - `robots..physics` / `sim.physics` (JSBSim is experimental: PX4's EKF - does not yet complete tilt alignment). Validated with liveliness, sensors, + `robots..physics` / `sim.physics`, and `airstack test --physics`. + JSBSim integrates in 1 ms substeps (at the 3 ms simulator tick its landing + gear chattered and PX4 needed ~90 s to pass preflight). Validated with liveliness, sensors, takeoff/hover/land (0.5–2 m/s), fixed trajectories, MIGHTY waypoint flight, and two robots. `PROJECT_AIRSIM_LUMEN` toggles Lumen GI and reflections per camera in environments packaged with the plugin from Project AirSim diff --git a/docs/simulation/project-airsim/index.md b/docs/simulation/project-airsim/index.md index e445a4d44..4f7d72af4 100644 --- a/docs/simulation/project-airsim/index.md +++ b/docs/simulation/project-airsim/index.md @@ -125,8 +125,8 @@ Because Project AirSim's own control link is parked on an unused port, its param | | `fast-physics` (default) | `jsbsim` | |---|---|---| | Model | Project AirSim's rigid-body quad: point-mass rotors, box drag | Auterion's `quadrotor_x` JSBSim flight-dynamics model | -| Status | Validated: liveliness, sensors, takeoff/hover/land, fixed trajectories, MIGHTY waypoint flight, two robots | **Experimental:** the scene loads and sensors stream, but PX4's EKF does not complete tilt alignment at rest (IMU contact jitter) | -| Use for | All AirStack testing | Investigating flight-dynamics fidelity | +| Status | Validated: liveliness, sensors, takeoff/hover/land, fixed trajectories, MIGHTY waypoint flight, two robots | Validated: liveliness, takeoff/hover/land (0.5–2 m/s), one robot | +| Use for | All AirStack testing | Flight-dynamics fidelity: JSBSim's aerodynamics, propulsion and landing gear | Selection, first match wins: @@ -148,6 +148,10 @@ sim: Both variants carry identical sensors and PX4 settings; only the dynamics differ. The choice per robot is printed in the container log (`generate_scene: robot_1: physics=...`). +JSBSim integrates in 1 ms substeps, three per 3 ms simulator tick. At the tick itself, `quadrotor_x`'s landing-gear friction solves unstably: the vehicle chatters on the ground (IMU spikes near 50 m/s²) and PX4 takes about 90 s to pass preflight. With 1 ms substeps it is at rest and ready in seconds, at no measurable CPU or real-time-factor cost. + +The system tests take the same choice: `airstack test ... --sim projectairsim --physics jsbsim`. + ## Spawn origins Project AirSim places `0 0 0` at the Unreal world origin, not at a player start. In the packaged Blocks environment that origin lies inside a block and below the ground surface. A drone spawned there is pushed out of the geometry every few seconds, which looks like it teleports to the ground mid-flight. Each environment therefore has a **spawn origin** (NED metres, world frame), and fleet `spawn:` offsets apply relative to it: diff --git a/simulation/project-airsim/config/generate_scene.py b/simulation/project-airsim/config/generate_scene.py index ccd90bfab..b24ad772f 100755 --- a/simulation/project-airsim/config/generate_scene.py +++ b/simulation/project-airsim/config/generate_scene.py @@ -31,6 +31,12 @@ from pathlib import Path PHYSICS_CHOICES = ("fast-physics", "jsbsim") +# Largest JSBSim integration step. Project AirSim runs JSBSim in substeps of at +# most jsbsim-dt per clock tick. At the 3 ms tick, quadrotor_x's landing-gear +# friction (mu = 5) solves unstably: the vehicle chatters at rest (IMU spikes +# near 50 m/s^2) and PX4 needs ~90 s to align and pass preflight. 1 ms substeps +# remove the chatter (preflight in ~5 s) at no measurable CPU or RTF cost. +JSBSIM_MAX_DT_S = 0.001 DEFAULT_PHYSICS = "fast-physics" SCENE_ID = "SceneAirStack" HIL_TCP_BASE = 4560 @@ -454,7 +460,7 @@ def build_robot_config(robot, params): "jsbsim-aircraft-path": "aircraft", "jsbsim-engine-path": "engine", "jsbsim-systems-path": "systems", - "jsbsim-dt": params["step_ns"] / 1e9, + "jsbsim-dt": min(params["step_ns"] / 1e9, JSBSIM_MAX_DT_S), }) else: cfg["physics-type"] = "fast-physics" diff --git a/tests/conftest.py b/tests/conftest.py index f903901e1..190d56e7c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -37,6 +37,12 @@ def pytest_addoption(parser): "= the default dispatch, stacks/full_default. The " "wiring test drift-checks against " "stacks//wiring.md.") + parser.addoption("--physics", default=None, + choices=("fast-physics", "jsbsim"), + help="Project AirSim dynamics model for every robot, " + "same as `airstack up --physics` (sets " + "PROJECT_AIRSIM_PHYSICS). Ignored by other sims. " + "Default: None = the sim's default (fast-physics).") parser.addoption("--fleet", default=None, help="Fleet preset under config/fleets/ (RFC #380 §2), " "e.g. sim_three_mixed. Sets FLEET_CONFIG_FILE for " @@ -160,7 +166,7 @@ def pytest_sessionfinish(session, exitstatus): "sim", "num_robots", "stress_iterations", "stable_duration", "stable_interval", "gui", "takeoff_velocities", "trajectory_types", "waypoints", "waypoint_tolerance", - "goal_tolerance", "waypoint_timeout", + "goal_tolerance", "waypoint_timeout", "physics", ): try: campaign_config[key] = session.config.getoption( @@ -276,6 +282,9 @@ def airstack_env(request): # Forces rviz/Qt apps to render offscreen instead of spawning windows. env_overrides["QT_QPA_PLATFORM"] = "offscreen" env_overrides.update(cfg.get("extra_env", {})) + physics = request.config.getoption("--physics") + if physics and sim == "projectairsim": + env_overrides["PROJECT_AIRSIM_PHYSICS"] = physics # Stack dispatch (RFC #379 §3): route robot.launch.xml to the stack's # entry launch file (unset = the full_default default). Container path — diff --git a/tests/harness/run_meta.py b/tests/harness/run_meta.py index 48b22cad8..b817a463e 100644 --- a/tests/harness/run_meta.py +++ b/tests/harness/run_meta.py @@ -42,6 +42,7 @@ def is_simulation_test_id(test_id: str) -> bool: "waypoint_tolerance", "goal_tolerance", "waypoint_timeout", + "physics", ) diff --git a/tests/meta/test_project_airsim_scene_contract.py b/tests/meta/test_project_airsim_scene_contract.py index d04365642..5a2825642 100644 --- a/tests/meta/test_project_airsim_scene_contract.py +++ b/tests/meta/test_project_airsim_scene_contract.py @@ -168,6 +168,22 @@ def test_jsbsim_differs_only_in_dynamics(gen, tmp_path): assert escs == [f"fcs/esc-cmd-norm[{k}]" for k in range(4)] +@pytest.mark.parametrize("step_ns, want_dt", [ + (None, 0.001), # default 3 ms tick -> three 1 ms JSBSim substeps + ("500000", 0.0005), # a tick finer than the cap is used as-is +]) +def test_jsbsim_substeps_at_most_1ms(gen, tmp_path, step_ns, want_dt): + """quadrotor_x's gear friction chatters at a 3 ms step (IMU spikes ~50 + m/s^2, PX4 preflight ~90 s); jsbsim-dt is capped at 1 ms (016).""" + env = {"PROJECT_AIRSIM_PHYSICS": "jsbsim"} + if step_ns: + env["PROJECT_AIRSIM_STEP_NS"] = step_ns + scene, _ = _generate(gen, tmp_path, **env) + dt = scene["actors"][0]["robot-config"]["jsbsim-dt"] + assert dt == pytest.approx(want_dt) + assert dt <= gen.JSBSIM_MAX_DT_S + + def test_fleet_physics_per_robot(gen, tmp_path): fleet = { "defaults": {"vehicle": "quad_default", "stack": "stacks/full_default"},