pub struct ODrive<T>where
T: Read,{ /* private fields */ }Expand description
The ODrive struct manages a connection with an ODrive motor over the ASCII protocol.
It acts as a newtype around a connection stream.
This has been tested using serial types from serialport-rs.
Implementations§
Source§impl<T> ODrive<T>where
T: Read,
impl<T> ODrive<T>where
T: Read,
Sourcepub fn read_string(&mut self) -> Result<Option<String>>
pub fn read_string(&mut self) -> Result<Option<String>>
Reads the next message sent by the ODrive as a string.
If their is no message, this function should return None
It is suggested that you only use this if you are directly using the Write implementation
and are expecting a response, as normally the supplied for the ODrive can directly support
reading any response.
pub fn read_odrive_response(&mut self) -> ODriveResult<String>
Sourcepub fn read_float(&mut self) -> Result<Option<f32>>
pub fn read_float(&mut self) -> Result<Option<f32>>
Reads the next message as a float. This will return zero if the message is not a valid float.
It is suggested that you only use this if you are directly using the Write implementation
and are expecting a response, as normally the supplied for the ODrive can directly support
reading any response.
Sourcepub fn read_int(&mut self) -> Result<Option<i32>>
pub fn read_int(&mut self) -> Result<Option<i32>>
Reads the next message as an int. This will return zero if the message is not a valid int.
It is suggested that you only use this if you are directly using the Write implementation
and are expecting a response, as normally the supplied for the ODrive can directly support
reading any response.
Source§impl<T> ODrive<T>
impl<T> ODrive<T>
Sourcepub fn set_position_p(
&mut self,
axis: AxisID,
position: f32,
velocity_feed_forward: Option<f32>,
current_feed_forward: Option<f32>,
) -> Result<()>
pub fn set_position_p( &mut self, axis: AxisID, position: f32, velocity_feed_forward: Option<f32>, current_feed_forward: Option<f32>, ) -> Result<()>
Move the motor to a position. Use this command if you have a real-time controller which
is streaming setpoints and tracking a trajectory.
axis The motor to be used for the operation.
position is the desired position, in encoder counts.
velocity_feed_forward is the velocity feed forward term, in encoder counts per second.
current_feed_forward is the current feed forward term, in amps.
If None is supplied for a feed forward input, zero will be provided as a default.
Sourcepub fn set_position_q(
&mut self,
axis: AxisID,
position: f32,
velocity_limit: Option<f32>,
current_limit: Option<f32>,
) -> Result<()>
pub fn set_position_q( &mut self, axis: AxisID, position: f32, velocity_limit: Option<f32>, current_limit: Option<f32>, ) -> Result<()>
Move the motor to a position. Use this command if you are sending one setpoint at a time.
axis The motor to be used for the operation.
position is the desired position, in encoder counts.
velocity_limit is the velocity limit, in encoder counts per second.
current_limit is the current limit, in amps.
If None is supplied for a limit, zero will be provided as a default.
Sourcepub fn set_velocity(
&mut self,
axis: AxisID,
velocity: f32,
current_feed_forward: Option<f32>,
) -> Result<()>
pub fn set_velocity( &mut self, axis: AxisID, velocity: f32, current_feed_forward: Option<f32>, ) -> Result<()>
Specifies a velocity setpoint for the motor.
axis The motor to be used for the operation.
velocity is the velocity setpoint, in encoder counts per second.
current_feed_forward is the current feed forward term, in amps.
If None is supplied for a feed forward input, zero will be provided as a default.
Source§impl<T> ODrive<T>
impl<T> ODrive<T>
Sourcepub fn get_velocity(&mut self, axis: AxisID) -> Result<Option<f32>>
pub fn get_velocity(&mut self, axis: AxisID) -> Result<Option<f32>>
Retrieves the velocity of a motor, in counts per second.
Sourcepub fn run_state(
&mut self,
axis: AxisID,
requested_state: AxisState,
wait: bool,
) -> Result<bool>
pub fn run_state( &mut self, axis: AxisID, requested_state: AxisState, wait: bool, ) -> Result<bool>
Changes the state of an axis.
The wait flag indicates whether this command should block until the state is updated.
Returns true unless we are in blocking mode and the operation times out.
The current timeout is 10 seconds.
This command will likely be deprecated and reworked in a future release.
Source§impl<T> ODrive<T>
§Startup Configuration
The ODrive motor controllers have several optional startup procedures which can be enabled.
Each of them has an associated getter and setter which can be invoked to read to and write from
their value.
impl<T> ODrive<T>
§Startup Configuration
The ODrive motor controllers have several optional startup procedures which can be enabled. Each of them has an associated getter and setter which can be invoked to read to and write from their value.
From the official documentation:
By default the ODrive takes no action at startup and goes to idle immediately. In order to change what startup procedures are used, set the startup procedures you want to
true. The ODrive will sequence all enabled startup actions selected in the order shown below.
<axis>.config.startup_motor_calibration<axis>.config.startup_encoder_index_search<axis>.config.startup_encoder_offset_calibration<axis>.config.startup_closed_loop_control<axis>.config.startup_sensorless_control
For further information, see the documentation for AxisState.
pub fn set_startup_motor_calibration( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<()>
pub fn set_startup_encoder_index_search( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<()>
pub fn set_startup_encoder_offset_calibration( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<()>
pub fn set_startup_closed_loop_control( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<()>
pub fn set_startup_sensorless_control( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<()>
pub fn read_startup_motor_calibration( &mut self, axis: AxisID, ) -> ODriveResult<bool>
pub fn read_startup_encoder_index_search( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<bool>
pub fn read_startup_encoder_offset_calibration( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<bool>
pub fn read_startup_closed_loop_control( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<bool>
pub fn read_startup_sensorless_control( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<bool>
Source§impl<T> ODrive<T>
Configuration management.
impl<T> ODrive<T>
Configuration management.
Sourcepub fn save_configuration(&mut self) -> ODriveResult<()>
pub fn save_configuration(&mut self) -> ODriveResult<()>
Saves the current configuration of properties to the ODrives non-volatile memory, allowing the configuration to persist after reboots.
Sourcepub fn erase_configuration(&mut self) -> ODriveResult<()>
pub fn erase_configuration(&mut self) -> ODriveResult<()>
Reset the current configuration to the factory default settings.
Source§impl<T> ODrive<T>
Motor configuration
impl<T> ODrive<T>
Motor configuration
pub fn set_motor_pole_pairs( &mut self, axis: AxisID, value: u16, ) -> ODriveResult<()>
pub fn set_motor_resistance_calib_max_voltage( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_motor_requested_current_range( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_motor_current_control_bandwidth( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_motor_pre_calibrated( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<()>
Source§impl<T> ODrive<T>
Encoder configuration
impl<T> ODrive<T>
Encoder configuration
pub fn set_encoder_mode( &mut self, axis: AxisID, value: EncoderMode, ) -> ODriveResult<()>
pub fn set_encoder_cpr(&mut self, axis: AxisID, value: u16) -> ODriveResult<()>
pub fn set_encoder_bandwidth( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_encoder_pre_calibrated( &mut self, axis: AxisID, value: bool, ) -> ODriveResult<()>
Source§impl<T> ODrive<T>
Controller configuration
impl<T> ODrive<T>
Controller configuration
pub fn set_position_gain( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_velocity_gain( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_velocity_integrator_gain( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_velocity_limit( &mut self, axis: AxisID, value: f32, ) -> ODriveResult<()>
pub fn set_control_mode( &mut self, axis: AxisID, mode: ControlMode, ) -> ODriveResult<()>
Trait Implementations§
Source§impl<T> Read for ODrive<T>where
T: Read,
An implementation of Write has been provided as an escape hatch to enable the usage of
operations not yet supported by this library. Be advised that using this implementation may
place the connection into an inconsistent state.
impl<T> Read for ODrive<T>where
T: Read,
An implementation of Write has been provided as an escape hatch to enable the usage of
operations not yet supported by this library. Be advised that using this implementation may
place the connection into an inconsistent state.
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moreSource§impl<T> Write for ODrive<T>
An implementation of Write has been provided as an escape hatch to enable the usage of
operations not yet supported by this library.
impl<T> Write for ODrive<T>
An implementation of Write has been provided as an escape hatch to enable the usage of
operations not yet supported by this library.
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)