Skip to content

Commit 76b2813

Browse files
committed
fix: fixed compiler errors in main file, fixed trait mismatch, resolved compiler warnings
1 parent 5887a46 commit 76b2813

8 files changed

Lines changed: 60 additions & 96 deletions

File tree

src/main.rs

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,12 @@ use sw8s_rust_lib::{
1414
missions::{
1515
action::ActionExec,
1616
action_context::FullActionContext,
17-
align_buoy::{buoy_align, buoy_align_shot},
1817
basic::descend_and_go_forward,
1918
bin::bin,
20-
circle_buoy::{
21-
buoy_circle_sequence, buoy_circle_sequence_blind, buoy_circle_sequence_model,
22-
},
23-
coinflip::{coinflip, coinflip_procedural},
19+
coinflip::coinflip_procedural,
2420
example::{initial_descent, pid_test},
2521
fire_torpedo::{FireLeftTorpedo, FireRightTorpedo},
26-
gate::{
27-
gate_run_complex, gate_run_cv_procedural, gate_run_dead_reckon, gate_run_naive,
28-
gate_run_procedural, gate_run_testing,
29-
},
22+
gate::{gate_run_cv_procedural, gate_run_dead_reckon, gate_run_procedural},
3023
meb::WaitArm,
3124
octagon::octagon,
3225
path_align::{path_align_procedural, static_align_procedural},
@@ -37,15 +30,14 @@ use sw8s_rust_lib::{
3730
vision::PIPELINE_KILL,
3831
},
3932
video_source::appsink::Camera,
40-
vision::buoy::Target,
4133
TIMESTAMP,
4234
};
4335
use tokio::{
4436
io::WriteHalf,
4537
signal,
4638
sync::{
4739
mpsc::{self, UnboundedSender},
48-
OnceCell, RwLock, Semaphore,
40+
OnceCell, Semaphore,
4941
},
5042
time::{sleep, timeout},
5143
};
@@ -129,13 +121,6 @@ async fn bottom_cam() -> &'static Camera {
129121
.await
130122
}
131123

