Skip to content

Commit 96a47ed

Browse files
authored
Autostory: Player/Camera movement based on YOLO. Arrive at Area Zero Station 1. (#816)
* add extra segments/checkpoints * checkpoint 93: Entered Area Zero Gate. Flew down to Area Zero from the platform. * minor update to checkpoint 93 * add functions that move player forward and move the camera, based on yolo object detection * for routines that move the player/camera based on yolo, throw exception if caught in battle. adjust scale factors for move_camera_yolo * add TEST_YOLO_BOX * add bag detection for run_battle_press_A() * clear YOLO overlays when caught in battle * add move_forward_until_yolo_object_not_detected(). change color of overlays if it's the target object. * add do_action_and_monitor_for_battles_early(), which uses NoMinimapWatcher * add times_not_seen_threshold to move_forward_until_yolo_object_not_detected() * partial checkpoint_94: arrive at rock-3 * add move_player_to_realign_via_yolo() * adjust recovery routine after battle to use move_player_to_realign_via_yolo() * add move_camera_until_yolo_object_detected() * add do_action_until_dialog(). adjust move_player_forward() to include a recovery_action * partial checkpoint_94: arrive at station-1 dialog * add recovery action to move_camera_yolo() * minor tweaks to station 1 navigation routine. * adjust close_game_from_home() * more changes to station 1 nav routine * adjust target x values when recovering from battles within move_camera_yolo: X. * when moving forward, don't pause to use Let's Go. * more changes to station 1 nav routine * complete checkpoint_94 * adjust recovery_action for move_camera_yolo: X. Don't move the player after a battle. just adjust the camera. * more adjustments to checkpoint_94 * yolo-based camera/player movement routines: rename variables. throw exception if never detected yolo object. throw exception if exceed max rounds. reduce delays after joystick movement. * more checkpoint_94 adjustments * minor changes to close_game_from_home * move_camera_yolo: increase max_attempts * updated move_player_forward() and walk_forward_until_dialog() * preliminary checkpoint 95: entering station 1 * more tidy up
1 parent b542de9 commit 96a47ed

22 files changed

+2068
-31
lines changed

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void ensure_at_home(ConsoleHandle& console, ControllerContext& context){
7070
{home_menu}
7171
);
7272
if (ret == 0){
73+
console.log("Home detected.");
7374
// While we're on the Home screen, we might as well read the
7475
// console type as well.
7576
if (console.state().console_type_confirmed()){
@@ -104,6 +105,7 @@ void ensure_at_home(ConsoleHandle& console, JoyconContext& context){
104105
//
105106

106107
void close_game_from_home(ConsoleHandle& console, ProControllerContext& context){
108+
console.log("close_game_from_home");
107109
ensure_at_home(console, context);
108110

109111
// Use mashing to ensure that the X press succeeds. If it fails, the SR
@@ -124,6 +126,7 @@ void close_game_from_home(ConsoleHandle& console, ProControllerContext& context)
124126
pbf_mash_button(context, BUTTON_B, 350);
125127
}
126128
void close_game_from_home(ConsoleHandle& console, JoyconContext& context){
129+
console.log("close_game_from_home");
127130
ensure_at_home(console, context);
128131
// Use mashing to ensure that the X press succeeds. If it fails, the SR
129132
// will fail and can kill a den for the autohosts.

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
6+
7+
8+
#include "ML/Inference/ML_YOLOv5Detector.h"
9+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
10+
#include "CommonFramework/Exceptions/UnexpectedBattleException.h"
11+
12+
613
#include "CommonFramework/Exceptions/OperationFailedException.h"
714
#include "CommonTools/Async/InferenceRoutines.h"
815

@@ -57,6 +64,11 @@
5764
#include "PokemonSV_AutoStory_Segment_33.h"
5865
#include "PokemonSV_AutoStory_Segment_34.h"
5966
#include "PokemonSV_AutoStory_Segment_35.h"
67+
#include "PokemonSV_AutoStory_Segment_36.h"
68+
#include "PokemonSV_AutoStory_Segment_37.h"
69+
#include "PokemonSV_AutoStory_Segment_38.h"
70+
#include "PokemonSV_AutoStory_Segment_39.h"
71+
#include "PokemonSV_AutoStory_Segment_40.h"
6072
#include "PokemonSV_AutoStory.h"
6173

6274
#include <iostream>
@@ -70,6 +82,7 @@ namespace NintendoSwitch{
7082
namespace PokemonSV{
7183

7284
using namespace Pokemon;
85+
using namespace ML;
7386

7487
static constexpr size_t INDEX_OF_LAST_TUTORIAL_SEGMENT = 9;
7588
static constexpr size_t INDEX_OF_LAST_TUTORIAL_CHECKPOINT = 20;
@@ -112,8 +125,15 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
112125
segment_list.emplace_back(std::make_unique<AutoStory_Segment_32>());
113126
segment_list.emplace_back(std::make_unique<AutoStory_Segment_33>());
114127
segment_list.emplace_back(std::make_unique<AutoStory_Segment_34>());
115-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_35>());
116128

129+
if (PreloadSettings::instance().DEVELOPER_MODE){
130+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_35>());
131+
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_36>());
132+
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_37>());
133+
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_38>());
134+
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_39>());
135+
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_40>());
136+
}
117137
return segment_list;
118138
};
119139

