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

Zoner defense 2 #2256

Merged
merged 57 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7d14611
modified code in robot_factory_position and a few other classes to us…
Mar 6, 2024
32e194c
modified code in update_alive_robots in position to use the data from…
Mar 6, 2024
748aa37
Apply suggestions from code review
sid-parikh Mar 6, 2024
ef2d465
typo & pretty-lines
sid-parikh Mar 6, 2024
b1d2718
Add topic name constant for strategy/alive_robots
oddlyspookycherry Mar 6, 2024
8a8a554
Publish robots 0-6 as alive in sim_radio
oddlyspookycherry Mar 6, 2024
d162471
Use global topic name declaration in agent_action_client
oddlyspookycherry Mar 6, 2024
de004c7
Change topic name in radio to use the global costant declaration (str…
oddlyspookycherry Mar 6, 2024
8178d7b
Fix style formatting
oddlyspookycherry Mar 6, 2024
3f0c927
combine both branches; why four offense??
sid-parikh Mar 6, 2024
1f8382f
fix alive_robots and goalie_id propagation
sid-parikh Mar 6, 2024
ee8eb82
Made the requests a queue and added code to determine kicker
sanatd33 Feb 14, 2024
d234e31
Working on implemetning free kick
sanatd33 Feb 21, 2024
e23cff3
reformat
sid-parikh Feb 25, 2024
47bb66f
clang-tidy
sid-parikh Feb 25, 2024
53ac7b3
change name; cleanup; use deque (queue not iterable)
sid-parikh Feb 25, 2024
4714167
use max
sid-parikh Feb 25, 2024
a94f28f
free kick works basic. need state machine
sid-parikh Feb 26, 2024
3385d90
Added State machine and implemented free kick/kickoff
sanatd33 Feb 28, 2024
492a0ee
Fix Code Style On kicker-picker (#2201)
github-actions[bot] Feb 28, 2024
4ffa80e
Fixed compile error in theory
sanatd33 Mar 6, 2024
f56abf3
Fix Code Style On kicker-picker (#2211)
github-actions[bot] Mar 6, 2024
5c1d205
ok compile errors gone now
sanatd33 Mar 6, 2024
d944e4f
rebase with position-assignment
sid-parikh Mar 6, 2024
873803d
expect referee to be physically on localhost
sid-parikh Mar 6, 2024
aa5a0cf
use RTTI to switch classes
sid-parikh Mar 6, 2024
4afc316
more RTTI
sid-parikh Mar 6, 2024
d639e3a
reformat
sid-parikh Mar 6, 2024
dd09832
WIP VERY WIP
sid-parikh Mar 6, 2024
4faf8ab
WIP
sid-parikh Mar 10, 2024
c3de1fa
goalie pk skeleton
petergarud Mar 11, 2024
c38789e
added penalty_player stuff
petergarud Mar 11, 2024
c73fc84
Cleaned up code so it compiles, added a smart idlewith a path planner…
Mar 11, 2024
3d840f1
Made a slight modification to smart idle
Mar 11, 2024
0794d89
made SmartIdle get away from the ball in penalty position so that it …
Mar 13, 2024
4b8fe1d
finished basic functionality for penalty player
Mar 13, 2024
7787dd0
fixed a bug with position reassignment in robot_factory_position
Mar 13, 2024
57ecbb5
update state machine
jacksherling Mar 13, 2024
51636b7
Merge remote-tracking branch 'origin/pk' into kicker-picker
jacksherling Mar 13, 2024
6b08314
fix a few bugs; getting there
jacksherling Mar 13, 2024
8f30b03
wip
jacksherling Mar 27, 2024
b4f9d70
positions and factory
jacksherling Apr 3, 2024
ede21e7
very little useful code
jacksherling Apr 8, 2024
79b5dd2
fix kicker picker communication
jacksherling Apr 10, 2024
12b6f8b
bug fixes
jacksherling Apr 17, 2024
215bdf0
Merge branch 'kicker-picker' into ros2
jacksherling Apr 17, 2024
abbcf97
Fix Code Style On kicker-picker (#2251)
github-actions[bot] Apr 22, 2024
e6bbaaf
Fixing PR review changes
jacksherling Apr 22, 2024
60b5857
asdf
Apr 23, 2024
cb1e3a8
new defense with zoner
petergarud Apr 24, 2024
dfdb70d
Cleaned up
jacksherling Apr 24, 2024
5c0903c
Merge remote-tracking branch 'origin/zoner-defense' into ros2
jacksherling Apr 24, 2024
e86d4c9
uhm
jacksherling Apr 24, 2024
7f92639
resolved comments on PR
rishiso Apr 29, 2024
473e5e9
Committing before resolving conflicts
rishiso Apr 29, 2024
5987844
Resolving merge conflicts
rishiso Apr 29, 2024
4ad1dd5
Adding constructor overloads
rishiso Apr 29, 2024
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 soccer/src/soccer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ set(ROBOCUP_LIB_SRC
strategy/agent/position/penalty_player.cpp
strategy/agent/position/penalty_non_kicker.cpp
strategy/agent/position/smartidling.cpp
strategy/agent/position/zoner.cpp
strategy/agent/position/pivot_test.cpp

)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ bool RobotFactoryPosition::am_closest_kicker() {
}

void RobotFactoryPosition::set_default_position() {
// zoner defense testing
// if (robot_id_ == goalie_id_) {
// return;
// }
// if (robot_id_ == 1) {
// set_current_position<Zoner>();
// } else {
// set_current_position<Defense>();
// }
// return;
// end zoner defense testing

// TODO (Rishi and Jack): Make this synchronized across all robots to avoid race conditions
// Get sorted positions of all friendly robots
using RobotPos = std::pair<int, double>; // (robotId, yPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "strategy/agent/position/pivot_test.hpp"
#include "strategy/agent/position/position.hpp"
#include "strategy/agent/position/smartidling.hpp"
#include "strategy/agent/position/zoner.hpp"

namespace strategy {

Expand Down
133 changes: 133 additions & 0 deletions soccer/src/soccer/strategy/agent/position/zoner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include "zoner.hpp"

namespace strategy {

Zoner::Zoner(int r_id) : Position(r_id, "Zoner") {}

Zoner::Zoner(const Position& other) : Position{other} { position_name_ = "Zoner"; }

std::optional<RobotIntent> Zoner::derived_get_task(RobotIntent intent) {
current_state_ = next_state();
// waller_id_ = get_waller_id();
return state_to_task(intent);
}

Zoner::State Zoner::next_state() {
rj_geometry::Point ball_pos = last_world_state_->ball.position;
rj_geometry::Segment block_path{ball_pos, field_dimensions_.our_goal_loc()};

double min_dist = std::numeric_limits<double>::infinity();
for (int i = 0; i < static_cast<int>(kNumShells); i++) {
// TODO: Add solo offense here as well

Check warning on line 21 in soccer/src/soccer/strategy/agent/position/zoner.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

missing username/bug in TODO
if (i == robot_id_ || i == goalie_id_) {
continue;
}
if (alive_robots_[i]) {
RobotState robot = last_world_state_->get_robot(true, i);
double dist = block_path.dist_to(robot.pose.position());
min_dist = std::min(min_dist, dist);
}
}

if (min_dist < (2 * kRobotRadius)) {
return ZONE;
}
return WALL;
}

std::optional<RobotIntent> Zoner::state_to_task(RobotIntent intent) {
switch (current_state_) {
case WALL: {
float box_w{field_dimensions_.penalty_long_dist()};
float box_h{field_dimensions_.penalty_short_dist()};
float line_w{field_dimensions_.line_width()};
double min_wall_rad{
(kRobotRadius * 4.0f) + line_w +
hypot(static_cast<double>(box_w) / 2, static_cast<double>((box_h)))};
min_wall_rad *= 1.5;

rj_geometry::Point goal_pos = field_dimensions_.our_goal_loc();
rj_geometry::Point ball_pos = last_world_state_->ball.position;

rj_geometry::Point target_point =
((ball_pos - goal_pos).normalized(min_wall_rad)) + goal_pos;

rj_geometry::Point target_vel{0.0, 0.0};

// Face ball
planning::PathTargetFaceOption face_option{planning::FaceBall{}};

// Avoid ball
bool ignore_ball{true};

// Create Motion Command
planning::LinearMotionInstant target{target_point, target_vel};
intent.motion_command =
planning::MotionCommand{"path_target", target, face_option, ignore_ball};
return intent;
}

case ZONE: {
// can change this point depending on zoner behavior
rj_geometry::Point center{1.35, 1.5};
rj_geometry::Point ball_pos = last_world_state_->ball.position;

if (field_dimensions_.our_goal_loc().y() > 4.5) {
center.y() = -1 * center.y();
}
if (ball_pos.x() > 0) {
center.x() = -1 * center.x();
}

std::vector<rj_geometry::Point> opp_poses{};

for (RobotState opp : last_world_state_->their_robots) {
double dist = center.dist_to(opp.pose.position());
if (dist < kZonerRadius) {
opp_poses.emplace_back(opp.pose.position());
}
}
// SPDLOG_INFO("opp pose size: {}", opp_poses.size());

rj_geometry::Point target_point{};
if (opp_poses.size() >= 2) {
// finding point that minimizes distance from opponent robots
target_point = find_centroid(opp_poses);
} else if (opp_poses.size() == 1) {
// mark if just one robot
double mark_rad = kRobotRadius * 4;
rishiso marked this conversation as resolved.
Show resolved Hide resolved
target_point = (ball_pos - opp_poses[0]).normalized(mark_rad) + opp_poses[0];
} else {
target_point = center;
}

rj_geometry::Point target_vel{0.0, 0.0};

// Face ball
planning::PathTargetFaceOption face_option{planning::FaceBall{}};

// Avoid ball
bool ignore_ball{true};

// Create Motion Command
planning::LinearMotionInstant target{target_point, target_vel};
intent.motion_command =
planning::MotionCommand{"path_target", target, face_option, ignore_ball};
return intent;
}
}
}

rj_geometry::Point Zoner::find_centroid(const std::vector<rj_geometry::Point> opp_poses) {

Check warning on line 121 in soccer/src/soccer/strategy/agent/position/zoner.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

the const qualified parameter 'opp_poses' is copied for each invocation; consider making it a reference
rj_geometry::Point p{};

for (rj_geometry::Point pos : opp_poses) {
p += pos;
}

return p / static_cast<double>(opp_poses.size());
}

std::string Zoner::get_current_state() { return "Zoner"; }

} // namespace strategy
61 changes: 61 additions & 0 deletions soccer/src/soccer/strategy/agent/position/zoner.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <cmath>

#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
#include <spdlog/spdlog.h>

#include <rj_msgs/action/robot_move.hpp>

#include "planning/instant.hpp"
#include "position.hpp"
#include "rj_common/field_dimensions.hpp"
#include "rj_common/time.hpp"
#include "rj_constants/constants.hpp"
#include "rj_geometry/geometry_conversions.hpp"
#include "rj_geometry/point.hpp"
#include "role_interface.hpp"

namespace strategy {

/*
* The Waller role provides the implementation for a defensive robot that implements
* this class to have a waller-like behavior where it aims to serve as a wall between
* the ball and the goal.
*/
class Zoner : public Position {

Check warning on line 27 in soccer/src/soccer/strategy/agent/position/zoner.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

class 'Zoner' defines a default destructor, a copy assignment operator, a move constructor and a move assignment operator but does not define a copy constructor
public:
Zoner(int r_id);
rishiso marked this conversation as resolved.
Show resolved Hide resolved
~Zoner() override = default;
Zoner(const Position& other);
Zoner(Zoner&& other) = default;
Zoner& operator=(const Zoner& other) = default;

Check warning on line 33 in soccer/src/soccer/strategy/agent/position/zoner.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

copy assignment operator is explicitly defaulted but implicitly deleted, probably because a base class or a non-static data member is not assignable, e.g. because the latter is marked 'const'; definition can either be removed or explicitly deleted
Zoner& operator=(Zoner&& other) = default;

Check warning on line 34 in soccer/src/soccer/strategy/agent/position/zoner.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

move assignment operator is explicitly defaulted but implicitly deleted, probably because a base class or a non-static data member is not assignable, e.g. because the latter is marked 'const'; definition can either be removed or explicitly deleted

private:
std::optional<RobotIntent> derived_get_task(RobotIntent intent) override;

// static constexpr double robot_diameter_multiplier_ = 1.5;
enum State { ZONE, WALL };

State current_state_ = ZONE;

/**
* @return what the state should be right now. called on each get_task tick
*/
State next_state();

/**
* @return the task to execute. called on each get_task tick AFTER next_state()
*/
std::optional<RobotIntent> state_to_task(RobotIntent intent);

static rj_geometry::Point find_centroid(const std::vector<rj_geometry::Point> opp_poses);

Check warning on line 54 in soccer/src/soccer/strategy/agent/position/zoner.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

parameter 'opp_poses' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions

std::string get_current_state() override;

static constexpr double kZonerRadius = 1.5;
};

} // namespace strategy
Loading