Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ std::set<std::string> enter_region_and_read_MMO(
// on map. But when you land in a region, the initial location is a camp, the map cursor
// will show a text box "xxx Camp - Take a rest or do some crafting". This may occlude some
// MMO question marks. So we have to move the map cursor away after we land in the region.
uint8_t map_cursor_move_x = 0;
uint8_t map_cursor_move_y = 0;
double map_cursor_move_x = 0;
double map_cursor_move_y = 0;
const Milliseconds map_cursor_move_duration = 400ms;

for(size_t i = 0; i < 5; i++){
Expand All @@ -73,36 +73,36 @@ std::set<std::string> enter_region_and_read_MMO(
region = MapRegion::FIELDLANDS;
location = TravelLocations::instance().Fieldlands_Fieldlands;
camp = Camp::FIELDLANDS_FIELDLANDS;
map_cursor_move_x = 128;
map_cursor_move_y = 0;
map_cursor_move_x = 0;
map_cursor_move_y = +1;
break;
case 1:
region = MapRegion::MIRELANDS;
location = TravelLocations::instance().Mirelands_Mirelands;
camp = Camp::MIRELANDS_MIRELANDS;
map_cursor_move_x = 0;
map_cursor_move_y = 128;
map_cursor_move_x = -1;
map_cursor_move_y = 0;
break;
case 2:
region = MapRegion::COASTLANDS;
location = TravelLocations::instance().Coastlands_Beachside;
camp = Camp::COASTLANDS_BEACHSIDE;
map_cursor_move_x = 0;
map_cursor_move_y = 128;
map_cursor_move_x = -1;
map_cursor_move_y = 0;
break;
case 3:
region = MapRegion::HIGHLANDS;
location = TravelLocations::instance().Highlands_Highlands;
camp = Camp::HIGHLANDS_HIGHLANDS;
map_cursor_move_x = 128;
map_cursor_move_y = 255;
map_cursor_move_x = 0;
map_cursor_move_y = -1;
break;
case 4:
region = MapRegion::ICELANDS;
location = TravelLocations::instance().Icelands_Snowfields;
camp = Camp::ICELANDS_SNOWFIELDS;
map_cursor_move_x = 128;
map_cursor_move_y = 255;
map_cursor_move_x = 0;
map_cursor_move_y = -1;
break;
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ std::set<std::string> enter_region_and_read_MMO(
}

// Move cursor away so that it does not show a text box that occludes MMO sprites.
pbf_move_left_joystick_old(context, map_cursor_move_x, map_cursor_move_y, map_cursor_move_duration, 240ms);
pbf_move_left_joystick(context, {map_cursor_move_x, map_cursor_move_y}, map_cursor_move_duration, 240ms);
context.wait_for_all_requests();

// Fix Missions & Requests tab:
Expand Down Expand Up @@ -242,7 +242,7 @@ std::set<std::string> enter_region_and_read_MMO(
}

// Move cursor away so that it does not show a text box that occludes MMO sprites.
pbf_move_left_joystick_old(context, map_cursor_move_x, map_cursor_move_y, map_cursor_move_duration, 240ms);
pbf_move_left_joystick(context, {map_cursor_move_x, map_cursor_move_y}, map_cursor_move_duration, 240ms);
context.wait_for_all_requests();

std::set<std::string> found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ ImageFloatBox OliveDetector::align_to_olive(

uint16_t push_duration_ticks = std::max(uint16_t((std::abs(diff_from_center) + 0.02) * scale_factor / (olive_y)), uint16_t(15));
Milliseconds push_duration = push_duration_ticks * 8ms;
double push_magnitude = 128; // std::max(double(128 / (i + 1)), double(20)); // push less with each iteration/attempt
uint8_t push_x = uint8_t(std::max(std::min(int(128 + (push_direction * push_magnitude)), 255), 0));
double push_magnitude = 1; // std::max(double(128 / (i + 1)), double(20)); // push less with each iteration/attempt
double push_x = std::max(std::min(push_direction * push_magnitude, 1.0), -1.0);
stream.log("scale_factor: " + std::to_string(scale_factor));
stream.log("push x: " + std::to_string(push_x) + ", push duration: " + std::to_string(push_duration.count()) + "ms");
// pbf_wait(context, 800ms);
Expand All @@ -205,7 +205,7 @@ ImageFloatBox OliveDetector::align_to_olive(
wait_ticks = 100;
}
Milliseconds wait_duration = wait_ticks * 8ms;
pbf_move_left_joystick_old(context, push_x, 128, push_duration, wait_duration);
pbf_move_left_joystick(context, {push_x, 0}, push_duration, wait_duration);
prev_push_direction = push_direction;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1924,23 +1924,23 @@ bool move_player_to_realign_via_yolo(
// if (std::abs(diff) < 0.05){
// duration_scale_factor /= 2;
// }
double push_magnitude_scale_factor = 60 / std::sqrt(std::abs(diff));
double push_magnitude_scale_factor = 0.46875 / std::sqrt(std::abs(diff));

uint16_t push_duration_ticks = std::max(uint16_t(std::abs(diff * duration_scale_factor)), uint16_t(8));
Milliseconds push_duration = push_duration_ticks * 8ms;
int16_t push_direction = (diff > 0) ? -1 : 1;
double push_magnitude = std::max(double(std::abs(diff * push_magnitude_scale_factor)), double(15));
uint8_t x_push = uint8_t(std::max(std::min(int(128 + (push_direction * push_magnitude)), 255), 0));
double push_magnitude = std::max(double(std::abs(diff * push_magnitude_scale_factor)), 0.117);
double x_push = std::max(std::min(push_direction * push_magnitude, +1.0), -1.0);

// env.console.log("object_x: {" + std::to_string(target_box.x) + ", " + std::to_string(target_box.y) + ", " + std::to_string(target_box.width) + ", " + std::to_string(target_box.height) + "}");
// env.console.log("object_x_pos: " + std::to_string(object_x_pos));
env.console.log("x push: " + std::to_string(x_push) + ", push duration: " + std::to_string(push_duration.count()) + "ms");
if (i == 0){
pbf_move_left_joystick_old(context, x_push, 128, 80ms, 400ms);
pbf_move_left_joystick(context, {x_push, 0}, 80ms, 400ms);
pbf_press_button(context, BUTTON_R, 160ms, 840ms);
}

pbf_move_left_joystick_old(context, x_push, 128, push_duration, 0ms);
pbf_move_left_joystick(context, {x_push, 0}, push_duration, 0ms);

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ void WildItemFarmer::run_program(SingleSwitchProgramEnvironment& env, ProControl
assert_16_9_720p_min(env.logger(), env.console);
WildItemFarmer_Descriptor::Stats& stats = env.current_stats<WildItemFarmer_Descriptor::Stats>();

const std::vector<std::pair<int, int>> MANUVERS{
{128, 0},
{96, 0},
{160, 0},
const std::vector<std::pair<double, double>> MANUVERS{
{0, +1},
{-0.25, +1},
{+0.25, +1},
};

uint16_t items_cloned = 0;
Expand Down Expand Up @@ -325,8 +325,8 @@ void WildItemFarmer::run_program(SingleSwitchProgramEnvironment& env, ProControl

pbf_press_button(context, BUTTON_L, 160ms, 184ms);
if (ENABLE_FORWARD_RUN){
const std::pair<int, int>& direction = MANUVERS[consecutive_throw_attempts];
pbf_move_left_joystick_old(context, (uint8_t)direction.first, (uint8_t)direction.second, 400ms, 0ms);
const std::pair<double, double>& direction = MANUVERS[consecutive_throw_attempts];
pbf_move_left_joystick(context, {direction.first, direction.second}, 400ms, 0ms);
}
pbf_mash_button(context, BUTTON_ZR, 2000ms);
pbf_wait(context, 2800ms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ void move_cursor_to_position_offset_from_flypoint(const ProgramInfo& info, Video
const double dif_x = (closest_icon_x - expected_x) * 1920;
const double dif_y = (closest_icon_y - expected_y) * 1080;
const double magnitude = std::max(std::sqrt(closest_dist2), 1.0);
double push_x = dif_x * 64 / magnitude;
double push_y = dif_y * 64 / magnitude;
double push_x = dif_x * 0.5 / magnitude;
double push_y = dif_y * 0.5 / magnitude;

double scale = 0.29;
if (closest_dist2 < 1000){ // if we're already very close to the target, reduce push velocity and push duration
Expand All @@ -414,12 +414,12 @@ void move_cursor_to_position_offset_from_flypoint(const ProgramInfo& info, Video
break;
}

const uint8_t move_x = uint8_t(std::max(std::min(int(round(push_x + 128) + 0.5), 255), 0));
const uint8_t move_y = uint8_t(std::max(std::min(int(round(push_y + 128) + 0.5), 255), 0));
const double move_x = std::max(std::min(push_x, 1.0), -1.0);
const double move_y = -std::max(std::min(push_y, 1.0), -1.0);

const uint16_t push_time_ticks = std::max(uint16_t(magnitude * scale + 0.5), uint16_t(3));
Milliseconds push_time = push_time_ticks * 8ms;
pbf_move_left_joystick_old(context, move_x, move_y, push_time, 240ms);
pbf_move_left_joystick(context, {move_x, move_y}, push_time, 240ms);
context.wait_for_all_requests();
}

Expand Down Expand Up @@ -475,18 +475,18 @@ bool detect_closest_flypoint_and_move_map_cursor_there(
const double dif_x = (closest_icon_x - center_x) * 1920/ screen_width;
const double dif_y = (closest_icon_y - center_y) * 1080/ screen_height;
const double magnitude = std::max(std::sqrt(max_dist), 1.0);
const double push_x = dif_x * 64 / magnitude, push_y = dif_y * 64 / magnitude;
const double push_x = dif_x * 0.5 / magnitude, push_y = dif_y * 0.5 / magnitude;

// 0.5 is too large, 0.25 a little too small, 0.30 is a bit too much for a far-away pokecenter
const double scale = push_scale;

const uint8_t move_x = uint8_t(std::max(std::min(int(round(push_x + 128) + 0.5), 255), 0));
const uint8_t move_y = uint8_t(std::max(std::min(int(round(push_y + 128) + 0.5), 255), 0));
const double move_x = std::max(std::min(push_x, +1.0), -1.0);
const double move_y = -std::max(std::min(push_y, +1.0), -1.0);

stream.overlay().add_log("Move Cursor to PokeCenter", COLOR_WHITE);
const uint16_t push_time_ticks = std::max(uint16_t(magnitude * scale + 0.5), uint16_t(3));
Milliseconds push_time = push_time_ticks * 8ms;
pbf_move_left_joystick_old(context, move_x, move_y, push_time, 240ms);
pbf_move_left_joystick(context, {move_x, move_y}, push_time, 240ms);
context.wait_for_all_requests();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ HandMoveData move_sandwich_hand_and_check_if_plates_empty(
stream.log("Start moving sandwich hand: " + SANDWICH_HAND_TYPE_NAMES(hand_type)
+ " start box " + box_to_string(start_box) + " end box " + box_to_string(end_box));

uint8_t joystick_x = 128;
uint8_t joystick_y = 128;
double joystick_x = 0;
double joystick_y = 0;

SandwichHandWatcher hand_watcher(hand_type, start_box);

Expand Down Expand Up @@ -520,7 +520,7 @@ HandMoveData move_sandwich_hand_and_check_if_plates_empty(

// We assume for a screen distance of 4 (1/4 of the width), we can use max joystick push, 128.
// So for distance of value 1.0, we multiply by 32 to get joystick push
double target_joystick_push = std::min(distance * 32, 128.0);
double target_joystick_push = std::min(distance * 0.25, 1.0);

std::pair<double, double> push(real_dif.first * target_joystick_push / distance, real_dif.second * target_joystick_push / distance);
// console.log("push force " + std::to_string(push.first) + ", " + std::to_string(push.second));
Expand All @@ -541,8 +541,8 @@ HandMoveData move_sandwich_hand_and_check_if_plates_empty(
push.second += damped_push_offset.second;
}

joystick_x = (uint8_t) std::max(std::min(int(push.first + 0.5) + 128, 255), 0);
joystick_y = (uint8_t) std::max(std::min(int(push.second + 0.5) + 128, 255), 0);
joystick_x = std::max(std::min(push.first, +1.0), -1.0);
joystick_y = -std::max(std::min(push.second, +1.0), -1.0);
// console.log("joystick push " + std::to_string(joystick_x) + ", " + std::to_string(joystick_y));

// Dispatch a new series of commands that overwrites the last ones
Expand All @@ -552,7 +552,7 @@ HandMoveData move_sandwich_hand_and_check_if_plates_empty(
// pbf_controller_state(context, BUTTON_A, DPAD_NONE, joystick_x, joystick_y, 128, 128, 20);
ssf_press_button(context, BUTTON_A, 0ms, 8000ms, 0ms);
}
pbf_move_left_joystick_old(context, joystick_x, joystick_y, 160ms, 0ms);
pbf_move_left_joystick(context, {joystick_x, joystick_y}, 160ms, 0ms);
});

stream.log("Moved joystick");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>
#include <cmath>
#include "Controllers/JoystickTools.h"
#include "Common/Cpp/PrettyPrint.h"
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
Expand Down Expand Up @@ -317,25 +318,25 @@ void area_zero_platform_run_path0(
find_and_center_on_sky(env, stream, context);
pbf_move_right_joystick(context, {0, -1}, 560ms, 0ms);

uint8_t x = 128;
double x = 0;
switch (iteration_count % 4){
case 0:
x = 96;
x = -0.25;
duration = 2000ms;
break;
case 1:
x = 112;
x = -0.125;
break;
case 2:
x = 128;
x = 0;
break;
case 3:
x = 112;
x = -0.125;
break;
}

ssf_press_button(context, BUTTON_L, 0ms, 160ms);
pbf_move_left_joystick_old(context, x, 0, duration, 0ms);
pbf_move_left_joystick(context, {x, +1}, duration, 0ms);
});
use_lets_go_to_clear_in_front(stream, context, tracker, true, [&](ProControllerContext& context){
pbf_move_left_joystick(context, {0, -1}, duration, 4000ms);
Expand Down Expand Up @@ -381,24 +382,24 @@ void area_zero_platform_run_path1(

// Move forward.

uint8_t x = 128;
double x = 0;
switch (iteration_count % 4){
case 0:
x = 96;
x = -0.25;
duration = 2000ms;
break;
case 1:
x = 112;
x = -0.125;
break;
case 2:
x = 128;
x = 0;
break;
case 3:
x = 112;
x = -0.125;
break;
}

pbf_move_left_joystick_old(context, x, 0, duration, 0ms);
pbf_move_left_joystick(context, {x, +1}, duration, 0ms);
});

stream.log("Run backwards and wait...");
Expand Down Expand Up @@ -450,7 +451,7 @@ void choose_path(
void turn_angle(ProControllerContext& context, double angle_radians){
uint8_t turn_x, turn_y;
direction_to_stick(turn_x, turn_y, -std::sin(angle_radians), std::cos(angle_radians));
pbf_move_left_joystick_old(context, turn_x, turn_y, 320ms, 160ms);
pbf_move_left_joystick(context, {JoystickTools::linear_u8_to_float(turn_x), -JoystickTools::linear_u8_to_float(turn_y)}, 320ms, 160ms);
pbf_mash_button(context, BUTTON_L, 480ms);
}

Expand Down Expand Up @@ -487,7 +488,7 @@ void area_zero_platform_run_path2(

choose_path(stream.logger(), move_x, move_y, duration, platform_x, platform_y);

pbf_move_left_joystick_old(context, move_x, move_y, 320ms, 160ms);
pbf_move_left_joystick(context, {JoystickTools::linear_u8_to_float(move_x), JoystickTools::linear_u8_to_float(move_y)}, 320ms, 160ms);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm testing platform bot right now and something isn't quite right. I think the Y-axis here needs to be negated. Testing that now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. My bad. I negated the first one in that same file, but didn't do the second one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that was it. I'll merge this, then immediately merge a (bigger) fix for this file.

pbf_mash_button(context, BUTTON_L, 480ms);
// pbf_wait(context, 1250);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void EggHatcher::program(SingleSwitchProgramEnvironment& env, ProControllerConte
fly_home(context, false);

// Travel to spin location.
pbf_move_left_joystick_old(context, STICK_MAX, STICK_CENTER, TRAVEL_RIGHT_DURATION, 0ms);
pbf_move_left_joystick(context, {+1, 0}, TRAVEL_RIGHT_DURATION, 0ms);

// Spin
#if 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <cmath>
#include "Controllers/JoystickTools.h"
#include "Common/Cpp/PrettyPrint.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonTools/Async/InferenceRoutines.h"
Expand Down Expand Up @@ -298,6 +299,8 @@ bool ShinyHuntAutonomousOverworld::charge_at_target(
);

const Trajectory& trajectory = target.second.trajectory;
double stick_x = JoystickTools::linear_u8_to_float(trajectory.joystick_x);
double stick_y = -JoystickTools::linear_u8_to_float(trajectory.joystick_y);
double angle = std::atan2(
(double)trajectory.joystick_y - 128,
(double)trajectory.joystick_x - 128
Expand Down Expand Up @@ -325,10 +328,9 @@ bool ShinyHuntAutonomousOverworld::charge_at_target(
stream, context,
[&](ProControllerContext& context){
// Move to target.
pbf_move_left_joystick_old(
pbf_move_left_joystick(
context,
trajectory.joystick_x,
trajectory.joystick_y,
{stick_x, stick_y},
duration, 0ms
);

Expand Down