Skip to content

Commit b453496

Browse files
committed
Clean up
1 parent 792fd56 commit b453496

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

crates/control/src/fall_state_detection.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use std::{collections::VecDeque, time::Duration};
1+
use core::panic;
2+
use std::{
3+
collections::VecDeque,
4+
time::{Duration, SystemTime},
5+
};
26

37
use color_eyre::Result;
48
use coordinate_systems::{Field, Robot};
@@ -11,7 +15,10 @@ use context_attribute::context;
1115
use framework::{deserialize_not_implemented, MainOutput};
1216
use tflite::{ops::builtin::BuiltinOpResolver, FlatBufferModel, InterpreterBuilder};
1317
use types::{
14-
cycle_time::CycleTime, fall_state::FallState, joints::Joints, sensor_data::SensorData,
18+
cycle_time::CycleTime,
19+
fall_state::{Direction, FallState, Kind, Side},
20+
joints::Joints,
21+
sensor_data::SensorData,
1522
};
1623

1724
#[derive(Deserialize, Serialize)]
@@ -55,7 +62,7 @@ pub struct CycleContext {
5562
#[context]
5663
#[derive(Default)]
5764
pub struct MainOutputs {
58-
pub fall_state: MainOutput<FallState>,
65+
pub fall_state_tinyml: MainOutput<FallState>,
5966
}
6067

6168
impl FallStateDetection {
@@ -122,7 +129,6 @@ impl FallStateDetection {
122129
interpreter.invoke()?;
123130

124131
let output: &[f32] = interpreter.tensor_data(output_index)?;
125-
dbg!(output);
126132

127133
let guess = output
128134
.iter()
@@ -131,10 +137,20 @@ impl FallStateDetection {
131137
.unwrap()
132138
.0;
133139

134-
dbg!(guess);
140+
let fall_state = match guess {
141+
0 => FallState::Upright,
142+
1 => FallState::Falling {
143+
start_time: SystemTime::UNIX_EPOCH,
144+
direction: Direction::Forward { side: Side::Left },
145+
},
146+
2 => FallState::Fallen {
147+
kind: Kind::FacingUp,
148+
},
149+
_ => panic!(),
150+
};
135151

136152
Ok(MainOutputs {
137-
fall_state: FallState::default().into(),
153+
fall_state_tinyml: fall_state.into(),
138154
})
139155
}
140156
}

0 commit comments

Comments
 (0)