Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create recovery timer mechanism #101

Merged
merged 12 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
clear interrupts
  • Loading branch information
Eilay Katsnelson committed May 4, 2024
commit 5249e3034b458b83614354cbb2cf3744a218d313
4 changes: 2 additions & 2 deletions boards/recovery/src/data_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::app::{fire_drogue, fire_main};
use crate::state_machine::RocketStates;
use atsamd_hal::timer::TimerCounter2;
use common_arm::{spawn, HydraError};
use defmt::info;
use heapless::HistoryBuffer;
Expand All @@ -20,6 +19,7 @@ pub struct DataManager {
pub gps_vel: Option<GpsVel>,
pub historical_barometer_altitude: HistoryBuffer<(f32, u32), 8>,
pub current_state: Option<RocketStates>,
// each tick represents a minute that passed
pub recovery_counter: u8,
NoahSprenger marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -103,7 +103,7 @@ impl DataManager {
match avg_sum / 7.0 {
// inclusive range
x if (-0.25..=0.25).contains(&x) => {
if (self.recovery_counter >= 15) {
if self.recovery_counter >= 15 {
return true;
}
spawn!(recovery_counter_tick);
NoahSprenger marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
20 changes: 11 additions & 9 deletions boards/recovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use state_machine::{StateMachine, StateMachineContext};
use systick_monotonic::*;
use types::COM_ID;
use hal::timer::TimerCounter2;

/// Custom panic handler.
/// Reset the system if a panic occurs.
Expand All @@ -49,7 +50,7 @@
led_green: Pin<PB16, PushPullOutput>,
led_red: Pin<PB17, PushPullOutput>,
state_machine: StateMachine,
recovery_timer: hal::timer::TimerCounter2,
recovery_timer: TimerCounter2,
}

#[monotonic(binds = SysTick, default = true)]
Expand Down Expand Up @@ -141,21 +142,22 @@
/// Idle task for when no other tasks are running.
#[idle]
fn idle(_: idle::Context) -> ! {
loop {}

Check warning on line 145 in boards/recovery/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

empty `loop {}` wastes CPU cycles

warning: empty `loop {}` wastes CPU cycles --> boards/recovery/src/main.rs:145:9 | 145 | loop {} | ^^^^^^^ | = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop = note: `#[warn(clippy::empty_loop)]` on by default
}

// handle recovery counter
// start a counter
#[task(local = [recovery_timer])]
fn recovery_counter_tick(mut cx: recovery_counter_tick::Context) {
fn recovery_counter_tick(cx: recovery_counter_tick::Context) {
let timer = cx.local.recovery_timer;
// should probably check if timer is already running
// to avoid resetting it

let duration_mins = atsamd_hal::fugit::MinutesDurationU32::minutes(1);
// timer requires specific duration format
let timer_duration: atsamd_hal::fugit::Duration<u32, 1, 1000000000> = duration_mins.convert();
timer.start(timer_duration);
// only start timer if it is not already running
if timer.wait().is_ok() {
let duration_mins = atsamd_hal::fugit::MinutesDurationU32::minutes(1);
// timer requires specific duration format
let timer_duration: atsamd_hal::fugit::Duration<u32, 1, 1000000000> = duration_mins.convert();
timer.enable_interrupt(); // clear interrupt?
timer.start(timer_duration);
}
}

// interrupt handler for when counter is finished
Expand Down
Loading