adds initial motor bravo implementation

This commit is contained in:
2026-08-19 19:24:28 -07:00
parent 47b1323af1
commit d9728b8680
25 changed files with 1081 additions and 123 deletions
+29 -2
View File
@@ -18,8 +18,12 @@ use tokio::select;
use tokio::sync::RwLock;
use tokio::sync::mpsc::{Sender, channel};
use tokio_util::sync::CancellationToken;
use nautilus_common::command::set_pwm::SetPwm;
const MAX_DATETIME: DateTime<Utc> = DateTime::from_timestamp_nanos(i64::MAX);
const PIN_PRIORITY: u8 = 1;
const RCS_PRIORITY: u8 = 1;
pub struct CommandHandler<'a> {
cmd: CommandRegistry,
@@ -60,6 +64,18 @@ impl From<RcsCommand> for SetRcs {
}
}
#[derive(IntoCommandDefinition)]
struct PwmCommand {
duty_cycle: u8
}
impl From<PwmCommand> for SetPwm {
fn from(value: PwmCommand) -> Self {
Self {
duty_cycle: value.duty_cycle
}
}
}
impl<'a> CommandHandler<'a> {
pub fn new(
client: Arc<Client>,
@@ -101,7 +117,7 @@ impl<'a> CommandHandler<'a> {
&ValidPriorityCommand {
inner: SetPin::from(cmd),
valid_until: MAX_DATETIME,
priority: 0,
priority: PIN_PRIORITY,
}
)?;
@@ -132,7 +148,7 @@ impl<'a> CommandHandler<'a> {
&ValidPriorityCommand {
inner: SetRcs::from(cmd),
valid_until: header.timestamp + TimeDelta::seconds(5),
priority: 0,
priority: RCS_PRIORITY,
}
)?;
@@ -140,6 +156,17 @@ impl<'a> CommandHandler<'a> {
}));
}
{
let outgoing_commands_tx = outgoing_commands_tx.clone();
commands.push(self.cmd.register_handler("pwm.set", move |_, cmd: PwmCommand| -> anyhow::Result<_> {
trace!("Sending Pwm Set Command");
outgoing_commands_tx.try_send_command("/pwm/set", &SetPwm::from(cmd))?;
Ok("Command Executed Successfully".to_string())
}));
}
// We no longer need this
drop(outgoing_commands_tx);