use phoxal::api::y2026_1 as api;
use phoxal::prelude::*;
#[derive(phoxal::Runtime)]
#[phoxal(id = "avoid-obstacles", api = y2026_1)]
struct AvoidObstacles {
state: Latest<api::drive::State>,
target: Publisher<api::drive::Target>,
}
#[phoxal::runtime]
impl AvoidObstacles {
#[setup]
async fn setup(ctx: &mut SetupContext<Self>) -> Result<Self> {
Ok(Self {
state: ctx
.subscribe(api::topic::new().drive().state())
.latest()
.await?,
target: ctx.publisher(api::topic::new().drive().target()).await?,
})
}
#[step(hz = 50)]
async fn step(&mut self, step: StepContext) -> Result<()> {
let now = step.time();
let target = match self.state.latest() {
Some(_) => api::drive::Target {
linear_x_mps: 0.2,
angular_z_radps: 0.0,
},
None => api::drive::Target {
linear_x_mps: 0.0,
angular_z_radps: 0.0,
},
};
self.target.publish_at(now, target).await?;
Ok(())
}
#[shutdown]
async fn shutdown(&mut self) -> Result<()> {
Ok(())
}
}
fn main() -> phoxal::Result<()> {
phoxal::run::<AvoidObstacles>()
}