8 releases (5 breaking)

0.6.0 Jan 11, 2020
0.5.1 Dec 9, 2019
0.4.1 Apr 2, 2019
0.4.0 Sep 30, 2018
0.1.0 Sep 19, 2018

#28 in Hardware support

Download history 13/week @ 2019-10-09 30/week @ 2019-10-16 23/week @ 2019-10-23 16/week @ 2019-10-30 5/week @ 2019-11-06 8/week @ 2019-11-13 7/week @ 2019-11-20 15/week @ 2019-11-27 40/week @ 2019-12-04 284/week @ 2019-12-11 32/week @ 2019-12-18 7/week @ 2019-12-25 4/week @ 2020-01-01 87/week @ 2020-01-08 33/week @ 2020-01-15

161 downloads per month

MIT license

94KB
1.5K SLoC

Rust language bindings for ev3dev

Build Status Latest version

Notice

Currently this project is not compatible with the BrickPi platform.

Usage

extern crate ev3dev_lang_rust;

use ev3dev_lang_rust::prelude::*;
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 recognised 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(())
}

Cross compile for ev3 brick

  1. Create Dockerfile

    FROM debian:stretch
    
    RUN dpkg --add-architecture armel
    RUN apt update
    
    # Fix debian package alias
    RUN sed -i "s#deb http://security.debian.org/debian-security stretch/updates main#deb http://deb.debian.org/debian-security stretch/updates main#g" /etc/apt/sources.list
    
    # Install curl for rust installation
    # Install g++ as buildscript compiler
    # Install g++-arm-linux-gnueabi as cross compiler
    RUN apt --yes install curl g++ g++-arm-linux-gnueabi crossbuild-essential-armel
    
    # Instull rust for host platform
    RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
    
    ENV PATH "$PATH:/root/.cargo/bin"
    
    # Add stdlib for target platform
    RUN rustup target add armv5te-unknown-linux-gnueabi
    
    # docker run -it --rm -v $PWD:/build/ -w /build pixix4/ev3dev-rust-cross
    # cargo build --release --target armv5te-unknown-linux-gnueabi
    
  2. Build docker image

    docker build . -t pixix4/ev3dev-rust-cross
    
  3. Start docker image

    docker run -it --rm -v $PWD:/build/ -w /build pixix4/ev3dev-rust-cross
    
  4. Build binary for ev3dev

    cargo build --release --target armv5te-unknown-linux-gnueabi
    

    The --release flag is optional. However, it can speedup the execution time by a factor of 30.

The target binary is now in target/armv5te-unknown-linux-gnueabi/release/libev3dev_lang_rust.rlib

Dependencies

~0.5–0.8MB
~19K SLoC