Make motor and Sensor selection dynamic
This commit is contained in:
parent
f730c0baf1
commit
b01c8b2daf
14
src/main.rs
14
src/main.rs
@ -3,11 +3,7 @@ mod display;
|
|||||||
|
|
||||||
use buttons::SmartEv3Buttons;
|
use buttons::SmartEv3Buttons;
|
||||||
use display::{draw_calibration, draw_driving, draw_finished, draw_settings, font, Parameter};
|
use display::{draw_calibration, draw_driving, draw_finished, draw_settings, font, Parameter};
|
||||||
use ev3dev_lang_rust::{
|
use ev3dev_lang_rust::{motors::LargeMotor, sensors::ColorSensor, Ev3Error, Ev3Result, Screen};
|
||||||
motors::{LargeMotor, MotorPort},
|
|
||||||
sensors::{ColorSensor, SensorPort},
|
|
||||||
Ev3Error, Ev3Result, Screen,
|
|
||||||
};
|
|
||||||
use pid::Pid;
|
use pid::Pid;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use rusttype::Font;
|
use rusttype::Font;
|
||||||
@ -19,9 +15,9 @@ use std::{
|
|||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let left_motor = LargeMotor::get(MotorPort::OutB)?;
|
let motors = LargeMotor::list()?;
|
||||||
let right_motor = LargeMotor::get(MotorPort::OutC)?;
|
let [right_motor, left_motor] = &motors[..] else {println!("motors: {motors:?}"); Err("need two motors")?};
|
||||||
let sensor = ColorSensor::get(SensorPort::In3)?;
|
let sensor = ColorSensor::find()?;
|
||||||
let mut buttons = SmartEv3Buttons::new()?;
|
let mut buttons = SmartEv3Buttons::new()?;
|
||||||
let mut screen = Screen::new()?;
|
let mut screen = Screen::new()?;
|
||||||
let font = font();
|
let font = font();
|
||||||
@ -42,7 +38,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
draw_driving(&mut screen, &font);
|
draw_driving(&mut screen, &font);
|
||||||
let result = follow_line(
|
let result = follow_line(
|
||||||
(&left_motor, &right_motor),
|
(left_motor, right_motor),
|
||||||
&sensor,
|
&sensor,
|
||||||
&mut buttons,
|
&mut buttons,
|
||||||
setpoint,
|
setpoint,
|
||||||
|
Loading…
Reference in New Issue
Block a user