pub struct Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>where
ServoPwm: PwmPin,
DS: DistanceSensor<DE>,{
steering: Steering<ServoPwm>,
motor: Motor<MAIN1, MAIN2, MAPWM>,
front_distance_sensor: Option<DS>,
display: Option<Display>,
led_status_obstacle: OLED,
current_state: CarState,
latest_front_distance_in_mm: Option<u16>,
last_front_distance_update: Option<TimerInstantU32<1_000_000>>,
_distance_sensor_error: PhantomData<DE>,
}
Expand description
Represents the robot car.
Fields
steering: Steering<ServoPwm>
motor: Motor<MAIN1, MAIN2, MAPWM>
front_distance_sensor: Option<DS>
display: Option<Display>
led_status_obstacle: OLED
current_state: CarState
latest_front_distance_in_mm: Option<u16>
last_front_distance_update: Option<TimerInstantU32<1_000_000>>
_distance_sensor_error: PhantomData<DE>
Needed to be able to specify the DE
type parameter
Implementations
sourceimpl<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED> Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>where
ServoPwm: PwmPin<Duty = u16>,
MAIN1: OutputPin,
MAIN2: OutputPin,
MAPWM: PwmPin<Duty = u16>,
DS: DistanceSensor<DE>,
DE: Debug,
OLED: OutputPin,
impl<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED> Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>where
ServoPwm: PwmPin<Duty = u16>,
MAIN1: OutputPin,
MAIN2: OutputPin,
MAPWM: PwmPin<Duty = u16>,
DS: DistanceSensor<DE>,
DE: Debug,
OLED: OutputPin,
pub fn new(
steering: Steering<ServoPwm>,
motor: Motor<MAIN1, MAIN2, MAPWM>,
front_distance_sensor: Option<DS>,
display: Option<Display>,
led_status_obstacle: OLED
) -> Self
pub fn steer_left(&mut self)
pub fn steer_center(&mut self)
pub fn steer_right(&mut self)
pub fn drive_forward(&mut self, speed: u8) -> Result<(), Error>
pub fn drive_backwards(&mut self, speed: u8) -> Result<(), Error>
sourcepub fn current_speed(&mut self) -> i8
pub fn current_speed(&mut self) -> i8
Return the current speed of the motor (in percentage). Note that driving forward returns a positive number while driving backwards returns a negative number and a stopped car returns 0.
pub fn halt(&mut self)
pub fn handle_distance_sensor_interrupt(
&mut self,
now: TimerInstantU32<1_000_000>
) -> Result<(), DE>
pub fn validate_distance(&mut self, now: TimerInstantU32<1_000_000>)
sourcefn halt_if_driving_forward(&mut self)
fn halt_if_driving_forward(&mut self)
Halt in case the car is currently driving forward, otherwise do nothing. This is used in the collision avoidance to ensure that it’s still possible to drive backwards.
fn update_display(&mut self)
Auto Trait Implementations
impl<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED> !RefUnwindSafe for Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>
impl<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED> Send for Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>where
DE: Send,
DS: Send,
MAIN1: Send,
MAIN2: Send,
MAPWM: Send,
OLED: Send,
ServoPwm: Send,
<ServoPwm as PwmPin>::Duty: Send,
impl<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED> Sync for Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>where
DE: Sync,
DS: Sync,
MAIN1: Sync,
MAIN2: Sync,
MAPWM: Sync,
OLED: Sync,
ServoPwm: Sync,
<ServoPwm as PwmPin>::Duty: Sync,
impl<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED> Unpin for Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>where
DE: Unpin,
DS: Unpin,
MAIN1: Unpin,
MAIN2: Unpin,
MAPWM: Unpin,
OLED: Unpin,
ServoPwm: Unpin,
<ServoPwm as PwmPin>::Duty: Unpin,
impl<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED> !UnwindSafe for Car<ServoPwm, MAIN1, MAIN2, MAPWM, DS, DE, OLED>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcefn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
sourcefn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcefn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
sourcefn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcefn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
sourcefn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcefn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
sourcefn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcefn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
sourcefn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.