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

Use SBG sensor status #47

Merged
merged 14 commits into from
Mar 19, 2024
Merged
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ jobs:
# with:
# command: make
# args: test-device --no-run
test:
runs-on: ubuntu-latest
env:
RUST_MIN_STACK: 8388608
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed if Cargo Make sets it itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is needed as I tested before with the stack increase only in the Cargo Make.

steps:
- uses: actions/checkout@v2
- name: Install packages
run: sudo apt update && sudo apt install -y cmake
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions-rs/cargo@v1
name: "Install cargo-make"
with:
command: install
args: --force cargo-make
- uses: actions-rs/cargo@v1
name: "Run Host Tests"
with:
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"boards/*",
Expand Down
3 changes: 2 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ dependencies = [

[tasks.test-messages]
command = "cargo"
args = ["test", "-p", "messages", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"]
args = ["test", "-p", "messages", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}", "--features", "std", "--no-default-features"]
env = {RUST_MIN_STACK = "8388608"}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment documenting why this is needed. Also, is this value special in any way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 The value is not special.


# -----------------------
# Embedded Testing
Expand Down
20 changes: 19 additions & 1 deletion boards/beacon/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
pub air: Option<Message>,
pub ekf_nav_1: Option<Message>,
pub ekf_nav_2: Option<Message>,
pub ekf_nav_acc: Option<Message>,
pub ekf_quat: Option<Message>,
pub imu_1: Option<Message>,
pub imu_2: Option<Message>,
pub utc_time: Option<Message>,
pub gps_vel: Option<Message>,
pub gps_vel_acc: Option<Message>,
pub gps_pos_1: Option<Message>,
pub gps_pos_2: Option<Message>,
pub gps_pos_acc: Option<Message>,
pub state: Option<StateData>,
pub logging_rate: Option<RadioRate>,
}
Expand All @@ -24,41 +27,47 @@
air: None,
ekf_nav_1: None,
ekf_nav_2: None,
ekf_nav_acc: None,
ekf_quat: None,
imu_1: None,
imu_2: None,
utc_time: None,
gps_vel: None,
gps_vel_acc: None,
gps_pos_1: None,
gps_pos_2: None,
gps_pos_acc: None,
state: None,
logging_rate: Some(RadioRate::Slow), // start slow.
}
}

