Skip to content

Commit de7c8ab

Browse files
authored
Sandwich maker: if the expected filling doesn't match the ingredient read on the plate, continue as normal if there's only 1 plate. else throw error (#663)
* Sandwich maker: if the expected filling doesn't match the ingredient read on the plate, continue as normal if there's only 1 plate. else throw error * testing sandwich plate reader
1 parent a125a84 commit de7c8ab

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.h"
119119
#include "PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMenuDetector.h"
120120
#include "PokemonSV/Inference/Picnics/PokemonSV_SandwichHandDetector.h"
121+
#include "PokemonSV/Inference/Picnics/PokemonSV_SandwichPlateDetector.h"
121122
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonSwapMenu.h"
122123
#include "CommonTools/Images/ImageFilter.h"
123124
#include "NintendoSwitch/Options/NintendoSwitch_ModelType.h"
@@ -254,7 +255,14 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
254255
ProControllerContext context(scope, console.pro_controller());
255256
VideoOverlaySet overlays(overlay);
256257

258+
257259
#if 1
260+
ImageRGB32 image(IMAGE_PATH);
261+
SandwichPlateDetector middle_plate_detector(logger, COLOR_RED, LANGUAGE, SandwichPlateDetector::Side::MIDDLE);
262+
cout << middle_plate_detector.detect_filling_name(image) << endl;
263+
#endif
264+
265+
#if 0
258266
ItemPrinterMaterialDetector detector(COLOR_RED, LANGUAGE);
259267
// detector.make_overlays(overlays);
260268
// cout << (int)detector.find_happiny_dust_row_index(console, context) << endl;

SerialPrograms/Source/PokemonSV/Inference/Picnics/PokemonSV_SandwichPlateDetector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "CommonTools/Images/ImageFilter.h"
1212
#include "PokemonSV_SandwichPlateDetector.h"
1313
#include "PokemonSV/Inference/Picnics/PokemonSV_SandwichIngredientDetector.h"
14+
// #include "CommonFramework/Tools/DebugDumper.h"
1415

1516
//#include <iostream>
1617
//using std::cout;

SerialPrograms/Source/PokemonSV/Programs/Sandwiches/PokemonSV_SandwichRoutines.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,12 +1213,12 @@ void run_sandwich_maker(
12131213
context.wait_for_all_requests();
12141214

12151215
//Find fillings and add them in order
1216-
for (const std::string& i : fillings_sorted){
1217-
//cout << "Placing " << i << endl;
1218-
stream.log("Placing " + i, COLOR_WHITE);
1219-
stream.overlay().add_log("Placing " + i, COLOR_WHITE);
1216+
for (const std::string& expected_filling : fillings_sorted){
1217+
//cout << "Placing " << expected_filling << endl;
1218+
stream.log("Placing " + expected_filling, COLOR_WHITE);
1219+
stream.overlay().add_log("Placing " + expected_filling, COLOR_WHITE);
12201220

1221-
int times_to_place = (int)(FillingsCoordinates::instance().get_filling_information(i).piecesPerServing) * (fillings.find(i)->second);
1221+
int times_to_place = (int)(FillingsCoordinates::instance().get_filling_information(expected_filling).piecesPerServing) * (fillings.find(expected_filling)->second);
12221222
int placement_number = 0;
12231223

12241224
//cout << "Times to place: " << times_to_place << endl;
@@ -1227,12 +1227,30 @@ void run_sandwich_maker(
12271227

12281228
std::vector<int> plate_index;
12291229
//Get the plates we want to go to
1230+
bool found_plate_index = false;
12301231
for (int j = 0; j < (int)plate_order.size(); j++){
1231-
if (i == plate_order.at(j)){
1232+
if (expected_filling == plate_order.at(j)){
12321233
plate_index.push_back(j);
1234+
found_plate_index = true;
1235+
}
1236+
}
1237+
if (!found_plate_index){
1238+
// expected_filling not found within plate_order
1239+
stream.log("The expected filling not found within the plates.", COLOR_ORANGE);
1240+
if (plate_order.size() == 1){ // if there's only one plate, we assume it's the expected filling
1241+
stream.log("There's only one plate, so we assume it's the expected filling.");
1242+
plate_index.push_back(0);
1243+
}else{
1244+
OperationFailedException::fire(
1245+
ErrorReport::SEND_ERROR_REPORT,
1246+
"run_sandwich_maker(): Did not detect the expected ingredients on the plate(s).",
1247+
stream
1248+
);
12331249
}
1250+
12341251
}
12351252

1253+
12361254
//Target the correct filling plate and place until it is empty
12371255
for (int j = 0; j < (int)plate_index.size(); j++){
12381256
//Navigate to plate and set target plate
@@ -1284,8 +1302,8 @@ void run_sandwich_maker(
12841302
context.wait_for_all_requests();
12851303

12861304
//Get placement location
1287-
ImageFloatBox placement_target = FillingsCoordinates::instance().get_filling_information(i).placementCoordinates.at(
1288-
(int)fillings.find(i)->second).at(placement_number);
1305+
ImageFloatBox placement_target = FillingsCoordinates::instance().get_filling_information(expected_filling).placementCoordinates.at(
1306+
(int)fillings.find(expected_filling)->second).at(placement_number);
12891307

12901308
HandMoveData hand_move_data = move_sandwich_hand_and_check_if_plates_empty(
12911309
env,

0 commit comments

Comments
 (0)