Crate ev3dev_lang_rust
source ·Expand description
Rust language bindings for ev3dev
extern crate ev3dev_lang_rust;
use ev3dev_lang_rust::Ev3Result;
use ev3dev_lang_rust::motors::{LargeMotor, MotorPort};
use ev3dev_lang_rust::sensors::ColorSensor;
fn main() -> Ev3Result<()> {
// Get large motor on port outA.
let large_motor = LargeMotor::get(MotorPort::OutA)?;
// Set command "run-direct".
large_motor.run_direct()?;
// Run motor.
large_motor.set_duty_cycle_sp(50)?;
// Find color sensor. Always returns the first recognized one.
let color_sensor = ColorSensor::find()?;
// Switch to rgb mode.
color_sensor.set_mode_rgb_raw()?;
// Get current rgb color tuple.
println!("Current rgb color: {:?}", color_sensor.get_rgb()?);
Ok(())
}Modules
- Container module for motor types
- Container module for sensor types
- Sound-related functions. It can beep, play wav files, or convert text to speech.
- Utility functions for cpu efficient
waitcommands. Uses thelibc::epoll_waitthat only works on linux systems.
Macros
- The DcMotor provides a uniform interface for using regular DC motors with no fancy controls or feedback. This includes LEGO MINDSTORMS RCX motors and LEGO Power Functions motors.
- Helper to create a new
Deviceinstance. - Add a sensor mode constant with getter and setter
- The ServoMotor provides a uniform interface for using hobby type servo motors.
- The TachoMotor provides a uniform interface for using motors with positional and directional feedback such as the EV3 and NXT motors. This feedback allows for precise control of the motors.
Structs
- A wrapper to a attribute file in the
/sys/class/directory. - Button
ev3Ev3 brick button handler. Opens the corresponding/dev/inputfile handlers. - Helper struct that manages attributes. It creates an
Attributeinstance if it does not exists or uses a cached one. - Led
ev3The led’s on top of the EV3 brick. - An interface to read data from the system’s power_supply class. Uses the built-in legoev3-battery if none is specified.
- Screen
screenRepresents the device screen. Advanced drawing operations can be performed with theimageproccrate.
Enums
- Custom error type for internal errors.
Traits
- The ev3dev device base trait
- EV3 ports
Type Definitions
- Helper
Resulttype for easy access.