Skip to content

Commit 1aeb0c0

Browse files
committed
wip: fix slalom at night
1 parent 1e4d2d2 commit 1aeb0c0

4 files changed

Lines changed: 72 additions & 21 deletions

File tree

src/config/slalom.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::RangeInclusive;
2+
13
use super::Side;
24
use serde::{Deserialize, Serialize};
35

@@ -15,6 +17,8 @@ pub struct Config {
1517
pub traversal_duration: f32,
1618
pub yaw_adjustment: f32,
1719
pub yaw_speed: f32,
20+
pub area_bounds: RangeInclusive<f64>,
21+
pub correction_factor: f32,
1822
}
1923

2024
impl Default for Config {
@@ -32,6 +36,8 @@ impl Default for Config {
3236
traversal_duration: 6.0,
3337
yaw_adjustment: 15.0,
3438
yaw_speed: 0.2,
39+
area_bounds: 1000.0..=11000.0,
40+
correction_factor: 0.4,
3541
}
3642
}
3743
}

src/missions/slalom.rs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub async fn slalom<
4343

4444
let mut vision = VisionNormAngle::<Con, Slalom, f64>::new(
4545
context,
46-
Slalom::from_color_profile(color_profile),
46+
Slalom::from_color_profile(color_profile, config.area_bounds.clone()),
4747
);
4848

4949
let initial_yaw = loop {
@@ -55,6 +55,12 @@ pub async fn slalom<
5555
}
5656
};
5757

58+
let _ = cb
59+
.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, initial_yaw, config.depth)
60+
.await;
61+
62+
sleep(Duration::from_secs(3)).await;
63+
5864
let mut yaw_target = 0.0;
5965
let mut true_count = 0;
6066
let mut false_count = 0;
@@ -78,20 +84,6 @@ pub async fn slalom<
7884
logln!("Starting slalom detection");
7985

8086
// Default left, right if flipped
81-
let _ = cb
82-
.stability_1_speed_set(
83-
0.0,
84-
0.0,
85-
if flip {
86-
config.yaw_speed
87-
} else {
88-
-config.yaw_speed
89-
},
90-
0.0,
91-
0.0,
92-
config.depth,
93-
)
94-
.await;
9587
'detections: loop {
9688
#[allow(unused_variables)]
9789
let detections = vision.execute().await.unwrap_or_else(|e| {
@@ -132,12 +124,30 @@ pub async fn slalom<
132124
logln!("true_count: {true_count}/4");
133125
}
134126
} else {
135-
correction = dbg!(-0.2 * x);
127+
correction = dbg!(config.correction_factor * x);
136128
let _ = cb
137129
.stability_1_speed_set(0.0, 0.0, correction, 0.0, 0.0, config.depth)
138130
.await;
139131
}
140132
} else {
133+
#[cfg(feature = "logging")]
134+
logln!("SEARCHING");
135+
136+
let _ = cb
137+
.stability_1_speed_set(
138+
0.0,
139+
0.0,
140+
if flip {
141+
config.yaw_speed
142+
} else {
143+
-config.yaw_speed
144+
},
145+
0.0,
146+
0.0,
147+
config.depth,
148+
)
149+
.await;
150+
141151
false_count += 1;
142152
#[cfg(feature = "logging")]
143153
logln!("NO DETECTIONS");
@@ -153,12 +163,28 @@ pub async fn slalom<
153163
#[cfg(feature = "logging")]
154164
logln!("APPROACH");
155165

166+
let strafe_direction = if let Left = config.side { -1.0 } else { 1.0 };
167+
168+
let _ = cb
169+
.stability_2_speed_set(
170+
config.speed * strafe_direction,
171+
0.0,
172+
0.0,
173+
0.0,
174+
yaw_target,
175+
config.depth,
176+
)
177+
.await;
178+
179+
sleep(Duration::from_secs(config.strafe_duration as u64)).await;
180+
156181
yaw_target = (yaw_target
157182
+ (if let Left = config.side {
158183
config.yaw_adjustment
159184
} else {
160185
-config.yaw_adjustment
161186
}));
187+
162188
let _ = cb
163189
.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, yaw_target, config.depth)
164190
.await;
@@ -167,8 +193,13 @@ pub async fn slalom<
167193

168194
// init_timer.execute().await;
169195

196+
// let _ = cb
197+
// .stability_1_speed_set(0.0, config.speed, 0.0, 0.0, 0.0, config.depth)
198+
// .await;
199+
200+
//
170201
let _ = cb
171-
.stability_1_speed_set(0.0, config.speed, 0.0, 0.0, 0.0, config.depth)
202+
.stability_2_speed_set(0.0, config.speed, 0.0, 0.0, yaw_target, config.depth)
172203
.await;
173204

174205
// traversal_timer.execute().await;

src/video_source/appsink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn pipeline_head(device_name: &str, width: u32, height: u32, framerate: u32) ->
173173
return format!("mfvideosrc device-index={device_name} ! image/jpeg, width={width}, height={height}, framerate={framerate}/1");
174174

175175
#[cfg(not(target_os = "windows"))]
176-
return format!("v4l2src device={device_name} exposure=30 ! image/jpeg, width={width}, height={height}, framerate={framerate}/1");
176+
return format!("v4l2src device={device_name} ! image/jpeg, width={width}, height={height}, framerate={framerate}/1");
177177
}
178178

179179
fn h264_enc_pipeline(bitrate: u32) -> String {

src/vision/slalom.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,34 @@ use std::ops::RangeInclusive;
1414
#[derive(Debug)]
1515
pub struct Slalom {
1616
color_bounds: RangeInclusive<Yuv>,
17+
area_bounds: RangeInclusive<f64>,
1718
size: Size,
1819
image: MatWrapper,
1920
}
2021

2122
impl Slalom {
22-
pub fn new(color_bounds: RangeInclusive<Yuv>, size: Size) -> Self {
23+
pub fn new(
24+
color_bounds: RangeInclusive<Yuv>,
25+
area_bounds: RangeInclusive<f64>,
26+
size: Size,
27+
) -> Self {
2328
Self {
2429
color_bounds,
30+
area_bounds,
2531
size,
2632
image: Mat::default().into(),
2733
}
2834
}
2935

30-
pub fn from_color_profile(color_profile: &ColorProfile) -> Self {
31-
Self::new(color_profile.red.clone(), Size::from((400, 300)))
36+
pub fn from_color_profile(
37+
color_profile: &ColorProfile,
38+
area_bounds: RangeInclusive<f64>,
39+
) -> Self {
40+
Self::new(
41+
color_profile.red.clone(),
42+
area_bounds,
43+
Size::from((400, 300)),
44+
)
3245
}
3346
}
3447

@@ -45,6 +58,7 @@ impl Default for Slalom {
4558
u: 135,
4659
v: 255,
4760
}),
61+
1000.0..=11000.0,
4862
Size::from((400, 300)),
4963
)
5064
}

0 commit comments

Comments
 (0)