Skip to main content

SimRobot

Struct SimRobot 

Source
pub struct SimRobot { /* private fields */ }
Expand description

A simulated differential-drive robot: drive it with a Twist, read back its Pose.

This stands in for a real rover in a hardware-free test or demo. It is both an Actuator whose command is a body twist and a Sensor whose reading is the pose: each command advances the robot one time step at the commanded velocity, integrating the motion with the same exact-arc odometry a real robot would use, and a read returns where it has reached. A control loop can therefore be developed and tested end to end with no robot.

§Examples

use pamoja_core::{Actuator, Sensor};
use pamoja_kit::Twist;
use pamoja_sim::SimRobot;

let mut robot = SimRobot::new(0.1); // 0.1 s per command
// Drive straight at 1 m/s for ten steps: about one metre forward.
for _ in 0..10 {
    robot.apply(Twist::planar(1.0, 0.0)).await?;
}
let pose = robot.read().await?;
assert!((pose.x - 1.0).abs() < 1e-5 && pose.y.abs() < 1e-5);

Implementations§

Source§

impl SimRobot

Source

pub fn new(dt: f32) -> Self

Creates a robot at the origin that advances dt seconds per command.

§Arguments
  • dt - the time each apply advances the robot; its magnitude is used.
§Returns

The simulated robot.

Source

pub fn starting_at(pose: Pose, dt: f32) -> Self

Creates a robot starting from a known pose.

§Arguments
  • pose - the starting pose.
  • dt - the time each command advances the robot; its magnitude is used.
§Returns

The simulated robot.

Source

pub fn pose(&self) -> Pose

Returns the robot’s current pose.

§Returns

The pose reached so far.

Trait Implementations§

Source§

impl Actuator for SimRobot

Source§

type Command = Twist

The command accepted by a single application, for example a setpoint.
Source§

async fn apply(&mut self, command: Twist) -> Result<()>

Applies a command to the actuator. Read more
Source§

impl Clone for SimRobot

Source§

fn clone(&self) -> SimRobot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SimRobot

Source§

impl Debug for SimRobot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Sensor for SimRobot

Source§

type Reading = Pose

The value produced by a single read, for example a temperature or a fix.
Source§

async fn read(&mut self) -> Result<Pose>

Takes a single reading from the sensor. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.