Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async-trait = "0.1.89"
clap = { version = "4.6.1", features = ["derive"] }
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread", "time", "signal", "sync", "fs"] }
tracing = "0.1.44"
phoxal = { version = "0.5.0" }
phoxal = { version = "0.9.0" }

[workspace.lints.rust]
unused = "warn"
Expand Down
33 changes: 17 additions & 16 deletions bno085/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::time::Duration;

use anyhow::{Result, bail};
use phoxal::api::v1::component::capability::accelerometer::Sample as AccelerometerSample;
use phoxal::api::v1::component::capability::gyroscope::Sample as GyroscopeSample;
use phoxal::api::v1::component::capability::imu::Sample as ImuSample;
use phoxal::api::v1::topic;
use phoxal::api::component::capability::accelerometer::{self, v1 as accelerometer_v1};
use phoxal::api::component::capability::gyroscope::{self, v1 as gyroscope_v1};
use phoxal::api::component::capability::imu::{self, v1 as imu_v1};
use phoxal::api::topic;
use phoxal::model::component::v1::CapabilityRef;
use phoxal::model::component::v1::capability::Capability;
use phoxal::runtime::clock::{Schedule, SchedulePolicy, Step};
Expand Down Expand Up @@ -136,9 +136,9 @@ pub struct Bno085Runtime {
imu: Schedule,
accelerometer: Schedule,
gyroscope: Schedule,
imu_pub: TopicPublisher<ImuSample>,
accelerometer_pub: TopicPublisher<AccelerometerSample>,
gyroscope_pub: TopicPublisher<GyroscopeSample>,
imu_pub: TopicPublisher<imu::Sample>,
accelerometer_pub: TopicPublisher<accelerometer::Sample>,
gyroscope_pub: TopicPublisher<gyroscope::Sample>,
}

#[async_trait::async_trait]
Expand All @@ -161,7 +161,6 @@ impl Runtime for Bno085Runtime {
let imu_pub = io
.publisher_topic(
topic::new()
.v1()
.component(&config.imu.capability.component_id)
.imu(&config.imu.capability.capability_id)
.data(),
Expand All @@ -170,7 +169,6 @@ impl Runtime for Bno085Runtime {
let accelerometer_pub = io
.publisher_topic(
topic::new()
.v1()
.component(&config.accelerometer.capability.component_id)
.accelerometer(&config.accelerometer.capability.capability_id)
.data(),
Expand All @@ -179,7 +177,6 @@ impl Runtime for Bno085Runtime {
let gyroscope_pub = io
.publisher_topic(
topic::new()
.v1()
.component(&config.gyroscope.capability.component_id)
.gyroscope(&config.gyroscope.capability.capability_id)
.data(),
Expand All @@ -206,18 +203,22 @@ impl Runtime for Bno085Runtime {
async fn step(&mut self, step: Step, _inputs: RuntimeInputs<Self::Input>) -> Result<()> {
let at_ns = step.tick.time_ns();
if self.imu.due_steps(step.tick.time_ns()) > 0 {
let sample = ImuSample::new(self.backend.orientation().await?);
self.imu_pub.put(at_ns, &sample).await?;
let sample = imu_v1::Sample::new(self.backend.orientation().await?);
self.imu_pub.put(at_ns, &imu::Sample::V1(sample)).await?;
}

if self.accelerometer.due_steps(step.tick.time_ns()) > 0 {
let sample = AccelerometerSample::new(self.backend.accelerometer().await?);
self.accelerometer_pub.put(at_ns, &sample).await?;
let sample = accelerometer_v1::Sample::new(self.backend.accelerometer().await?);
self.accelerometer_pub
.put(at_ns, &accelerometer::Sample::V1(sample))
.await?;
}

if self.gyroscope.due_steps(step.tick.time_ns()) > 0 {
let sample = GyroscopeSample::new(self.backend.gyroscope().await?);
self.gyroscope_pub.put(at_ns, &sample).await?;
let sample = gyroscope_v1::Sample::new(self.backend.gyroscope().await?);
self.gyroscope_pub
.put(at_ns, &gyroscope::Sample::V1(sample))
.await?;
}

Ok(())
Expand Down
44 changes: 23 additions & 21 deletions ddsm115/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::time::Duration;

use anyhow::{Result, bail};
use phoxal::api::v1::component::capability::encoder::Sample;
use phoxal::api::v1::component::capability::motor::Command;
use phoxal::api::v1::topic;
use phoxal::api::component::capability::encoder::{self, v1 as encoder_v1};
use phoxal::api::component::capability::motor::{self, v1 as motor_v1};
use phoxal::api::topic;
use phoxal::model::component::v1::CapabilityRef;
use phoxal::model::component::v1::capability::{Capability, MotorCommand};
use phoxal::runtime::clock::{Schedule, SchedulePolicy, Step};
Expand Down Expand Up @@ -94,7 +94,7 @@ impl SampledEncoder {
}

pub enum Input {
Command(Command),
Command(motor_v1::Command),
}

#[derive(Debug)]
Expand All @@ -103,17 +103,17 @@ struct StubActuatorBackend {
}

impl StubActuatorBackend {
async fn apply_command(&mut self, command: Command) -> Result<()> {
async fn apply_command(&mut self, command: motor_v1::Command) -> Result<()> {
match command {
Command::Velocity(velocity_command) => {
motor_v1::Command::Velocity(velocity_command) => {
self.ensure_supported(MotorCommand::Velocity)?;
info!(velocity = velocity_command, "StubActuator set velocity");
}
Command::Position(position_command) => {
motor_v1::Command::Position(position_command) => {
self.ensure_supported(MotorCommand::Position)?;
info!(position = position_command, "StubActuator set position");
}
Command::Torque(torque_command) => {
motor_v1::Command::Torque(torque_command) => {
self.ensure_supported(MotorCommand::Torque)?;
info!(torque = torque_command, "StubActuator set torque");
}
Expand Down Expand Up @@ -150,11 +150,11 @@ pub struct Ddsm115Runtime {
actuator_backend: StubActuatorBackend,
encoder_backend: StubEncoderBackend,
encoder_schedule: Option<Schedule>,
encoder_pub: Option<TopicPublisher<Sample>>,
encoder_pub: Option<TopicPublisher<encoder::Sample>>,
}

impl Ddsm115Runtime {
async fn apply_command(&mut self, command: Command) {
async fn apply_command(&mut self, command: motor_v1::Command) {
if let Err(error) = self.actuator_backend.apply_command(command).await {
tracing::warn!(actuator_id = %self.actuator_id, error = %error, "motor command rejected by backend");
}
Expand All @@ -179,12 +179,13 @@ impl Runtime for Ddsm115Runtime {

async fn new(io: &mut Io<Self::Input>, config: Self::Config) -> Result<Self> {
let command_topic = topic::new()
.v1()
.component(&config.actuator_id.component_id)
.motor(&config.actuator_id.capability_id)
.command();
io.subscribe_topic(command_topic, |received| Input::Command(received.value))
.await?;
io.subscribe_topic(command_topic, |received| match received.value {
motor::Command::V1(command) => Input::Command(command),
})
.await?;

let encoder_pub = declare_encoder_publisher(io, config.encoder.as_ref()).await?;
let encoder_enabled = config.encoder.is_some();
Expand Down Expand Up @@ -223,33 +224,34 @@ impl Runtime for Ddsm115Runtime {
}

if let Some(publisher) = &self.encoder_pub {
let sample = Sample::new(self.encoder_backend.read().await?);
publisher.put(step.tick.time_ns(), &sample).await?;
let sample = encoder_v1::Sample::new(self.encoder_backend.read().await?);
publisher
.put(step.tick.time_ns(), &encoder::Sample::V1(sample))
.await?;
}

Ok(())
}
}

fn valid_command(command: &Command) -> bool {
fn valid_command(command: &motor_v1::Command) -> bool {
match command {
Command::Velocity(value) | Command::Position(value) | Command::Torque(value) => {
value.is_finite()
}
motor_v1::Command::Velocity(value)
| motor_v1::Command::Position(value)
| motor_v1::Command::Torque(value) => value.is_finite(),
}
}

async fn declare_encoder_publisher(
io: &mut Io<Input>,
encoder: Option<&SampledEncoder>,
) -> Result<Option<TopicPublisher<Sample>>> {
) -> Result<Option<TopicPublisher<encoder::Sample>>> {
let Some(encoder) = encoder else {
return Ok(None);
};
Ok(Some(
io.publisher_topic(
topic::new()
.v1()
.component(&encoder.capability.component_id)
.encoder(&encoder.capability.capability_id)
.data(),
Expand Down
13 changes: 7 additions & 6 deletions vl53l1x/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{Result, bail};
use phoxal::api::v1::component::capability::range::Sample;
use phoxal::api::v1::topic;
use phoxal::api::component::capability::range::{self, v1 as range_v1};
use phoxal::api::topic;
use phoxal::model::component::v1::CapabilityRef;
use phoxal::model::component::v1::capability::{Capability, Range as RangeConfig};
use phoxal::runtime::clock::{Schedule, SchedulePolicy, Step};
Expand Down Expand Up @@ -91,7 +91,7 @@ pub struct Vl53l1xRuntime {
backend: StubBackend,
default_distance_m: f32,
schedule: Schedule,
range_pub: TopicPublisher<Sample>,
range_pub: TopicPublisher<range::Sample>,
}

#[async_trait::async_trait]
Expand All @@ -114,7 +114,6 @@ impl Runtime for Vl53l1xRuntime {
let range_pub = io
.publisher_topic(
topic::new()
.v1()
.component(&config.range.capability.component_id)
.range(&config.range.capability.capability_id)
.data(),
Expand All @@ -134,8 +133,10 @@ impl Runtime for Vl53l1xRuntime {
return Ok(());
}

let sample = Sample::new(self.backend.distance_m(self.default_distance_m).await?);
self.range_pub.put(step.tick.time_ns(), &sample).await?;
let sample = range_v1::Sample::new(self.backend.distance_m(self.default_distance_m).await?);
self.range_pub
.put(step.tick.time_ns(), &range::Sample::V1(sample))
.await?;

Ok(())
}
Expand Down
Loading