From 0555f6f4813c2943301b812446eaa9e334fdaa25 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+Tropix126@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:11:14 -0600 Subject: [PATCH] docs: fix example --- packages/pros/examples/accessories.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/pros/examples/accessories.rs b/packages/pros/examples/accessories.rs index 811849f5..e9329a54 100644 --- a/packages/pros/examples/accessories.rs +++ b/packages/pros/examples/accessories.rs @@ -23,7 +23,7 @@ impl ExampleRobot { pub fn new(peripherals: Peripherals) -> Self { Self { motor: Arc::new(Mutex::new( - Motor::new(peripherals.port_2, Gearset::Green, false).unwrap(), + Motor::new(peripherals.port_2, Gearset::Green, Direction::Forward).unwrap(), )), vision: VisionSensor::new(peripherals.port_9, VisionZeroPoint::Center).unwrap(), } @@ -40,9 +40,6 @@ impl AsyncRobot for ExampleRobot { }); handle.await; - // Create a new motor plugged into port 2. The motor will brake when not moving. - // We'll wrap it in an Arc> to allow safe access to the device from multiple tasks. - self.motor.lock().wait_until_stopped().await?; // Create a controller, specifically controller 1. let controller = Controller::Master; @@ -56,14 +53,14 @@ impl AsyncRobot for ExampleRobot { move || loop { println!( "Motor stopped? {}", - motor.lock().get_state().unwrap_or_default().stopped + motor.lock().velocity() < 2 ); // Sleep the task as to not steal processing time from the OS. // This should always be done in any loop, including loops in the main task. // Because this is a real FreeRTOS task this is not the sleep function used elsewhere in this example. // This sleep function will block the entire task, including the async executor! (There isn't one running here, but there is in the main task.) - delay(Duration::from_millis(20)); + delay(Duration::from_millis(Motor::DATA_READ_RATE)); } }); @@ -72,7 +69,7 @@ impl AsyncRobot for ExampleRobot { // Set output takes a float from -1 to 1 that is scaled to -12 to 12 volts. self.motor .lock() - .set_output(controller.state()?.joysticks.right.y)?; + .set_voltage(Motor::MAX_VOLTAGE * controller.state()?.joysticks.right.y)?; // println!("pid out {}", pid.update(10.0, motor.position().into_degrees() as f32)); println!(