Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PD-416] - [Feature] Pivot with Inverse A Move #18

Merged
merged 2 commits into from
Jun 5, 2024
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
1 change: 1 addition & 0 deletions include/suiryoku/locomotion/model/robot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Robot
double y_speed;
double a_speed;
bool aim_on;
bool inverse_a_move;
};

} // namespace suiryoku
Expand Down
3 changes: 3 additions & 0 deletions include/suiryoku/locomotion/process/locomotion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Locomotion

bool dribble(const keisan::Angle<double> & direction);
bool pivot(const keisan::Angle<double> & direction);
bool pivot_inverse_a_move(const keisan::Angle<double> & direction);

bool position_until(
const keisan::Angle<double> & target_pan,
Expand All @@ -85,6 +86,8 @@ class Locomotion

std::string config_name;

bool initial_pivot;

private:

double move_min_x;
Expand Down
1 change: 1 addition & 0 deletions src/suiryoku/locomotion/node/locomotion_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void LocomotionNode::publish_walking()
walking_msg.y_move = robot->y_speed;
walking_msg.a_move = robot->a_speed;
walking_msg.aim_on = robot->aim_on;
walking_msg.inverse_a_move = robot->inverse_a_move;

set_walking_publisher->publish(walking_msg);
}
Expand Down
56 changes: 56 additions & 0 deletions src/suiryoku/locomotion/process/locomotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,62 @@ bool Locomotion::pivot(const keisan::Angle<double> & direction)
return false;
}

bool Locomotion::pivot_inverse_a_move(const keisan::Angle<double> & direction)
{
if (initial_pivot) {
initial_pivot = false;
walk_in_position();
return false;
}

auto delta_direction = (direction - robot->orientation).normalize().degree();

if (std::abs(delta_direction) < pivot_max_delta_direction) {
walk_in_position();
robot->inverse_a_move = false;
return true;
}

double delta_tilt = (pivot_target_tilt - robot->tilt + robot->tilt_center).degree();

printf("pivot inverse a move\n");
printf("delta direction %f\n", delta_direction);
printf("delta tilt %f\n", delta_tilt);

// x_movement
double x_speed = delta_tilt > 0.0
? keisan::map(delta_tilt, 0.0, 20.0, 0.0, pivot_min_x)
: keisan::map(delta_tilt, -20.0, 0.0, pivot_max_x, 0.0);

// y movement
double y_speed = delta_direction < 0
? keisan::map(delta_direction, 180.0, 0.0, pivot_max_ry * 0.9, pivot_max_ry)
: keisan::map(delta_direction, -180.0, 0.0, pivot_max_ly * 0.9, pivot_max_ly);

// a movement
double a_speed = y_speed < 0.0
? keisan::map(delta_direction, -180.0, 0.0, -pivot_max_a * 0.9, -pivot_max_a)
: keisan::map(delta_direction, 180.0, 0.0, pivot_max_a, pivot_max_a * 0.9);

#if ITHAARO || UMARU || MIRU
double smooth_ratio = 1.0;
#else
double smooth_ratio = 0.8;
#endif

a_speed = keisan::smooth(robot->a_speed, a_speed, smooth_ratio);
x_speed = keisan::smooth(robot->x_speed, x_speed, smooth_ratio);
y_speed = keisan::smooth(robot->y_speed, y_speed, smooth_ratio);

robot->inverse_a_move = true;
robot->x_speed = x_speed;
robot->y_speed = y_speed;
robot->a_speed = a_speed;
start();

return false;
}

bool Locomotion::position_until(
const keisan::Angle<double> & target_pan,
const keisan::Angle<double> & target_tilt,
Expand Down
Loading