3232#include " PokemonSV/Programs/Sandwiches/PokemonSV_IngredientSession.h"
3333#include " PokemonSV/Inference/Picnics/PokemonSV_SandwichPlateDetector.h"
3434
35+ // #include <iostream>
36+ // using std::cout;
37+ // using std::endl;
3538
3639namespace PokemonAutomation {
3740namespace NintendoSwitch {
@@ -1013,7 +1016,8 @@ void run_sandwich_maker(ProgramEnvironment& env, VideoStream& stream, ProControl
10131016 SandwichPlateDetector left_plate_detector (stream.logger (), COLOR_RED, language, SandwichPlateDetector::Side::LEFT);
10141017 SandwichPlateDetector middle_plate_detector (stream.logger (), COLOR_RED, language, SandwichPlateDetector::Side::MIDDLE);
10151018 SandwichPlateDetector right_plate_detector (stream.logger (), COLOR_RED, language, SandwichPlateDetector::Side::RIGHT);
1016-
1019+ bool left_plate_absent = false ;
1020+ bool right_plate_absent = false ;
10171021 {
10181022 VideoSnapshot screen = stream.video ().snapshot ();
10191023
@@ -1045,7 +1049,8 @@ void run_sandwich_maker(ProgramEnvironment& env, VideoStream& stream, ProControl
10451049
10461050 // Get left (2nd) ingredient
10471051 std::string left_filling = left_plate_detector.detect_filling_name (screen);
1048- if (left_filling.empty ()){
1052+ left_plate_absent = left_filling.empty ();
1053+ if (left_plate_absent){
10491054 stream.log (" No ingredient found on left label." );
10501055 stream.overlay ().add_log (" No left plate" );
10511056 }else {
@@ -1056,7 +1061,8 @@ void run_sandwich_maker(ProgramEnvironment& env, VideoStream& stream, ProControl
10561061
10571062 // Get right (3rd) ingredient
10581063 std::string right_filling = right_plate_detector.detect_filling_name (screen);
1059- if (right_filling.empty ()){
1064+ right_plate_absent = right_filling.empty ();
1065+ if (right_plate_absent){
10601066 stream.log (" No ingredient found on right label." );
10611067 stream.overlay ().add_log (" No right plate" );
10621068 }else {
@@ -1219,8 +1225,14 @@ void run_sandwich_maker(ProgramEnvironment& env, VideoStream& stream, ProControl
12191225 auto screen = stream.video ().snapshot ();
12201226
12211227 // The label check is needed for ingredients with multiple plates as we don't know which plate has what amount
1222- if (!left_plate_detector.is_label_yellow (screen) && !middle_plate_detector.is_label_yellow (screen)
1223- && !right_plate_detector.is_label_yellow (screen)){
1228+ // ensure the plates aren't absent to minimize false positives.
1229+ bool is_left_plate_yellow = !left_plate_absent && left_plate_detector.is_label_yellow (screen);
1230+ bool is_middle_plate_yellow = middle_plate_detector.is_label_yellow (screen);
1231+ bool is_right_plate_yellow = !right_plate_absent && right_plate_detector.is_label_yellow (screen);
1232+ // cout << "is_left_plate_yellow: " << is_left_plate_yellow << endl;
1233+ // cout << "is_middle_plate_yellow: " << is_middle_plate_yellow << endl;
1234+ // cout << "is_right_plate_yellow: " << is_right_plate_yellow << endl;
1235+ if (!is_left_plate_yellow && !is_middle_plate_yellow && !is_right_plate_yellow){
12241236 context.wait_for_all_requests ();
12251237 stream.log (" None of the labels are yellow, so we assume our current plate is empty and move on to the next plate." , COLOR_WHITE);
12261238 break ;
@@ -1238,8 +1250,12 @@ void run_sandwich_maker(ProgramEnvironment& env, VideoStream& stream, ProControl
12381250 }
12391251 }
12401252 }
1253+
1254+ context.wait_for_all_requests ();
1255+ context.wait_for (Milliseconds (1000 ));
1256+ stream.log (" All ingredients should now be empty. Wait for upper bread." , COLOR_YELLOW);
12411257 // Handle top slice by tossing it away
1242- SandwichHandWatcher grabbing_hand (SandwichHandType::FREE , { 0 , 0 , 1.0 , 1.0 });
1258+ SandwichHandWatcher grabbing_hand (SandwichHandType::GRABBING , { 0 , 0 , 1.0 , 1.0 });
12431259 int ret = wait_until (stream, context, std::chrono::seconds (30 ), { grabbing_hand });
12441260 if (ret < 0 ){
12451261 OperationFailedException::fire (
0 commit comments