Align Nav2 with physics time and preserve complete simulation scenes
This commit is contained in:
@@ -26,6 +26,8 @@ def main():
|
||||
parser.add_argument("--source", type=Path, required=True)
|
||||
parser.add_argument("--stream-address", required=True)
|
||||
parser.add_argument("--no-stream", action="store_true", help="Qualify sensors without WebRTC")
|
||||
parser.add_argument('--catch-up-mode', choices=['sensor-period-catchup', 'render-period-catchup'],
|
||||
default='sensor-period-catchup', help='Native scheduling qualification')
|
||||
args, _ = parser.parse_known_args()
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(root / "src"))
|
||||
@@ -324,7 +326,8 @@ def main():
|
||||
mission = mission_for_inputs(execution_inputs)
|
||||
continuous = rig["schema_version"] == "missioncore.simulation-sensor-rig/v4"
|
||||
scheduling = build_scheduling_policy(continuous=continuous, physics_dt=1/60,
|
||||
capture_hz=SENSOR_HZ, main_loop_hz=30)
|
||||
capture_hz=SENSOR_HZ, main_loop_hz=30,
|
||||
catch_up_mode=args.catch_up_mode)
|
||||
config.set("/persistent/simulation/minFrameRate",
|
||||
scheduling["min_simulation_frame_rate_hz"])
|
||||
if config.get("/persistent/simulation/minFrameRate") != scheduling["min_simulation_frame_rate_hz"]:
|
||||
@@ -358,6 +361,8 @@ def main():
|
||||
envelope, chassis_feedback = motion_control.envelope, motion_control.feedback
|
||||
state = {"velocity": 0.0, "yaw_rate": 0.0, "stop_reason": "paused", "decision": None}
|
||||
physics_rows = []
|
||||
from loop_profile import LoopProfile
|
||||
loop_profile = LoopProfile()
|
||||
physics_seconds = 0.0
|
||||
from motion_metrics import PlanarDistance, planar_twist
|
||||
travelled = PlanarDistance()
|
||||
@@ -478,7 +483,8 @@ def main():
|
||||
if continuous:
|
||||
heading = state['transform'].TransformDir(Gf.Vec3d(1, 0, 0))
|
||||
ai.observe_pose(state["pose"], state["speed"], time.monotonic(), measured_twist=
|
||||
planar_twist(state['body_velocity'], state['body_angular_velocity'], heading))
|
||||
planar_twist(state['body_velocity'], state['body_angular_velocity'], heading),
|
||||
simulation_time_ns=round(physics_seconds * 1e9))
|
||||
if track_motion:
|
||||
track_motion.advance(dt, *drive.side_speeds())
|
||||
unstable |= inclination(state["pose"]) >= PROFILE["stop_tilt_degrees"]
|
||||
@@ -517,6 +523,7 @@ def main():
|
||||
|
||||
def guarded(callback):
|
||||
def invoke(dt, context):
|
||||
began = time.perf_counter()
|
||||
try:
|
||||
callback(dt, context)
|
||||
except Exception:
|
||||
@@ -525,6 +532,8 @@ def main():
|
||||
callback_errors.append(traceback.format_exc())
|
||||
ai.enable(False)
|
||||
drive.command(0.0, 0.0)
|
||||
finally:
|
||||
loop_profile.add(callback.__name__, time.perf_counter()-began)
|
||||
|
||||
return invoke
|
||||
|
||||
@@ -606,7 +615,9 @@ def main():
|
||||
# Apply fixtures before rendering so RGB and range observe the
|
||||
# same environment. Never mutate the rover or its controller.
|
||||
challenge.tick(time.monotonic(), obstacle)
|
||||
began_update = time.perf_counter()
|
||||
app.update() # Never waits for inference, a network request, or an operator ACK.
|
||||
loop_profile.add('app_update_inclusive', time.perf_counter()-began_update)
|
||||
if track_motion:
|
||||
track_motion.publish()
|
||||
if callback_errors:
|
||||
@@ -621,11 +632,13 @@ def main():
|
||||
velocity, yaw_rate = state["velocity"], state["yaw_rate"]
|
||||
stop_reason, decision = state["stop_reason"], state["decision"]
|
||||
if physics_rows:
|
||||
began_journal = time.perf_counter()
|
||||
physics_motion.writelines(
|
||||
json.dumps(row, allow_nan=False) + "\n" for row in physics_rows
|
||||
)
|
||||
physics_rows.clear()
|
||||
physics_motion.flush()
|
||||
loop_profile.add('physics_journal', time.perf_counter()-began_journal)
|
||||
physics = SimulationManager.get_num_physics_steps()
|
||||
sim_ns = round((physics - baseline) * 1e9 / 60)
|
||||
if playing and capture_cadence.due(captured_at):
|
||||
@@ -654,6 +667,8 @@ def main():
|
||||
else range_sensor.capture(eye, transform, rear_eye)
|
||||
)
|
||||
range_ready_at = time.monotonic()
|
||||
loop_profile.add('range_capture', range_ready_at-rgb_ready_at)
|
||||
loop_profile.add('rgb_read', rgb_ready_at-captured_at)
|
||||
if obstacle and challenge.started is not None:
|
||||
challenge.record(
|
||||
"obstacle-observation",
|
||||
@@ -711,6 +726,8 @@ def main():
|
||||
json.dumps(e, allow_nan=False) + "\n" for e in challenge.drain_events()
|
||||
)
|
||||
challenge_events.flush()
|
||||
if loop_profile.due(captured_at):
|
||||
write_json(directory / 'loop-profile.json', loop_profile.report(captured_at))
|
||||
if captured_at - last_report >= 0.25:
|
||||
prior_at, prior_render, prior_sensor, prior_ai, prior_physics = prior_metrics
|
||||
elapsed = captured_at - prior_at
|
||||
|
||||
Reference in New Issue
Block a user