pub struct PlanarState {
pub position: Vec2,
pub velocity: Vec2,
pub yaw: f32,
pub turn_rate: f32,
}Fields§
§position: Vec2§velocity: Vec2§yaw: f32§turn_rate: f32Implementations§
Source§impl PlanarState
impl PlanarState
Sourcepub fn telemetry(&self) -> Result<PlanarTelemetry, VehicleError>
pub fn telemetry(&self) -> Result<PlanarTelemetry, VehicleError>
Read heading, speed and slip without advancing or modifying the motor.
Returns VehicleError::Invalid if any state field is nonfinite or a
derived speed cannot be represented as a finite f32.
use ferravex_math::Vec2;
use ferravex_play::vehicle::PlanarState;
let motor = PlanarState {
position: Vec2::ZERO, velocity: Vec2::new(3., 4.), yaw: 0., turn_rate: 0.,
};
let hud = motor.telemetry()?;
assert_eq!((hud.speed, hud.forward_speed, hud.lateral_speed), (5., 4., 3.));
assert!(hud.slip_angle > 0.); // Sliding to the right.Sourcepub fn reset(
&mut self,
position: Vec2,
yaw: f32,
velocity: Vec2,
) -> Result<(), VehicleError>
pub fn reset( &mut self, position: Vec2, yaw: f32, velocity: Vec2, ) -> Result<(), VehicleError>
Replace pose and linear velocity, clearing the smoothed turn rate.
Position, yaw and velocity must be finite, and velocity magnitude must be
at most 10000 (the largest supported handling speed). Yaw is retained as
supplied; the next step applies its usual wrapping and speed cap. Pass
Vec2::ZERO to stop. Invalid targets leave every field unchanged, while
a valid target can repair an invalid old state. No simulation tick elapses.
Reset the host’s previous pose too, to avoid interpolating across a teleport.
use ferravex_math::Vec2;
use ferravex_play::vehicle::PlanarState;
let mut motor = PlanarState {
position: Vec2::ZERO, velocity: Vec2::X * 8., yaw: 1., turn_rate: 2.,
};
motor.reset(Vec2::new(10., 20.), 0., Vec2::ZERO)?;
assert_eq!(motor.position, Vec2::new(10., 20.));
assert_eq!((motor.telemetry()?.speed, motor.turn_rate), (0., 0.));pub fn step( &mut self, p: PlanarHandling, input: DriveInput, dt: f32, ) -> Result<(), VehicleError>
Trait Implementations§
Source§impl Clone for PlanarState
impl Clone for PlanarState
Source§fn clone(&self) -> PlanarState
fn clone(&self) -> PlanarState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PlanarState
impl Debug for PlanarState
Source§impl PartialEq for PlanarState
impl PartialEq for PlanarState
impl Copy for PlanarState
impl StructuralPartialEq for PlanarState
Auto Trait Implementations§
impl Freeze for PlanarState
impl RefUnwindSafe for PlanarState
impl Send for PlanarState
impl Sync for PlanarState
impl Unpin for PlanarState
impl UnwindSafe for PlanarState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more