Skip to content

Commit

Permalink
Split arm worker to separate task
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rowe committed Oct 23, 2024
1 parent 8fdb038 commit 76aae47
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use arm::Arm;
use coordinate::PolarCoordinate;
use embassy_executor::Spawner;
use embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, channel::Channel};
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};

Expand All @@ -12,25 +13,32 @@ mod coordinate;
mod stepper;
mod stepper_pair;

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
static POSITION_CHANNEL: Channel<ThreadModeRawMutex, &PolarCoordinate, 10> = Channel::new();

#[embassy_executor::task]
async fn arm_task() {
let mut arm = Arm::new();
loop {
arm.move_to(&PolarCoordinate {
let coordinate: &PolarCoordinate = POSITION_CHANNEL.receive().await;
arm.move_to(coordinate).await;
}
}

#[embassy_executor::main]
async fn main(spawner: Spawner) {
spawner.spawn(arm_task()).unwrap();

Timer::after_secs(5).await;
POSITION_CHANNEL
.send(&PolarCoordinate {
theta: 0.0,
rho: 1.0,
})
.await;
arm.move_to(&PolarCoordinate {
theta: 1.57,
rho: 0.5,
})
.await;
arm.move_to(&PolarCoordinate {
POSITION_CHANNEL
.send(&PolarCoordinate {
theta: 0.0,
rho: 0.0,
})
.await;
Timer::after_secs(5).await;
}
}

0 comments on commit 76aae47

Please sign in to comment.