@@ -4,6 +4,7 @@ use tokio_serial::SerialStream;
44
55use crate :: {
66 act_nest,
7+ config:: coinflip:: Config ,
78 missions:: {
89 extra:: AlwaysTrue ,
910 meb:: WaitArm ,
@@ -33,6 +34,7 @@ pub async fn coinflip_procedural<
3334 Con : Send + Sync + GetControlBoard < WriteHalf < SerialStream > > + GetMainElectronicsBoard + FrontCamIO ,
3435> (
3536 context : & Con ,
37+ config : & Config ,
3638) {
3739 #[ cfg( feature = "logging" ) ]
3840 logln ! ( "Starting path align" ) ;
@@ -51,10 +53,17 @@ pub async fn coinflip_procedural<
5153 }
5254 } ;
5355
56+ let DEPTH = config. depth ;
57+
5458 let _ = cb
55- . stability_2_speed_set ( 0.0 , 0.0 , 0.0 , 0.0 , initial_yaw, 0.0 )
59+ . stability_2_speed_set ( 0.0 , 0.0 , 0.0 , 0.0 , initial_yaw, DEPTH )
5660 . await ;
5761
62+ let mut true_count = 0 ;
63+ let max_true_count = config. true_count ;
64+ let mut target_yaw = initial_yaw;
65+ let angle_correction = config. angle_correction ;
66+
5867 loop {
5968 #[ allow( unused_variables) ]
6069 let detections = vision. execute ( ) . await . unwrap_or_else ( |e| {
@@ -63,10 +72,33 @@ pub async fn coinflip_procedural<
6372 vec ! [ ]
6473 } ) ;
6574
66- let _gate = detections
75+ let gate = detections
6776 . iter ( )
6877 . filter ( |d| matches ! ( d. class( ) . identifier, Target :: Gate ) )
6978 . collect_vec ( ) ;
79+ let shark = detections
80+ . iter ( )
81+ . filter ( |d| matches ! ( d. class( ) . identifier, Target :: Shark ) )
82+ . collect_vec ( ) ;
83+ let sawfish = detections
84+ . iter ( )
85+ . filter ( |d| matches ! ( d. class( ) . identifier, Target :: Sawfish ) )
86+ . collect_vec ( ) ;
87+
88+ if ( gate. len ( ) > 0 || shark. len ( ) > 0 || sawfish. len ( ) > 0 ) {
89+ if true_count > max_true_count {
90+ let _ = cb
91+ . stability_2_speed_set ( 0.0 , 0.0 , 0.0 , 0.0 , initial_yaw, DEPTH )
92+ . await ;
93+ } else {
94+ true_count += 1 ;
95+ }
96+ } else {
97+ target_yaw += angle_correction;
98+ let _ = cb
99+ . stability_2_speed_set ( 0.0 , 0.0 , 0.0 , 0.0 , target_yaw, DEPTH )
100+ . await ;
101+ }
70102 }
71103}
72104
@@ -113,10 +145,11 @@ pub fn coinflip<
113145 DetectTarget :: <Target , YoloClass <Target >, Offset2D <f64 >>:: new( Target :: Gate ) ,
114146 DetectTarget :: <Target , YoloClass <Target >, Offset2D <f64 >>:: new( Target :: Middle ) ,
115147 DetectTarget :: <Target , YoloClass <Target >, Offset2D <f64 >>:: new( Target :: LeftPole ) ,
116- DetectTarget :: <Target , YoloClass <Target >, Offset2D <f64 >>:: new( Target :: RightPole ) ,
148+ DetectTarget :: <Target , YoloClass <Target >, Offset2D <f64 >>:: new(
149+ Target :: RightPole
150+ ) ,
117151 DetectTarget :: <Target , YoloClass <Target >, Offset2D <f64 >>:: new( Target :: Shark ) ,
118152 DetectTarget :: <Target , YoloClass <Target >, Offset2D <f64 >>:: new( Target :: Sawfish ) ,
119-
120153 ) ,
121154 CountTrue :: new( TRUE_COUNT ) ,
122155 ) ,
0 commit comments