diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 04:05:02 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 04:05:02 +0300 |
| commit | da4c8ed23fe5289dbdc7d81a6eb6ddf66ff94ef7 (patch) | |
| tree | d7e891167d8249195bef209e074787daab0fcc73 /crates/fparkan-runtime/src/route_motion.rs | |
| parent | 683d970343383d63eeb22219080c190769f888b1 (diff) | |
| download | fparkan-da4c8ed23fe5289dbdc7d81a6eb6ddf66ff94ef7.tar.xz fparkan-da4c8ed23fe5289dbdc7d81a6eb6ddf66ff94ef7.zip | |
fix(movement): route autonomous units around buildings
Project the bounds of live building meshes onto the ground and expand them by the vehicle radius. The shared route follower chooses exterior corners for blocked legs and can leave a footprint containing its starting position.
Verified a detour on the stock factory geometry, stock builder resupply, a window run of Single.01, and 15 minutes of simulation on all 29 missions. Narrow openings, flying clearance and moving bodies remain open.
Diffstat (limited to 'crates/fparkan-runtime/src/route_motion.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/route_motion.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/fparkan-runtime/src/route_motion.rs b/crates/fparkan-runtime/src/route_motion.rs index 3d831fa0..be57affb 100644 --- a/crates/fparkan-runtime/src/route_motion.rs +++ b/crates/fparkan-runtime/src/route_motion.rs @@ -1,6 +1,9 @@ //! Follow a terrain route with a shared time budget for turning and travel. -use crate::{EngineError, TerrainWorld, TransformState}; +use crate::{ + route_obstacles::{open_leg, Footprint}, + EngineError, TerrainWorld, TransformState, +}; use fparkan_terrain::{NavigationQuery, RouteRequest}; use std::collections::VecDeque; @@ -39,10 +42,17 @@ pub(super) fn follow_route( points: &mut VecDeque<[f32; 2]>, speed: f32, mut seconds: f32, + obstacles: &[Footprint], mut height_at: impl FnMut([f32; 2]) -> Result<Option<f32>, EngineError>, ) -> Result<TransformState, EngineError> { let [mut x, mut y, mut z] = pose.position.map(f32::from_bits); - while seconds > 0.0 { + while seconds > 0.0 && !points.is_empty() { + if !open_leg([x, y], points, obstacles, |point| { + height_at(point).map(|z| z.is_some()) + })? { + points.clear(); + break; + } let Some(&target) = points.front() else { break }; let [dx, dy] = [target[0] - x, target[1] - y]; let distance = dx.hypot(dy); @@ -92,7 +102,7 @@ mod tests { ..Default::default() }; let mut route = VecDeque::from([[0.0, 0.0], [0.0, 1.0], [4.0, 1.0]]); - let end = follow_route(start, &mut route, 2.0, 2.0, |[x, y]| Ok(Some(x + y))).unwrap(); + let end = follow_route(start, &mut route, 2.0, 2.0, &[], |[x, y]| Ok(Some(x + y))).unwrap(); let [x, y, z] = end.position.map(f32::from_bits); let expected_x = 3.0 - std::f32::consts::FRAC_PI_2; assert!((x - expected_x).abs() < 0.000_01); |
