Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
docs: fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
Tropix126 committed Mar 8, 2024
1 parent 86125ae commit 0555f6f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/pros/examples/accessories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand All @@ -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<Mutex<T>> 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;
Expand All @@ -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));
}
});

Expand All @@ -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!(
Expand Down

0 comments on commit 0555f6f

Please sign in to comment.