Currently this project is not compatible with the BrickPi platform.
extern crate ev3dev_lang_rust;
use std::io::Result;
use ev3dev_lang_rust::tacho_motor::{LargeMotor, TachoMotor};
use ev3dev_lang_rust::core::MotorPort;
use ev3dev_lang_rust::color_sensor::ColorSensor;
fn main() -> Result<()> {
// Get large motor on port outA.
let mut large_motor = LargeMotor::new(MotorPort::OutA).unwrap();
// 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 mut color_sensor = ColorSensor::find().unwrap();
// Switch to rgb mode.
color_sensor.set_mode_rgb_raw()?;
// Get current rgb color tuple.
println!("Current rgb color: {:?}", color_sensor.get_rgb()?);
Ok(())
}-
Create Dockerfile
FROM ubuntu:18.04 RUN apt update # 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 # Instull rust for host platform RUN curl https://sh.rustup.rs -sSf | sh -s -- -y ENV PATH "$PATH:/root/.cargo/bin" # Add stdlib for target platform RUN rustup target add armv5te-unknown-linux-gnueabi
-
Build docker image
docker build . -t pixix4/ev3dev-rust-cross -
Start docker image
docker run -it --rm -v $PWD:/build/ -w /build pixix4/ev3dev-rust-cross -
Build binary for ev3dev
cargo build --release --target armv5te-unknown-linux-gnueabi
The
--releaseflag 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