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

Ball placement obstacle with Stadium Shape on their ball placement #2294

Open
wants to merge 15 commits into
base: ros2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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 rj_common/include/rj_common/field_dimensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <rj_geometry/arc.hpp>
#include <rj_geometry/circle.hpp>
#include <rj_geometry/composite_shape.hpp>
#include <rj_geometry/stadium_shape.hpp>
#include <rj_geometry/geometry_conversions.hpp>
#include <rj_geometry/line.hpp>
#include <rj_geometry/point.hpp>
Expand Down
48 changes: 48 additions & 0 deletions rj_geometry/include/rj_geometry/stadium_shape.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include "point.hpp"
#include "shape.hpp"
#include "segment.hpp"
#include "polygon.hpp"
#include "shape_set.hpp"
#include <vector>
#include <memory>
#include <set>

namespace rj_geometry {

/**
* A rj_geometry::StadiumShape is a Shape that is made up of 2 circles and a polygon. It represents the shape of a track from track and field.
*/
class StadiumShape : public Shape {

Check warning on line 17 in rj_geometry/include/rj_geometry/stadium_shape.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

class 'StadiumShape' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator
public:
~StadiumShape() = default;

Check warning on line 19 in rj_geometry/include/rj_geometry/stadium_shape.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

annotate this function with 'override' or (rarely) 'final'

StadiumShape() = default;

Copy link
Contributor

Choose a reason for hiding this comment

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

add a move constructor

StadiumShape(Point c1, Point c2, float r) {
init(c1, c2, r);
}

[[nodiscard]] Shape* clone() const override;

[[nodiscard]] bool contains_point(Point pt) const override;
[[nodiscard]] bool near_point(Point pt, float threshold) const override;

[[nodiscard]] const std::vector<std::shared_ptr<Shape>>& subshapes() const {
return subshapes_;
}

[[nodiscard]] const rj_geometry::ShapeSet drawshapes() const {

Check warning on line 36 in rj_geometry/include/rj_geometry/stadium_shape.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

return type 'const rj_geometry::ShapeSet' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness
return drawshapes_;
}

protected:
void init(Point c1, Point c2, float r);

private:
std::vector<std::shared_ptr<Shape>> subshapes_;
rj_geometry::ShapeSet drawshapes_;
};

}

Check warning on line 48 in rj_geometry/include/rj_geometry/stadium_shape.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

