Struct PicoBorgRev

Source
pub struct PicoBorgRev<T: Read + Write + WriteRead> { /* private fields */ }
Expand description

The PicoBorgRev provides an easy way to interact with a PicoBorg Reverse from rust. The communication is done via the embedded-hal i2c traits and the PicoBorg Reverse is located at the i2c address 0x44 by default.

Implementations§

Source§

impl<T: Read + Write + WriteRead> PicoBorgRev<T>

Source

pub fn new(device: T) -> Result<PicoBorgRev<T>, <T as WriteRead>::Error>

Attempt to create a new PicoBorgRev.

This will fail if either the i2c device has an error or the PicoBorg Reverse is not found at the default address (0x44).

Source

pub fn set_motor_1(&mut self, power: f32) -> Result<(), <T as Write>::Error>

Sets the drive level for motor 1, from +1 to -1.

Source

pub fn set_motor_2(&mut self, power: f32) -> Result<(), <T as Write>::Error>

Sets the drive level for motor 2, from +1 to -1

Source

pub fn set_motors(&mut self, power: f32) -> Result<(), <T as Write>::Error>

Sets the drive level for all motors, from +1 to -1.

Source

pub fn motors_off(&mut self) -> Result<(), <T as Write>::Error>

Sets all motors to stopped, useful when ending a program

Source

pub fn get_motor_1(&mut self) -> Result<f32, <T as WriteRead>::Error>

Gets the drive level for motor 1, from +1 to -1.

Source

pub fn get_motor_2(&mut self) -> Result<f32, <T as WriteRead>::Error>

Gets the drive level for motor 1, from +1 to -1.

Source

pub fn set_led(&mut self, state: bool) -> Result<(), <T as Write>::Error>

Sets the current state of the Led, False for off, True for on

Source

pub fn get_led(&mut self) -> Result<bool, <T as WriteRead>::Error>

Reads the current state of the Led, False for off, True for on

Source

pub fn reset_epo(&mut self) -> Result<(), <T as Write>::Error>

Resets the Epo latch state, use to allow movement again after the Epo has been tripped.

Source

pub fn get_epo(&mut self) -> Result<bool, <T as WriteRead>::Error>

Reads the system Epo latch state. If false the Epo has not been tripped, and movement is allowed. If true the Epo has been tripped, movement is disabled if the Epo is not ignored (see set_epo_ignore).

Movement can be re-enabled by calling reset_epo.

Source

pub fn set_epo_ignore(&mut self, state: bool) -> Result<(), <T as Write>::Error>

Sets the system to ignore or use the Epo latch, set to false if you have an Epo switch, true if you do not.

Source

pub fn get_epo_ignore(&mut self) -> Result<bool, <T as WriteRead>::Error>

Reads the system Epo ignore state, false for using the Epo latch, true for ignoring the Epo latch.

Source

pub fn set_comms_failsafe( &mut self, state: bool, ) -> Result<(), <T as Write>::Error>

Sets the system to enable or disable the communications failsafe. The failsafe will turn the motors off unless it is commanded at least once every 1/4 of a second.

Set to true to enable this failsafe or set to false to disable.

The failsafe is disabled at power on.

Source

pub fn get_comms_failsafe(&mut self) -> Result<bool, <T as WriteRead>::Error>

Read the current system state of the communications failsafe, true for enabled, false for disabled. The failsafe will turn the motors off unless it is commanded at least once every 1/4 of a second.

Source

pub fn get_drive_fault(&mut self) -> Result<bool, <T as WriteRead>::Error>

Reads the system drive fault state, False for no problems, True for a fault has been detected. Faults may indicate power problems, such as under-voltage (not enough power), and may be cleared by setting a lower drive power.

If a fault is persistent, it repeatably occurs when trying to control the board, this may indicate a wiring problem such as:

  • The supply is not powerful enough for the motors
    • The board has a bare minimum requirement of 6V to operate correctly
    • A recommended minimum supply of 7.2V should be sufficient for smaller motors
  • The + and - connections for either motor are connected to each other
  • Either + or - is connected to ground (Gnd, also known as 0V or earth)
  • Either + or - is connected to the power supply (V+, directly to the battery or power pack)
  • One of the motors may be damaged

Faults will self-clear, they do not need to be reset, however some faults require both motors to be moving at less than 100% to clear.

The easiest way to check is to put both motors at a low power setting which is high enough for them to rotate easily, such as 30%. Note that the fault state may be true at power up, this is normal and should clear when both motors have been driven.

If there are no faults but you cannot make your motors move check get_epo to see if the safety switch has been tripped.

For more details check the website at www.piborg.org/picoborgrev and double check the wiring instructions.

Source

pub fn set_encoder_move_mode( &mut self, state: bool, ) -> Result<(), <T as Write>::Error>

Sets the system to enable or disable the encoder based move mode. In encoder move mode (enabled) the encoder_move_motor* commands are available to move fixed distances. In non-encoder move mode (disabled) the set_motor* commands should be used to set drive levels.

The encoder move mode requires that the encoder feedback is attached to an encoder signal, see the website at www.piborg.org/picoborgrev for wiring instructions.

The encoder based move mode is disabled at power on.

Source

pub fn get_encoder_move_mode(&mut self) -> Result<bool, <T as WriteRead>::Error>

Read the current system state of the encoder based move mode, true for enabled (encoder moves), false for disabled (power level moves)

Source

pub fn encoder_move_motor_1( &mut self, counts: i16, ) -> Result<(), <T as Write>::Error>

Moves motor 1 until it has seen a number of encoder counts, up to 32767 Use negative values to move in reverse

Source

pub fn encoder_move_motor_2( &mut self, counts: i16, ) -> Result<(), <T as Write>::Error>

Moves motor 2 until it has seen a number of encoder counts. Use negative values to move in reverse.

Source

pub fn encoder_move_motors( &mut self, counts: i16, ) -> Result<(), <T as Write>::Error>

Moves all motors until it has seen a number of encoder counts. Use negative values to move in reverse.

Source

pub fn is_encoder_moving(&mut self) -> Result<bool, <T as WriteRead>::Error>

Reads the current state of the encoder motion, false for all motors have finished, true for any motor is still moving.

Source

pub fn wait_while_encoder_moving( &mut self, timeout: Duration, ) -> Result<bool, <T as WriteRead>::Error>

Waits until all motors have finished performing encoder based moves If the motors stop moving the function will return true or if the timeout occurs it will return false.

Source

pub fn set_encoder_speed( &mut self, power: f32, ) -> Result<(), <T as Write>::Error>

Sets the drive limit for encoder based moves, from 0 to 1.

Source

pub fn get_encoder_speed(&mut self) -> Result<f32, <T as WriteRead>::Error>

Gets the drive limit for encoder based moves, from 0 to 1.

Trait Implementations§

Source§

impl<T: Read + Write + WriteRead> Drop for PicoBorgRev<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PicoBorgRev<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PicoBorgRev<T>
where T: RefUnwindSafe,

§

impl<T> Send for PicoBorgRev<T>
where T: Send,

§

impl<T> Sync for PicoBorgRev<T>
where T: Sync,

§

impl<T> Unpin for PicoBorgRev<T>
where T: Unpin,

§

impl<T> UnwindSafe for PicoBorgRev<T>
where T: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.