pub struct I2CDevices<'a, I2C: 'static> {
pub pwm: Option<Pca9685<RefCellDevice<'a, I2C>>>,
/* private fields */
}Expand description
High-level driver for PWM motor controller and IMU over a shared I2C bus.
Fields§
§pwm: Option<Pca9685<RefCellDevice<'a, I2C>>>Implementations§
Source§impl<'a, I2C, E> I2CDevices<'a, I2C>
impl<'a, I2C, E> I2CDevices<'a, I2C>
Sourcepub fn new(
i2c_bus: &'a RefCell<I2C>,
wheel_radius: f32,
robot_radius: f32,
) -> Self
pub fn new( i2c_bus: &'a RefCell<I2C>, wheel_radius: f32, robot_radius: f32, ) -> Self
Create a new I2CDevices manager with specified wheel and robot dimensions.
Sourcepub fn init_devices(&mut self) -> Result<(), DeviceError<E>>
pub fn init_devices(&mut self) -> Result<(), DeviceError<E>>
Initialize the IMU and PWM motor controller on the I2C bus.
On success, both self.imu and self.pwm are set. Returns error if initialization fails.
Sourcepub fn configure_pwm(&mut self) -> Result<(), DeviceError<E>>
pub fn configure_pwm(&mut self) -> Result<(), DeviceError<E>>
Configure and enable the PWM motor driver (prescale to 60Hz).
Sourcepub fn init_imu_data(&mut self)
pub fn init_imu_data(&mut self)
Perform an initial IMU data read and log accelerometer, gyro, and temperature.
Sourcepub fn execute_command(
&mut self,
command: I2CCommand,
) -> Result<Option<((f32, f32, f32), (f32, f32, f32), f32)>, DeviceError<E>>
pub fn execute_command( &mut self, command: I2CCommand, ) -> Result<Option<((f32, f32, f32), (f32, f32, f32), f32)>, DeviceError<E>>
Execute a high-level I2CCommand, performing motion or sensor operations.
Returns sensor data for ReadIMU or None for other commands.
Sourcepub fn apply_wheel_speeds(
&mut self,
wheel_speeds: &[f32],
) -> Result<(), DeviceError<E>>
pub fn apply_wheel_speeds( &mut self, wheel_speeds: &[f32], ) -> Result<(), DeviceError<E>>
Applies calculated motor speeds using the PWM driver.
Sourcepub fn read_imu(
&mut self,
) -> Result<((f32, f32, f32), (f32, f32, f32), f32), DeviceError<E>>
pub fn read_imu( &mut self, ) -> Result<((f32, f32, f32), (f32, f32, f32), f32), DeviceError<E>>
Read accelerometer, gyroscope, and temperature data from the IMU.
§Returns
Ok(((ax, ay, az), (gx, gy, gz), temp)) on success.
Sourcepub fn enable(&mut self) -> Result<(), DeviceError<E>>
pub fn enable(&mut self) -> Result<(), DeviceError<E>>
Enable the PWM motor controller and power up the IMU sensor.
Sourcepub fn disable(&mut self) -> Result<(), DeviceError<E>>
pub fn disable(&mut self) -> Result<(), DeviceError<E>>
Disable motor PWM and put the IMU into sleep mode.