132-
static GATE_TARGET: OnceCell<RwLock<Target>> = OnceCell::const_new();
133-
async fn gate_target() -> &'static RwLock<Target> {
134-
GATE_TARGET
135-
.get_or_init(|| async { RwLock::new(Target::Earth1) })
136-
.await
137-
}
138-
139124
static STATIC_CONTEXT: OnceCell<FullActionContext<WriteHalf<SerialStream>>> = OnceCell::const_new();
140125
async fn static_context() -> &'static FullActionContext<'static, WriteHalf<SerialStream>> {
141126
STATIC_CONTEXT
@@ -145,7 +130,6 @@ async fn static_context() -> &'static FullActionContext<'static, WriteHalf<Seria
145130
meb().await,
146131
front_cam().await,
147132
bottom_cam().await,
148-
gate_target().await,
149133
)
150134
})
151135
.await
@@ -369,23 +353,6 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
369353
meb().await,
370354
front_cam().await,
371355
bottom_cam().await,
372-
gate_target().await,
373-
))
374-
.execute()),
375-
"gate_run_naive" => ctwrap!(gate_run_naive(&FullActionContext::new(
376-
control_board().await,
377-
meb().await,
378-
front_cam().await,
379-
bottom_cam().await,
380-
gate_target().await,
381-
))
382-
.execute()),
383-
"gate_run_complex" => ctwrap!(gate_run_complex(&FullActionContext::new(
384-
control_board().await,
385-
meb().await,
386-
front_cam().await,
387-
bottom_cam().await,
388-
gate_target().await,
389356
))
390357
.execute()),
391358
"gate_run_coinflip" => ctwrap!(gate_run_cv_procedural(
@@ -394,7 +361,6 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
394361
meb().await,
395362
front_cam().await,
396363
bottom_cam().await,
397-
gate_target().await,
398364
),
399365
&config.missions.gate,
400366
&config.get_color_profile().unwrap(),
@@ -405,7 +371,6 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
405371
meb().await,
406372
front_cam().await,
407373
bottom_cam().await,
408-
gate_target().await,
409374
),
410375
&config.missions.gate
411376
)),
@@ -415,19 +380,9 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
415380
meb().await,
416381
front_cam().await,
417382
bottom_cam().await,
418-
gate_target().await,
419383
),
420384
&config.missions.gate,
421-
&config.get_color_profile().unwrap(),
422385
)),
423-
"gate_run_testing" => ctwrap!(gate_run_testing(&FullActionContext::new(
424-
control_board().await,
425-
meb().await,
426-
front_cam().await,
427-
bottom_cam().await,
428-
gate_target().await,
429-
))
430-
.execute()),
431386
"start_cam" => {
432387
// This has not been tested
433388
logln!("Opening camera");
@@ -442,7 +397,6 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
442397
meb().await,
443398
front_cam().await,
444399
bottom_cam().await,
445-
gate_target().await,
446400
),
447401
&config.missions.path_align,
448402
&config.get_color_profile().unwrap(),
@@ -453,7 +407,6 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
453407
meb().await,
454408
front_cam().await,
455409
bottom_cam().await,
456-
gate_target().await,
457410
),
458411
&config.missions.path_align,
459412
)),
@@ -462,15 +415,13 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
462415
meb().await,
463416
front_cam().await,
464417
bottom_cam().await,
465-
gate_target().await,
466418
))
467419
.execute()),
468420
"pid_test" => ctwrap!(pid_test(&FullActionContext::new(
469421
control_board().await,
470422
meb().await,
471423
front_cam().await,
472424
bottom_cam().await,
473-
gate_target().await,
474425
))
475426
.execute()),
476427
"octagon" => ctwrap!(octagon(
@@ -479,22 +430,7 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
479430
&config.get_color_profile().unwrap()
480431
)
481432
.execute()),
482-
"buoy_circle" => ctwrap!(buoy_circle_sequence(&FullActionContext::new(
483-
control_board().await,
484-
meb().await,
485-
front_cam().await,
486-
bottom_cam().await,
487-
gate_target().await,
488-
))
489-
.execute()),
490-
"buoy_model" => ctwrap!(buoy_circle_sequence_model(static_context().await).execute()),
491-
"buoy_blind" => ctwrap!(buoy_circle_sequence_blind(static_context().await).execute()),
492-
"buoy_align" => ctwrap!(buoy_align(static_context().await).execute()),
493-
"spin" => ctwrap!(spin(static_context().await).execute()),
494-
"torpedo" | "fire_torpedo" => {
495-
let _ = buoy_align_shot(static_context().await).execute().await;
496-
Ok(())
497-
}
433+
"spin" => ctwrap!(spin(static_context().await, &config.missions.spin)),
498434
"torpedo_only" => {
499435
FireRightTorpedo::new(static_context().await)
500436
.execute()
@@ -538,7 +474,7 @@ async fn run_mission(mission: &str, cancel: CancellationToken) -> Result<()> {
538474
let _ = sonar(static_context().await, &config.sonar, cancel).await;
539475
Ok(())
540476
}
541-
"bin" => ctwrap!(bin(static_context().await, &config.missions.bin)),
477+
"bin" => ctwrap!(bin(static_context().await)),
542478
x => bail!("Invalid argument: [{x}]"),
543479
};
544480

src/missions/gate.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub async fn gate_run_cv_procedural<
105105
.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, initial_yaw, config.depth)
106106
.await;
107107

108-
const TOLERANCE: f32 = 0.3;
108+
// const TOLERANCE: f32 = 0.3;
109109

110110
let mut gate_state = GateState::Align;
111111
let mut yaw_target = 0.0;
@@ -120,25 +120,25 @@ pub async fn gate_run_cv_procedural<
120120
vec![]
121121
});
122122

