Skip to content

Commit 1e4d2d2

Browse files
wip: working slalom align
1 parent 8ad0cc5 commit 1e4d2d2

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/missions/slalom.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ pub async fn slalom<
112112
logln!("ALIGN");
113113

114114
if let Some(position) = positions.next() {
115+
false_count = 0;
115116
let x = *position.x() as f32;
117+
dbg!(&x);
116118
let mut correction = 0.0;
117119
if x.abs() < 0.2 {
118120
true_count += 1;
119121
if true_count >= 4 {
120122
correction = 0.0;
123+
#[cfg(feature = "logging")]
124+
logln!("ALIGNED");
121125
slalom_state = SlalomState::Approach;
122126
if let Some(current_angle) = cb.responses().get_angles().await {
123127
let current_yaw = *current_angle.yaw();
@@ -128,14 +132,18 @@ pub async fn slalom<
128132
logln!("true_count: {true_count}/4");
129133
}
130134
} else {
131-
correction = 0.5 * x;
135+
correction = dbg!(-0.2 * x);
132136
let _ = cb
133137
.stability_1_speed_set(0.0, 0.0, correction, 0.0, 0.0, config.depth)
134138
.await;
135139
}
136140
} else {
137141
false_count += 1;
142+
#[cfg(feature = "logging")]
143+
logln!("NO DETECTIONS");
138144
if false_count >= 100 {
145+
#[cfg(feature = "logging")]
146+
logln!("KILLED NO DET");
139147
break 'detections;
140148
}
141149
}
@@ -145,29 +153,27 @@ pub async fn slalom<
145153
#[cfg(feature = "logging")]
146154
logln!("APPROACH");
147155

156+
yaw_target = (yaw_target
157+
+ (if let Left = config.side {
158+
config.yaw_adjustment
159+
} else {
160+
-config.yaw_adjustment
161+
}));
148162
let _ = cb
149-
.stability_2_speed_set(
150-
0.0,
151-
0.0,
152-
0.0,
153-
0.0,
154-
(yaw_target
155-
+ (if let Left = config.side {
156-
-config.yaw_adjustment
157-
} else {
158-
config.yaw_adjustment
159-
})) as f32,
160-
config.depth,
161-
)
163+
.stability_2_speed_set(0.0, 0.0, 0.0, 0.0, yaw_target, config.depth)
162164
.await;
163165

164-
init_timer.execute().await;
166+
sleep(Duration::from_secs(config.init_duration as u64)).await;
167+
168+
// init_timer.execute().await;
165169

166170
let _ = cb
167-
.stability_2_speed_set(0.0, config.speed, 0.0, 0.0, 0.0, config.depth)
171+
.stability_1_speed_set(0.0, config.speed, 0.0, 0.0, 0.0, config.depth)
168172
.await;
169173

170-
traversal_timer.execute().await;
174+
// traversal_timer.execute().await;
175+
sleep(Duration::from_secs(config.traversal_duration as u64)).await;
176+
171177
break 'detections;
172178
}
173179
}

src/vision/slalom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use opencv::{
55
core::{in_range, Point, Scalar, Size, Vector},
66
imgproc::{
77
box_points, contour_area_def, cvt_color_def, find_contours_def, min_area_rect,
8-
CHAIN_APPROX_SIMPLE, COLOR_BGR2HSV, RETR_EXTERNAL,
8+
CHAIN_APPROX_SIMPLE, COLOR_BGR2YUV, RETR_EXTERNAL,
99
},
1010
prelude::{Mat, MatTraitConst, MatTraitConstManual},
1111
};
@@ -64,7 +64,7 @@ impl VisualDetector<f64> for Slalom {
6464
self.image = resize(input_image, &self.size)?.into();
6565
let mut yuv_image = Mat::default();
6666

67-
cvt_color_def(&self.image.0, &mut yuv_image, COLOR_BGR2HSV)?;
67+
cvt_color_def(&self.image.0, &mut yuv_image, COLOR_BGR2YUV)?;
6868

6969
let color_start = self.color_bounds.start();
7070
let color_end = self.color_bounds.end();

0 commit comments

Comments
 (0)