namespace 'rj_geometry' not terminated with a closing comment
1 change: 1 addition & 0 deletions rj_geometry/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(GEOMETRY2D_SRCS
arc.cpp
circle.cpp
composite_shape.cpp
stadium_shape.cpp
line.cpp
point.cpp
polygon.cpp
Expand Down
50 changes: 50 additions & 0 deletions rj_geometry/src/stadium_shape.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <rj_geometry/stadium_shape.hpp>

namespace rj_geometry {

Shape* StadiumShape::clone() const { return new StadiumShape(*this); }

void StadiumShape::init(Point c1, Point c2, float r) {
rj_geometry::Circle first_circle = rj_geometry::Circle{c1, static_cast<float>(r)};
rj_geometry::Circle second_circle = rj_geometry::Circle{c2, static_cast<float>(r)};

rj_geometry::Segment vect{c1, c2};

rj_geometry::Point end1{c1.x() + r * (c2.x() - c1.x()) / vect.length(), c1.y() + r * (c2.y() - c1.y()) / vect.length()};
rj_geometry::Point end2{c2.x() - r * (c2.x() - c1.x()) / vect.length(), c2.y() - r * (c2.y() - c1.y()) / vect.length()};

rj_geometry::Segment vect_updated{end1, end2};
rj_geometry::Polygon rect_obs{vect_updated, r};

std::shared_ptr<rj_geometry::Circle> c1_obs_ptr = std::make_shared<rj_geometry::Circle>(first_circle);
std::shared_ptr<rj_geometry::Polygon> rect_obs_ptr = std::make_shared<rj_geometry::Polygon>(rect_obs);
std::shared_ptr<rj_geometry::Circle> c2_obs_ptr = std::make_shared<rj_geometry::Circle>(second_circle);

subshapes_.push_back(c1_obs_ptr);
subshapes_.push_back(rect_obs_ptr);
subshapes_.push_back(c2_obs_ptr);

drawshapes_.add(c1_obs_ptr);
drawshapes_.add(rect_obs_ptr);
drawshapes_.add(c2_obs_ptr);
}

bool StadiumShape::contains_point(Point pt) const {
for (const auto& subshape : subshapes_) {

Check warning on line 33 in rj_geometry/src/stadium_shape.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

replace loop by 'std::any_of()'
if (subshape->contains_point(pt)) {
return true;
}
}
return false;
}

bool StadiumShape::near_point(Point pt, float threshold) const {
for (const auto& subshape : subshapes_) {

Check warning on line 42 in rj_geometry/src/stadium_shape.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

replace loop by 'std::any_of()'
if (subshape->near_point(pt, threshold)) {
return true;
}
}
return false;
}

} // namespace rj_geometry
6 changes: 6 additions & 0 deletions soccer/src/soccer/debug_drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ void DebugDrawer::draw_circle(rj_geometry::Point center, float radius, const QCo
dbg->set_color(color(qc));
}

// void DebugDrawer::draw_stadium(rj_geometry::StadiumShape& stadium, const QColor& qc, const QString& layer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the comments

// this->draw_circle(stadium.drawshapes()[0], qc, layer);
// this->draw_polygon(stadium.drawshapes()[1], qc, layer);
// this->draw_circle(stadium.drawshapes()[2], qc, layer);
// }

void DebugDrawer::draw_arc(const rj_geometry::Arc& arc, const QColor& qc, const QString& layer) {
Packet::DebugArc* dbg = log_frame_.add_debug_arcs();
dbg->set_layer(find_debug_layer(layer));
Expand Down
5 changes: 5 additions & 0 deletions soccer/src/soccer/debug_drawer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <rj_geometry/arc.hpp>
#include <rj_geometry/composite_shape.hpp>
#include <rj_geometry/stadium_shape.hpp>
#include <rj_geometry/point.hpp>
#include <rj_geometry/polygon.hpp>
#include <rj_geometry/segment.hpp>
Expand Down Expand Up @@ -78,6 +79,10 @@ class DebugDrawer {
const QColor& qw = Qt::black,
const QString& layer = QString());

// void draw_stadium(rj_geometry::StadiumShape& stadium,
Copy link
Contributor

Choose a reason for hiding this comment

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

here too

// const QColor& qc = Qt::black,
// const QString& layer = QString());

/**
* Fill the given log frame with the current debug drawing information,
* and reset our current debug drawing data for the next cycle.
Expand Down
16 changes: 16 additions & 0 deletions soccer/src/soccer/planning/planner/plan_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@
}

out_static->add(std::make_shared<rj_geometry::Circle>(std::move(ball_obs)));

auto maybe_bp_point = in.play_state.ball_placement_point();
if (maybe_bp_point.has_value() && in.play_state.is_their_restart()) {
rj_geometry::Point bp_point = maybe_bp_point.value();
rj_geometry::StadiumShape stadium = rj_geometry::StadiumShape{in.world_state->ball.position, bp_point, ball_obs.radius()};

Check warning on line 85 in soccer/src/soccer/planning/planner/plan_request.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

'ball_obs' used after it was moved

// for some reason adding the shared pointer below to our static obstacles breaks it, so we add the shape set it has instead.
// std::shared_ptr<rj_geometry::Shape> track_obs_ptr = std::make_shared<rj_geometry::Shape>(stadium);
Copy link
Contributor

Choose a reason for hiding this comment

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

this will be fixed when you add a move constructor


out_static->add(stadium.drawshapes());

if (in.debug_drawer != nullptr) {
QColor draw_color = Qt::red;
in.debug_drawer->draw_stadium(stadium, draw_color);
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions soccer/src/soccer/ros_debug_drawer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
color_from_qt(color)));
}

void draw_stadium(const rj_geometry::StadiumShape& stadium, const QColor& color = QColor::fromRgb(0, 0, 0, 0)) {

Check failure on line 61 in soccer/src/soccer/ros_debug_drawer.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

no type named 'StadiumShape' in namespace 'rj_geometry'
this->draw_shapes(stadium.drawshapes(), color);
}

void draw_segment(const rj_geometry::Segment& segment,
const QColor& color = QColor::fromRgb(0, 0, 0)) {
frame_.segments.push_back(rj_drawing_msgs::build<rj_drawing_msgs::msg::DrawSegment>()
Expand Down
Loading