Skip to content

Commit 6ff4cea

Browse files
rhkoulenrkoulen3Squid5678rishisosanatd33
authored
Shared Utility File for rj_strategy Positions (#2525)
* wrote the basic framework for exporting common utilities, replaced one such example in offense * comp changes (#2522) * added robot pid values * Final PID values * field teting 3/17 * 03/18fasdfasdfsadjfjsdahflkajsdhfkljasdhfaslfhk * uh shit might work * sdfsadfsfd * march 202sjflsakdjflsadfjlks * defense now has a state for shooting to goal if closest to ball * added bounding checks to ensure kicking field and kick only when ball is slow * comp changes * Fix Code Style On field-testing-3-15 (#2523) automated style fixes Co-authored-by: Squid5678 <Squid5678@users.noreply.github.com> * i forgot header files were a thing * rebase * fix defense shooting * int not double --------- Co-authored-by: rishiso <rishisoni.5678@gmail.com> Co-authored-by: sanat <saisanat@gmail.com> Co-authored-by: Sid Parikh <parikhsid16@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Squid5678 <Squid5678@users.noreply.github.com> * wrote the basic framework for exporting common utilities, replaced one such example in offense * distilling some computations from offense * refactored solo offense with position utils (also made solo offense into a MVP robot position we can test on sunday) * I think it's bad for me to pollute this namespace? I don't really know how namespaces work. * tiny cleanups * rules * passing a non-positive value into granularity would infinite loop, might as well squash that bug early * Fix Code Style On common_utils (#2526) * automated style fixes * I don't like the way it styled this --------- Co-authored-by: rhkoulen <rhkoulen@users.noreply.github.com> Co-authored-by: r.koulen.p@gmail.com <rkoulen3@gatech.edu> * review fixes * Fix Code Style On common_utils (#2532) automated style fixes Co-authored-by: rhkoulen <rhkoulen@users.noreply.github.com> * fixes to calculate_kick_speed * Fix Code Style On common_utils (#2533) automated style fixes Co-authored-by: rhkoulen <rhkoulen@users.noreply.github.com> --------- Co-authored-by: r.koulen.p@gmail.com <rkoulen3@gatech.edu> Co-authored-by: Aalind Tyagi <42896179+Squid5678@users.noreply.github.com> Co-authored-by: rishiso <rishisoni.5678@gmail.com> Co-authored-by: sanat <saisanat@gmail.com> Co-authored-by: Sid Parikh <parikhsid16@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Squid5678 <Squid5678@users.noreply.github.com> Co-authored-by: rhkoulen <rhkoulen@users.noreply.github.com>
1 parent eef9bdc commit 6ff4cea

6 files changed

Lines changed: 448 additions & 274 deletions

File tree

src/rj_constants/include/rj_constants/constants.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ inline constexpr float kRobotHeight = 0.150f;
2626
inline constexpr float kRobotMouthWidth = 0.0635f;
2727
inline constexpr float kRobotMouthRadius = 0.078f;
2828

29+
inline constexpr float kShotCalculationGranularity = 0.04f;
30+
2931
// Constant for ball deceleration on field
3032
inline constexpr float kBallDecel{-0.4f};
3133

src/rj_strategy/include/rj_strategy/agent/position/offense.hpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "rj_strategy/agent/position.hpp"
2020
#include "rj_strategy/agent/position/seeker.hpp"
21+
#include "rj_strategy/agent/position_utils.hpp"
2122

2223
namespace strategy {
2324

@@ -230,21 +231,6 @@ class Offense : public Position {
230231
*/
231232
bool check_if_open(int target_robot_shell);
232233

233-
/**
234-
* @return whether or not a robot is capable of shooting from their pos
235-
*/
236-
bool can_i_shoot() const;
237-
238-
/**
239-
* @return the target (within the goal) that would be the most clear shot
240-
*/
241-
rj_geometry::Point calculate_best_shot() const;
242-
243-
/**
244-
* @return whether the ball is in an area that non-goalies cannot reach.
245-
*/
246-
bool ball_in_red() const;
247-
248234
/**
249235
* @return true when in PASSING_FINISHED and the kick failsafe timeout has
250236
* elapsed while the ball is still within possession range of this robot.

src/rj_strategy/include/rj_strategy/agent/position/solo_offense.hpp

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <rj_msgs/action/robot_move.hpp>
1818

1919
#include "rj_strategy/agent/position.hpp"
20+
#include "rj_strategy/agent/position_utils.hpp"
2021

2122
namespace strategy {
2223

@@ -31,34 +32,41 @@ class SoloOffense : public Position {
3132
std::string get_current_state() override;
3233

3334
private:
34-
/**
35-
* @brief Overriden from Position. Calls next_state and then state_to_task on each tick.
36-
*/
37-
std::optional<RobotIntent> derived_get_task(RobotIntent intent) override;
38-
39-
enum State { TO_BALL, KICK, MARKER, ROTATE };
40-
41-
State current_state_ = TO_BALL;
42-
43-
rj_geometry::Point target_;
35+
enum State {
36+
IDLE, // The nothing doer
37+
MARKER, // Aggressively sit between ball and goal pos
38+
TO_BALL, // Collect
39+
ROTATE, // After successful collect, aim and fire
40+
KICK // The more naive line kick
41+
};
42+
State kick_strategy_ =
43+
TO_BALL; // set to TO_BALL for collect kicking, set to KICK for line kicking
44+
planning::LinearMotionInstant kick_target_; // aiming point
45+
46+
State current_state_ = IDLE;
47+
48+
static constexpr std::string_view state_to_name(State s) {
49+
switch (s) {
50+
case IDLE:
51+
return "IDLE";
52+
case MARKER:
53+
return "MARKER";
54+
case TO_BALL:
55+
return "TO_BALL";
56+
case ROTATE:
57+
return "ROTATE";
58+
case KICK:
59+
return "KICK";
60+
default:
61+
return "unknown?";
62+
}
63+
}
4464

45-
int marking_id_;
46-
47-
bool kick_ = false;
48-
int counter_ = 0;
65+
std::optional<RobotIntent> derived_get_task(RobotIntent intent) override;
4966

50-
/**
51-
* @return what the state should be right now. called on each get_task tick
52-
*/
5367
State next_state();
5468

55-
/**
56-
* @return the task to execute. called on each get_task tick AFTER next_state()
57-
*/
5869
std::optional<RobotIntent> state_to_task(RobotIntent intent);
59-
60-
rj_geometry::Point calculate_best_shot() const;
61-
double distance_from_their_robots(rj_geometry::Point tail, rj_geometry::Point head) const;
6270
};
6371

6472
} // namespace strategy

0 commit comments

Comments
 (0)