Skip to content
Draft
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
24 changes: 19 additions & 5 deletions mcu-util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,26 +298,38 @@ enum PolarizerOpts {
},
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum IrLedMode {
On,
Off,
}

#[derive(Parser, Debug, Clone, Copy)]
enum Camera {
#[clap(action)]
Eye {
/// Frames per second
#[clap(default_value = "30")]
fps: u32,
/// Whether to enable IR LEDs while triggering the camera
#[clap(long, value_enum, default_value = "on")]
irleds: IrLedMode,
},
#[clap(action)]
Face {
/// Frames per second
#[clap(default_value = "30")]
fps: u32,
/// Whether to enable IR LEDs while triggering the camera
#[clap(long, value_enum, default_value = "on")]
irleds: IrLedMode,
},
}

/// Optics tests options
#[derive(Parser, Debug, Clone, Copy)]
enum UiOpts {
/// Test front leds for 3 seconds
/// Test front LEDs for 3 seconds
#[clap(subcommand)]
Front(Leds),
}
Expand Down Expand Up @@ -475,11 +487,13 @@ async fn execute(args: Args) -> Result<()> {
.await?
}
OpticsOpts::TriggerCamera(camera) => {
let fps = match camera {
Camera::Eye { fps } => fps,
Camera::Face { fps } => fps,
let (fps, irleds) = match camera {
Camera::Eye { fps, irleds } => (fps, irleds),
Camera::Face { fps, irleds } => (fps, irleds),
};
orb.main_board_mut().trigger_camera(camera, fps).await?
orb.main_board_mut()
.trigger_camera(camera, fps, irleds)
.await?
}
OpticsOpts::Signup(opts) => {
orb.main_board_mut().signup_capture(opts).await?
Expand Down
81 changes: 45 additions & 36 deletions mcu-util/src/orb/main_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::orb::revision::OrbRevision;
use crate::orb::{dfu, BatteryStatus};
use crate::orb::{Board, OrbInfo};
use crate::{
Camera, GimbalHomeOpts, IrWavelength, Leds, PolarizerOpts, RebootBehavior,
SignupOpts,
Camera, GimbalHomeOpts, IrLedMode, IrWavelength, Leds, PolarizerOpts,
RebootBehavior, SignupOpts,
};
use orb_mcu_interface::can::canfd::CanRawMessaging;
use orb_mcu_interface::can::isotp::{CanIsoTpMessaging, IsoTpNodeIdentifier};
Expand Down Expand Up @@ -227,7 +227,12 @@ impl MainBoard {
}
}

pub async fn trigger_camera(&mut self, cam: Camera, fps: u32) -> Result<()> {
pub async fn trigger_camera(
&mut self,
cam: Camera,
fps: u32,
irleds: IrLedMode,
) -> Result<()> {
// set FPS to provided value
match self
.send(McuPayload::ToMain(
Expand All @@ -248,42 +253,46 @@ impl MainBoard {
}
}

// set on-duration to 300us
match self
.send(McuPayload::ToMain(
main_messaging::jetson_to_mcu::Payload::LedOnTime(
main_messaging::LedOnTimeUs {
on_duration_us: 300,
},
),
))
.await
{
Ok(CommonAckError::Success) => {
info!("💡 LED on duration set to 300us");
}
Ok(ack_err) => {
return Err(eyre!("Error setting on-duration: ack: {:?}", ack_err));
}
Err(e) => {
return Err(eyre!("Error setting on-duration: {:?}", e));
if irleds == IrLedMode::On {
// set on-duration to 300us
match self
.send(McuPayload::ToMain(
main_messaging::jetson_to_mcu::Payload::LedOnTime(
main_messaging::LedOnTimeUs {
on_duration_us: 300,
},
),
))
.await
{
Ok(CommonAckError::Success) => {
info!("💡 LED on duration set to 300us");
}
Ok(ack_err) => {
return Err(eyre!("Error setting on-duration: ack: {:?}", ack_err));
}
Err(e) => {
return Err(eyre!("Error setting on-duration: {:?}", e));
}
}
}

// enable wavelength 850nm
match self.send(McuPayload::ToMain(
main_messaging::jetson_to_mcu::Payload::InfraredLeds(main_messaging::InfraredLeDs {
wavelength: orb_messages::main::infrared_le_ds::Wavelength::Wavelength850nm as i32,
}))).await {
Ok(CommonAckError::Success) => {
info!("⚡️ 850nm infrared LEDs enabled");
}
Ok(ack_err) => {
return Err(eyre!("Error enabling infrared leds: ack: {:?}", ack_err));
}
Err(e) => {
return Err(eyre!("Error enabling infrared leds: {:?}", e));
// enable wavelength 850nm
match self.send(McuPayload::ToMain(
main_messaging::jetson_to_mcu::Payload::InfraredLeds(main_messaging::InfraredLeDs {
wavelength: orb_messages::main::infrared_le_ds::Wavelength::Wavelength850nm as i32,
}))).await {
Ok(CommonAckError::Success) => {
info!("⚡️ 850nm infrared LEDs enabled");
}
Ok(ack_err) => {
return Err(eyre!("Error enabling infrared LEDs: ack: {:?}", ack_err));
}
Err(e) => {
return Err(eyre!("Error enabling infrared LEDs: {:?}", e));
}
}
} else {
info!("💡 IR LEDs left unchanged");
}

// enable camera trigger
Expand Down
Loading