pub fn get_logging_rate(&mut self) -> RadioRate {

Check warning on line 45 in boards/beacon/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

methods `get_logging_rate`, `take_sensors`, `clone_states`, and `handle_data` are never used

warning: methods `get_logging_rate`, `take_sensors`, `clone_states`, and `handle_data` are never used --> boards/beacon/src/data_manager.rs:45:12 | 24 | impl DataManager { | ---------------- methods in this implementation ... 45 | pub fn get_logging_rate(&mut self) -> RadioRate { | ^^^^^^^^^^^^^^^^ ... 56 | pub fn take_sensors(&mut self) -> [Option<Message>; 13] { | ^^^^^^^^^^^^ ... 74 | pub fn clone_states(&self) -> [Option<StateData>; 1] { | ^^^^^^^^^^^^ ... 77 | pub fn handle_data(&mut self, data: Message) { | ^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
if let Some(rate) = self.logging_rate.take() {
let rate_cln = rate.clone();
self.logging_rate = Some(rate);
return rate_cln;
}
self.logging_rate = Some(RadioRate::Slow);
return RadioRate::Slow;

Check warning on line 52 in boards/beacon/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/beacon/src/data_manager.rs:52:9 | 52 | return RadioRate::Slow; | ^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `#[warn(clippy::needless_return)]` on by default help: remove `return` | 52 - return RadioRate::Slow; 52 + RadioRate::Slow |
}

/// Do not clone instead take to reduce CPU load.
pub fn take_sensors(&mut self) -> [Option<Message>; 10] {
pub fn take_sensors(&mut self) -> [Option<Message>; 13] {
[
self.air.take(),
self.ekf_nav_1.take(),
self.ekf_nav_2.take(),
self.ekf_nav_acc.take(),
self.ekf_quat.take(),
self.imu_1.take(),
self.imu_2.take(),
self.utc_time.take(),
self.gps_vel.take(),
self.gps_vel_acc.take(),
self.gps_pos_1.take(),
self.gps_pos_2.take(),
self.gps_pos_acc.take(),
]
}

Expand All @@ -68,6 +77,12 @@
pub fn handle_data(&mut self, data: Message) {
match data.data {
messages::Data::Sensor(ref sensor) => match sensor.data {
messages::sensor::SensorData::EkfNavAcc(_) => {
self.ekf_nav_acc = Some(data);
}
messages::sensor::SensorData::GpsPosAcc(_) => {
self.gps_pos_acc = Some(data);
}
messages::sensor::SensorData::Air(_) => {
self.air = Some(data);
}
Expand All @@ -83,6 +98,9 @@
messages::sensor::SensorData::GpsVel(_) => {
self.gps_vel = Some(data);
}
messages::sensor::SensorData::GpsVelAcc(_) => {
self.gps_vel_acc = Some(data);
}
messages::sensor::SensorData::Imu1(_) => {
self.imu_1 = Some(data);
}
Expand Down
10 changes: 8 additions & 2 deletions boards/camera/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
}
pub fn is_launched(&self) -> bool {
match self.air.as_ref() {
Some(air) => air.altitude > HEIGHT_MIN,
Some(air) => match air.altitude {
Some(altitude) => altitude > HEIGHT_MIN,
None => false,
}
None => false,
}
}
Expand Down Expand Up @@ -100,18 +103,21 @@
}
pub fn is_below_main(&self) -> bool {
match self.air.as_ref() {
Some(air) => air.altitude < MAIN_HEIGHT,
Some(air) => match air.altitude {
Some(altitude) => altitude < MAIN_HEIGHT,
None => false
}
None => false,
}
}
pub fn handle_data(&mut self, data: Message) {
match data.data {
messages::Data::Sensor(sensor) => match sensor.data {
messages::sensor::SensorData::Air(air_data) => {
self.air = Some(air_data);
}
_ => {}
},

Check warning on line 120 in boards/camera/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> boards/camera/src/data_manager.rs:115:47 | 115 | messages::Data::Sensor(sensor) => match sensor.data { | _______________________________________________^ 116 | | messages::sensor::SensorData::Air(air_data) => { 117 | | self.air = Some(air_data); 118 | | } 119 | | _ => {} 120 | | }, | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try | 115 ~ messages::Data::Sensor(sensor) => if let messages::sensor::SensorData::Air(air_data) = sensor.data { 116 + self.air = Some(air_data); 117 ~ }, |
_ => {}
}

Check warning on line 122 in boards/camera/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> boards/camera/src/data_manager.rs:114:9 | 114 | / match data.data { 115 | | messages::Data::Sensor(sensor) => match sensor.data { 116 | | messages::sensor::SensorData::Air(air_data) => { 117 | | self.air = Some(air_data); ... | 121 | | _ => {} 122 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try | 114 ~ if let messages::Data::Sensor(sensor) = data.data { match sensor.data { 115 + messages::sensor::SensorData::Air(air_data) => { 116 + self.air = Some(air_data); 117 + } 118 + _ => {} 119 + } } |
}
Expand Down
20 changes: 19 additions & 1 deletion boards/communication/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
pub air: Option<Message>,
pub ekf_nav_1: Option<Message>,
pub ekf_nav_2: Option<Message>,
pub ekf_nav_acc: Option<Message>,
pub ekf_quat: Option<Message>,
pub imu_1: Option<Message>,
pub imu_2: Option<Message>,
pub utc_time: Option<Message>,
pub gps_vel: Option<Message>,
pub gps_vel_acc: Option<Message>,
pub gps_pos_1: Option<Message>,
pub gps_pos_2: Option<Message>,
pub gps_pos_acc: Option<Message>,
pub state: Option<StateData>,
pub logging_rate: Option<RadioRate>,
}
Expand All @@ -24,13 +27,16 @@
air: None,
ekf_nav_1: None,
ekf_nav_2: None,
ekf_nav_acc: None,
ekf_quat: None,
imu_1: None,
imu_2: None,
utc_time: None,
gps_vel: None,
gps_vel_acc: None,
gps_pos_1: None,
gps_pos_2: None,
gps_pos_acc: None,
state: None,
logging_rate: Some(RadioRate::Slow), // start slow.
}
Expand All @@ -43,22 +49,25 @@
return rate_cln;
}
self.logging_rate = Some(RadioRate::Slow);
return RadioRate::Slow;

Check warning on line 52 in boards/communication/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/data_manager.rs:52:9 | 52 | return RadioRate::Slow; | ^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 52 - return RadioRate::Slow; 52 + RadioRate::Slow |
}

/// Do not clone instead take to reduce CPU load.
pub fn take_sensors(&mut self) -> [Option<Message>; 10] {
pub fn take_sensors(&mut self) -> [Option<Message>; 13] {
[
self.air.take(),
self.ekf_nav_1.take(),
self.ekf_nav_2.take(),
self.ekf_nav_acc.take(),
self.ekf_quat.take(),
self.imu_1.take(),
self.imu_2.take(),
self.utc_time.take(),
self.gps_vel.take(),
self.gps_vel_acc.take(),
self.gps_pos_1.take(),
self.gps_pos_2.take(),
self.gps_pos_acc.take(),
]
}

Expand All @@ -68,6 +77,12 @@
pub fn handle_data(&mut self, data: Message) {
match data.data {
messages::Data::Sensor(ref sensor) => match sensor.data {
messages::sensor::SensorData::EkfNavAcc(_) => {
self.ekf_nav_acc = Some(data);
}
messages::sensor::SensorData::GpsPosAcc(_) => {
self.gps_pos_acc = Some(data);
}
messages::sensor::SensorData::Air(_) => {
self.air = Some(data);
}
Expand All @@ -83,6 +98,9 @@
messages::sensor::SensorData::GpsVel(_) => {
self.gps_vel = Some(data);
}
messages::sensor::SensorData::GpsVelAcc(_) => {
self.gps_vel_acc = Some(data);
}
messages::sensor::SensorData::Imu1(_) => {
self.imu_1 = Some(data);
}
Expand Down
2 changes: 1 addition & 1 deletion boards/power/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pub fn new() -> Self {
Self {}
}
pub fn handle_data(&mut self, data: Message) {
pub fn handle_data(&mut self, _data: Message) {

Check warning on line 10 in boards/power/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

method `handle_data` is never used

warning: method `handle_data` is never used --> boards/power/src/data_manager.rs:10:12 | 6 | impl DataManager { | ---------------- method in this implementation ... 10 | pub fn handle_data(&mut self, _data: Message) { | ^^^^^^^^^^^
// to do
}
}
Expand Down
31 changes: 23 additions & 8 deletions boards/recovery/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ impl DataManager {
}
pub fn is_launched(&self) -> bool {
match self.air.as_ref() {
Some(air) => air.altitude > HEIGHT_MIN,
Some(air) => match air.altitude {
Some(altitude) => altitude > HEIGHT_MIN,
None => false,
}
None => false,
}
}
Expand Down Expand Up @@ -114,7 +117,10 @@ impl DataManager {
}
pub fn is_below_main(&self) -> bool {
match self.air.as_ref() {
Some(air) => air.altitude < MAIN_HEIGHT,
Some(air) => match air.altitude {
Some(altitude) => altitude < MAIN_HEIGHT,
None => false,
}
None => false,
}
}
Expand All @@ -125,14 +131,23 @@ impl DataManager {
match data.data {
messages::Data::Sensor(sensor) => match sensor.data {
messages::sensor::SensorData::Air(air_data) => {
let tup_data = (air_data.altitude, air_data.time_stamp);
self.air = Some(air_data);
if let Some(recent) = self.historical_barometer_altitude.recent() {
if recent.1 != tup_data.1 {
/*
NOTE!!!
There should be added a counter to check how many times
the alt is dropped, if the number is high switch to
the on board barometer.
*/

if let Some(alt) = air_data.altitude {
let tup_data: (f32, u32) = (alt, air_data.time_stamp);
self.air = Some(air_data);
if let Some(recent) = self.historical_barometer_altitude.recent() {
if recent.1 != tup_data.1 {
self.historical_barometer_altitude.write(tup_data);
}
} else {
self.historical_barometer_altitude.write(tup_data);
}
} else {
self.historical_barometer_altitude.write(tup_data);
}
}
messages::sensor::SensorData::EkfNav1(nav1_data) => {
Expand Down
15 changes: 9 additions & 6 deletions boards/sensor/src/data_manager.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::app::sleep_system;
use common_arm::{spawn, HydraError};
use messages::sensor::{
Air, EkfNav1, EkfNav2, EkfQuat, GpsPos1, GpsPos2, GpsVel, Imu1, Imu2, SensorData, UtcTime,
Air, EkfNav1, EkfNav2, EkfQuat, GpsPos1, GpsPos2, GpsVel, Imu1, Imu2, SensorData, UtcTime, EkfNavAcc, GpsPosAcc, GpsVelAcc,
};
use messages::Message;

#[derive(Clone)]
pub struct DataManager {
pub air: Option<Air>,
pub ekf_nav: Option<(EkfNav1, EkfNav2)>,
pub ekf_nav: Option<(EkfNav1, EkfNav2, EkfNavAcc)>,
pub ekf_quat: Option<EkfQuat>,
pub imu: Option<(Imu1, Imu2)>,
pub utc_time: Option<UtcTime>,
pub gps_vel: Option<GpsVel>,
pub gps_pos: Option<(GpsPos1, GpsPos2)>,
pub gps_vel: Option<(GpsVel, GpsVelAcc)>,
pub gps_pos: Option<(GpsPos1, GpsPos2, GpsPosAcc)>,
}

impl DataManager {
Expand All @@ -29,18 +29,21 @@ impl DataManager {
}
}

pub fn clone_sensors(&self) -> [Option<SensorData>; 10] {
pub fn clone_sensors(&self) -> [Option<SensorData>; 13] {
[
self.air.clone().map(|x| x.into()),
self.ekf_nav.clone().map(|x| x.0.into()),
self.ekf_nav.clone().map(|x| x.1.into()),
self.ekf_nav.clone().map(|x| x.2.into()),
self.ekf_quat.clone().map(|x| x.into()),
self.imu.clone().map(|x| x.0.into()),
self.imu.clone().map(|x| x.1.into()),
self.utc_time.clone().map(|x| x.into()),
self.gps_vel.clone().map(|x| x.into()),
self.gps_vel.clone().map(|x| x.0.into()),
self.gps_vel.clone().map(|x| x.1.into()),
self.gps_pos.clone().map(|x| x.0.into()),
self.gps_pos.clone().map(|x| x.1.into()),
self.gps_pos.clone().map(|x| x.2.into()),
]
}

Expand Down
8 changes: 6 additions & 2 deletions libraries/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ defmt = "0.3.2"
fugit = "0.3.6"
heapless = "0.7.16"
ts-rs = { version = "6.2.1", optional = true }
mavlink = { git = "https://github.com/uorocketry/rust-mavlink", default-features = false}
mavlink = { git = "https://github.com/uorocketry/rust-mavlink", default-features = false }
bitflags = { version = "2.3.1", features = ["serde"] }
proptest = { version = "1.2.0", optional = true }
proptest-derive = { version = "0.3.0", optional = true }
messages-proc-macros-lib = { path = "messages-proc-macros-lib" }

[dev-dependencies]
proptest = "1.2.0"
Expand All @@ -21,5 +25,5 @@ postcard = { version = "1.0.4", features = ["alloc"] }

[features]
default = ["mavlink/embedded", "mavlink/uorocketry"]
std = ["mavlink/default"]
std = ["mavlink/default", "dep:proptest", "dep:proptest-derive"]
ts = ["std", "dep:ts-rs"]
Loading
Loading