Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable "arrival" logic for Waypoint, like we have for RouteStep #298

Open
michaelkirk opened this issue Oct 15, 2024 · 1 comment
Open

Comments

@michaelkirk
Copy link
Contributor

michaelkirk commented Oct 15, 2024

When a RouteStep should be considered complete, is a question answered by StepAdvanceMode

Similarly, we should have a way to customize arrival logic for Waypoint - currently it's hardcoded to "within 100 meters".

https://github.com/stadiamaps/ferrostar/blob/adb74ca72fc749a8c0960d4fdd84ea539aee89dd/common/ferrostar/src/navigation_controller/mod.rs#L120C1-L130C27

let should_advance_waypoint = if let Some(waypoint) =
    remaining_waypoints.first()
{
    let current_location: Point = snapped_user_location.coordinates.into();
    let next_waypoint: Point = waypoint.coordinate.into();
    // TODO: This is just a hard-coded threshold for the time being.
    // More sophisticated behavior will take some time and use cases, so punting on this for now.
    current_location.haversine_distance(&next_waypoint) < 100.0
} else {
    false
};

Note this is especially problematic in light of #285. Solving #285 without first addressing this Waypoint arrival logic would mean "completing" the trip too early in my case.

Proposed Solution

My first attempt at "more sophisticated behavior" is not all that sophisticated:

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize, Tsify))]
#[cfg_attr(feature = "wasm-bindgen", tsify(from_wasm_abi))]
pub enum WaypointAdvanceMode {
    /// Automatically advances when the user's location is close enough to the [`Waypoint`]
    #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))]
    DistanceToWaypoint {
        /// Distance to the waypoint, measured in meters, at which to advance.
        distance: u16,
        /// The minimum required horizontal accuracy of the user location, in meters.
        /// Values larger than this cannot trigger an advance.
        minimum_horizontal_accuracy: u16,
    },
}

impl Default for WaypointAdvanceMode {
    fn default() -> Self {
        WaypointAdvanceMode::DistanceToWaypoint {
            distance: 100,
            minimum_horizontal_accuracy: 10,
        }
    }
}
pub struct NavigationControllerConfig {
     /// Configures when navigation advances to the next step in the route.
     pub step_advance: StepAdvanceMode,
+    /// Configures when navigation advances to the next Waypoint in the route.
+    pub waypoint_advance: WaypointAdvanceMode,
     ...
}
michaelkirk added a commit to michaelkirk/ferrostar that referenced this issue Oct 15, 2024
Current distance is hard-coded for my purpose. We should make this
configurable before merging this. See
stadiamaps#298
michaelkirk added a commit to michaelkirk/ferrostar that referenced this issue Oct 15, 2024
Current distance is hard-coded for my purpose. We should make this
configurable before merging this. See
stadiamaps#298
@ianthetechie
Copy link
Contributor

Yeah, I think this is a good idea. Thanks for the thorough write-up! I'd welcome a PR for it (sounds like you're working on one based on the commits).

You can also have a look at RouteDeviationTracking, which is quite similar structurally, but also adds a custom variant with arbitrary user-supplied logic. We should probably do this for StepAdvanceMode too (idk why I didn't think of that earlier). I think that'd minimally solve every conceivable problem by providing hooks for arbitrary logic app-side. And of course we can always refine the defaults, built-in behaviors, etc.... "Ship sane defaults, but keep it flexible" is my north star.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants