diff --git a/Cargo.lock b/Cargo.lock index 34edf89..0dc8999 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1925,9 +1925,9 @@ dependencies = [ [[package]] name = "phoxal" -version = "0.5.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28e98fd325a693585a7ba0db4dfbffa940b913217630bd412c3e82f077f77ce4" +checksum = "c53144d1bcfbfcef30ee5f915f5376b4513199d4ff67b68f31a322661fde0b57" dependencies = [ "anyhow", "arc-swap", diff --git a/Cargo.toml b/Cargo.toml index acc9031..600dbf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/bno085/src/runtime.rs b/bno085/src/runtime.rs index adfd4d4..7dfe4c0 100644 --- a/bno085/src/runtime.rs +++ b/bno085/src/runtime.rs @@ -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}; @@ -136,9 +136,9 @@ pub struct Bno085Runtime { imu: Schedule, accelerometer: Schedule, gyroscope: Schedule, - imu_pub: TopicPublisher, - accelerometer_pub: TopicPublisher, - gyroscope_pub: TopicPublisher, + imu_pub: TopicPublisher, + accelerometer_pub: TopicPublisher, + gyroscope_pub: TopicPublisher, } #[async_trait::async_trait] @@ -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(), @@ -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(), @@ -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(), @@ -206,18 +203,22 @@ impl Runtime for Bno085Runtime { async fn step(&mut self, step: Step, _inputs: RuntimeInputs) -> 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(()) diff --git a/ddsm115/src/runtime.rs b/ddsm115/src/runtime.rs index 79d90a7..1b97a93 100644 --- a/ddsm115/src/runtime.rs +++ b/ddsm115/src/runtime.rs @@ -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}; @@ -94,7 +94,7 @@ impl SampledEncoder { } pub enum Input { - Command(Command), + Command(motor_v1::Command), } #[derive(Debug)] @@ -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"); } @@ -150,11 +150,11 @@ pub struct Ddsm115Runtime { actuator_backend: StubActuatorBackend, encoder_backend: StubEncoderBackend, encoder_schedule: Option, - encoder_pub: Option>, + encoder_pub: Option>, } 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"); } @@ -179,12 +179,13 @@ impl Runtime for Ddsm115Runtime { async fn new(io: &mut Io, config: Self::Config) -> Result { 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(); @@ -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, encoder: Option<&SampledEncoder>, -) -> Result>> { +) -> Result>> { 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(), diff --git a/vl53l1x/src/runtime.rs b/vl53l1x/src/runtime.rs index 4068ac3..6f2d308 100644 --- a/vl53l1x/src/runtime.rs +++ b/vl53l1x/src/runtime.rs @@ -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}; @@ -91,7 +91,7 @@ pub struct Vl53l1xRuntime { backend: StubBackend, default_distance_m: f32, schedule: Schedule, - range_pub: TopicPublisher, + range_pub: TopicPublisher, } #[async_trait::async_trait] @@ -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(), @@ -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(()) }