@@ -276,6 +296,15 @@ std::vector<std::unique_ptr<AutoStory_Checkpoint>> make_autoStory_checkpoint_lis
276296
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_91>());
277297
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_92>());
278298

299+
if (PreloadSettings::instance().DEVELOPER_MODE){
300+
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_93>());
301+
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_94>());
302+
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_95>());
303+
// checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_96>());
304+
// checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_97>());
305+
// checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_98>());
306+
// checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_99>());
307+
}
279308

280309
return checkpoint_list;
281310
};
@@ -658,11 +687,34 @@ AutoStory::AutoStory()
658687
LockMode::UNLOCK_WHILE_RUNNING,
659688
0
660689
)
690+
, TEST_YOLO_BOX(
691+
"<b>TEST: get_yolo_box():</b>",
692+
LockMode::UNLOCK_WHILE_RUNNING,
693+
false
694+
)
695+
, YOLO_PATH(
696+
false,
697+
"<b>YOLO Path:</b>",
698+
LockMode::LOCK_WHILE_RUNNING,
699+
"PokemonSV/YOLO/yolo_area0_station1.onnx",
700+
"<.onnx file>"
701+
)
702+
, TARGET_LABEL(
703+
false,
704+
"<b>YOLO Object Label:</b>",
705+
LockMode::LOCK_WHILE_RUNNING,
706+
"rock-1",
707+
"<target label>"
708+
)
661709
{
662710

663711
if (PreloadSettings::instance().DEVELOPER_MODE){
664712
PA_ADD_OPTION(m_advanced_options);
665713

714+
PA_ADD_OPTION(TEST_YOLO_BOX);
715+
PA_ADD_OPTION(YOLO_PATH);
716+
PA_ADD_OPTION(TARGET_LABEL);
717+
666718
PA_ADD_OPTION(FLYPOINT_TYPE);
667719
PA_ADD_OPTION(TEST_FLYPOINT_LOCATIONS);
668720
PA_ADD_OPTION(TEST_MOVE_CURSOR_OFFSET_FROM_FLYPOINT);
@@ -1137,6 +1189,18 @@ void AutoStory::run_autostory(SingleSwitchProgramEnvironment& env, ProController
11371189

11381190
void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
11391191

1192+
1193+
if (TEST_YOLO_BOX){
1194+
VideoOverlaySet overlays(env.console.overlay());
1195+
YOLOv5Detector yolo_detector(RESOURCE_PATH() + std::string(YOLO_PATH));
1196+
1197+
ImageFloatBox target_box = get_yolo_box(env, context, overlays, yolo_detector, TARGET_LABEL);
1198+
1199+
context.wait_for(Milliseconds(1000));
1200+
return;
1201+
}
1202+
1203+
11401204
if (TEST_FLYPOINT_LOCATIONS){
11411205
print_flypoint_location(env.program_info(), env.console, context, FLYPOINT_TYPE);
11421206
// print_flypoint_location(env.program_info(), env.console, context, FlyPoint::FAST_TRAVEL);
@@ -1200,6 +1264,11 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerCont
12001264
DirectionDetector direction;
12011265

12021266

1267+
YOLOv5Detector yolo_detector(RESOURCE_PATH() + "PokemonSV/YOLO/yolo_area0_station1.onnx");
1268+
// move_camera_yolo(env, context, CameraAxis::Y, yolo_detector, "tree-tera", 0.294444);
1269+
// move_camera_yolo(env, context, CameraAxis::X, yolo_detector, "tree-tera", 0.604688);
1270+
1271+
12031272

12041273
return;
12051274
}

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1212
#include "Common/Cpp/Options/FloatingPointOption.h"
1313
#include "Common/Cpp/Options/EnumDropdownOption.h"
14+
#include "Common/Cpp/Options/StringOption.h"
1415
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1516
#include "CommonTools/Options/StringSelectOption.h"
1617
#include "CommonTools/Options/LanguageOCROption.h"
@@ -147,6 +148,12 @@ class AutoStory : public SingleSwitchProgramInstance, public ConfigOption::Liste
147148
BooleanCheckBoxOption TEST_MOVE_CURSOR_OFFSET_FROM_FLYPOINT;
148149
FloatingPointOption X_OFFSET;
149150
FloatingPointOption Y_OFFSET;
151+
152+
BooleanCheckBoxOption TEST_YOLO_BOX;
153+
StringOption YOLO_PATH;
154+
StringOption TARGET_LABEL;
155+
156+
150157
};
151158

152159
const std::vector<std::unique_ptr<AutoStory_Segment>>& ALL_AUTO_STORY_SEGMENT_LIST();

0 commit comments

Comments
 (0)