Make motor and Sensor selection dynamic

This commit is contained in:
Max Känner 2023-01-29 16:08:18 +01:00
parent f730c0baf1
commit b01c8b2daf

View File

@ -3,11 +3,7 @@ mod display;
use buttons::SmartEv3Buttons;
use display::{draw_calibration, draw_driving, draw_finished, draw_settings, font, Parameter};
use ev3dev_lang_rust::{
motors::{LargeMotor, MotorPort},
sensors::{ColorSensor, SensorPort},
Ev3Error, Ev3Result, Screen,
};
use ev3dev_lang_rust::{motors::LargeMotor, sensors::ColorSensor, Ev3Error, Ev3Result, Screen};
use pid::Pid;
use rand::{thread_rng, Rng};
use rusttype::Font;
@ -19,9 +15,9 @@ use std::{
use thiserror::Error;
fn main() -> Result<(), Box<dyn Error>> {
let left_motor = LargeMotor::get(MotorPort::OutB)?;
let right_motor = LargeMotor::get(MotorPort::OutC)?;
let sensor = ColorSensor::get(SensorPort::In3)?;
let motors = LargeMotor::list()?;
let [right_motor, left_motor] = &motors[..] else {println!("motors: {motors:?}"); Err("need two motors")?};
let sensor = ColorSensor::find()?;
let mut buttons = SmartEv3Buttons::new()?;
let mut screen = Screen::new()?;
let font = font();
@ -42,7 +38,7 @@ fn main() -> Result<(), Box<dyn Error>> {
draw_driving(&mut screen, &font);
let result = follow_line(
(&left_motor, &right_motor),
(left_motor, right_motor),
&sensor,
&mut buttons,
setpoint,