123-
let leftPole = detections.iter().filter(|d| *d.class()).collect_vec();
124-
let leftPole_avg_x = leftPole
123+
let left_pole = detections.iter().filter(|d| *d.class()).collect_vec();
124+
let left_pole_avg_x = left_pole
125125
.iter()
126126
.map(|d| *d.position().x() as f32)
127127
.sum::<f32>();
128128

129-
let rightPole = detections.iter().filter(|d| !*d.class()).collect_vec();
130-
let rightPole_avg_x = rightPole
129+
let right_pole = detections.iter().filter(|d| !*d.class()).collect_vec();
130+
let right_pole_avg_x = right_pole
131131
.iter()
132132
.map(|d| *d.position().x() as f32)
133133
.sum::<f32>();
134134

135135
match gate_state {
136136
GateState::Align => match config.side {
137137
Side::Left => {
138-
if leftPole.len() > 0 {
138+
if left_pole.len() > 0 {
139139
false_count = 0;
140-
let mut correction;
141-
if leftPole_avg_x < 0.2 {
140+
let correction;
141+
if left_pole_avg_x < 0.2 {
142142
true_count += 1;
143143
if true_count >= config.true_count {
144144
#[cfg(feature = "logging")]
@@ -153,7 +153,7 @@ pub async fn gate_run_cv_procedural<
153153
logln!("true_count: {true_count}/4");
154154
}
155155
} else {
156-
correction = dbg!(config.correction_factor * leftPole_avg_x);
156+
correction = dbg!(config.correction_factor * left_pole_avg_x);
157157
let _ = cb
158158
.stability_1_speed_set(0.0, 0.0, correction, 0.0, 0.0, config.depth)
159159
.await;
@@ -185,10 +185,10 @@ pub async fn gate_run_cv_procedural<
185185
}
186186

187187
Side::Right => {
188-
if rightPole.len() > 0 {
188+
if right_pole.len() > 0 {
189189
false_count = 0;
190-
let mut correction;
191-
if rightPole_avg_x < 0.2 {
190+
let correction;
191+
if right_pole_avg_x < 0.2 {
192192
true_count += 1;
193193
if true_count >= config.true_count {
194194
#[cfg(feature = "logging")]
@@ -203,7 +203,7 @@ pub async fn gate_run_cv_procedural<
203203
logln!("true_count: {true_count}/4");
204204
}
205205
} else {
206-
correction = dbg!(config.correction_factor * rightPole_avg_x);
206+
correction = dbg!(config.correction_factor * right_pole_avg_x);
207207
let _ = cb
208208
.stability_1_speed_set(0.0, 0.0, correction, 0.0, 0.0, config.depth)
209209
.await;
@@ -322,10 +322,10 @@ pub async fn gate_run_procedural<
322322
vec![]
323323
});
324324

325-
let rightPole = detections
326-
.iter()
327-
.filter(|d| matches!(d.class().identifier, Target::RightPole))
328-
.collect_vec();
325+
// let right_pole = detections
326+
// .iter()
327+
// .filter(|d| matches!(d.class().identifier, Target::RightPole))
328+
// .collect_vec();
329329

330330
/* let middle = detections
331331
.iter()

src/missions/octagon.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub fn octagon<
4545
config: &Config,
4646
color_profile: &ColorProfile,
4747
) -> impl ActionExec<()> + 'static {
48+
let _ = config;
49+
let _ = color_profile;
4850
const FULL_SPEED_Y: f32 = 0.7;
4951
const FULL_SPEED_X: f32 = 0.0;
5052
const FULL_SPEED_PITCH: f32 = -45.0 / 4.0;

src/missions/slalom.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tokio_serial::SerialStream;
77
use super::action_context::{FrontCamIO, GetControlBoard, GetMainElectronicsBoard};
88
use crate::{
99
config::{slalom::Config, ColorProfile, Side::*},
10-
missions::{action::ActionExec, basic::DelayAction, vision::VisionNormAngle},
10+
missions::{action::ActionExec, vision::VisionNormAngle},
1111
};
1212

1313
// TODO: Consider filtering detections by angle (poles will always be upright)
@@ -90,10 +90,12 @@ pub async fn slalom<
9090
let x = *position.x() as f32;
9191
dbg!(&x);
9292
let mut correction = 0.0;
93+
let _ = correction;
9394
if x.abs() < 0.2 {
9495
true_count += 1;
9596
if true_count >= 4 {
9697
correction = 0.0;
98+
let _ = correction;
9799
#[cfg(feature = "logging")]
98100
logln!("ALIGNED");
99101
slalom_state = SlalomState::Approach;

src/missions/spin.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ pub async fn spin<
3737
let mut spin_count = 0;
3838
let mut in_spin = false;
3939

40-
cb.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, initial_yaw, config.depth)
40+
let _ = cb
41+
.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, initial_yaw, config.depth)
4142
.await;
4243
sleep(Duration::from_secs(1)).await;
43-
cb.global_speed_set(0.0, 0.0, 0.0, 0.0, config.spin_speed, 0.0)
44+
let _ = cb
45+
.global_speed_set(0.0, 0.0, 0.0, 0.0, config.spin_speed, 0.0)
4446
.await;
4547

4648
loop {
@@ -75,6 +77,7 @@ pub async fn spin<
7577
break;
7678
}
7779
}
78-
cb.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, initial_yaw, config.depth)
80+
let _ = cb
81+
.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, initial_yaw, config.depth)
7982
.await;
8083
}

src/vision/gate_poles.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use anyhow::Result;
22
use derive_getters::Getters;
33
use opencv::core::{multiply, BORDER_CONSTANT, CV_8U};
4-
use opencv::imgproc::morphology_default_border_value;
4+
use opencv::imgproc::{dilate, morphology_default_border_value};
55
use opencv::{
6-
core::imerge, split, Point, Scalar, Size, Vector},
7-
prelude::{Mat, MatTraitConst, MatTraitConstManual},
6+
core::{merge, split, Point, Size, Vector},
7+
prelude::{Mat, MatTraitConst},
88
};
99

1010
use crate::load_onnx;

src/vision/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,24 @@ impl Mul<&Mat> for PosVector {
478478
}
479479
}
480480
}
481+
482+
impl Draw for VisualDetection<bool, Offset2D<f64>> {
483+
fn draw(&self, canvas: &mut Mat) -> anyhow::Result<()> {
484+
let color = if self.class {
485+
Scalar::from((0.0, 255.0, 0.0))
486+
} else {
487+
Scalar::from((0.0, 0.0, 255.0))
488+
};
489+
490+
imgproc::circle(
491+
canvas,
492+
Point::new(*self.position.x() as i32, *self.position.y() as i32),
493+
10,
494+
color,
495+
2,
496+
LINE_8,
497+
0,
498+
)?;
499+
Ok(())
500+
}
501+
}

src/vision/slalom.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ impl VisualDetector<f64> for Slalom {
7373
input_image: &Mat,
7474
) -> anyhow::Result<Vec<VisualDetection<Self::ClassEnum, Self::Position>>> {
7575
let areas = self.area_bounds.clone();
76-
let MIN_AREA = areas.start();
77-
let MAX_AREA = areas.end();
76+
let min_area = areas.start();
77+
let max_area = areas.end();
7878

7979
self.image = resize(input_image, &self.size)?.into();
8080
let mut yuv_image = Mat::default();
@@ -114,7 +114,7 @@ impl VisualDetector<f64> for Slalom {
114114
#[cfg(feature = "logging")]
115115
logln!("AREA: {area}");
116116

117-
if area > *MIN_AREA && area < *MAX_AREA {
117+
if area > *min_area && area < *max_area {
118118
let rect = min_area_rect(&contour)?;
119119

120120
let mut box_rect = Mat::default();

0 commit comments

Comments
 (0)