adds initial motor bravo implementation
This commit is contained in:
+29
-2
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user