Skip to content

Commit

Permalink
Merge pull request #128 from RoboTeamTwente/keeperImprovements
Browse files Browse the repository at this point in the history
Keeper improvements and lots of other stuff
  • Loading branch information
JornJorn authored Jun 18, 2024
2 parents 7be4c91 + b9f5fca commit 06561b8
Show file tree
Hide file tree
Showing 150 changed files with 1,184 additions and 1,433 deletions.
1 change: 0 additions & 1 deletion roboteam_ai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ target_compile_options(testHelpers PRIVATE "${COMPILER_FLAGS}")
add_executable(roboteam_ai_tests
${PROJECT_SOURCE_DIR}/src/STPManager.cpp
${PROJECT_SOURCE_DIR}/test/main.cpp
${PROJECT_SOURCE_DIR}/test/ControlTests/ControlUtilsTest.cpp
${PROJECT_SOURCE_DIR}/test/HelperTests/FieldHelperTest.cpp
${PROJECT_SOURCE_DIR}/test/UtilTests/RefereeTest.cpp
${PROJECT_SOURCE_DIR}/test/WorldTests/BallTests.cpp
Expand Down
4 changes: 2 additions & 2 deletions roboteam_ai/include/roboteam_ai/control/ControlModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class ControlModule {
static void limitRobotCommand(rtt::RobotCommand& command, rtt::world::view::RobotView robot);

/**
* @brief Limits the velocity with a control_constants value
* @brief Limits the velocity with a constants value
* @param command Robot command that needs to be checked
*/
static void limitVel(rtt::RobotCommand& command);

/**
* @brief Limits the angular velocity with a control_constants value
* @brief Limits the angular velocity with a constants value
* @param command Robot command that needs to be checked
* @param robot Info about the robot
*/
Expand Down
29 changes: 0 additions & 29 deletions roboteam_ai/include/roboteam_ai/control/ControlUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,6 @@ namespace rtt::ai::control {
*/
class ControlUtils {
public:
/**
* @brief Calculates the force for a given vector and weight
* @param vector Direction of the force
* @param weight Weight that needs to be displaced
* @param minDistance Minimum distance the weight should move
* @return Force needed to displace the weight
*/
static Vector2 calculateForce(const rtt::Vector2 &vector, double weight, double minDistance);

/**
* @brief Limits the velocity
* @param vel current velocity
* @param maxVel maximum velocity
* @param minVel minimum velocity
* @param listenToReferee listen to or ignore the referee
* @return limited velocity
*/
static Vector2 velocityLimiter(const Vector2 &vel, double maxVel = Constants::MAX_VEL(), double minVel = 0.0, bool listenToReferee = true);

/**
* @brief calculates whether the object velocity will collide with a point
* @param objectPosition position of the object
* @param velocity velocity vector
* @param point point to check for collision
* @param maxDifference maximum difference between vector and point
* @return boolean that tells whether the object will collide with the point
*/
static bool objectVelocityAimedToPoint(const Vector2 &objectPosition, const Vector2 &velocity, const Vector2 &point, double maxDifference = 0.3);

/**
* @brief Determines the kick force based on the distance and the type of kick
* @param distance distance to the target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ namespace rtt::ai::control {
struct TimedPos1D {
double pos;
double time;
double timeToTarget;

TimedPos1D(double pos, double time) : pos(pos), time(time) {}
TimedPos1D(double pos, double time, double timeToTarget) : pos(pos), time(time), timeToTarget(timeToTarget) {}
};

class OvershootComputations {
Expand All @@ -35,8 +36,8 @@ class OvershootComputations {
* @param targetTime The time it takes to reach the target position.
* @return Vector2 The overshooting destination of the robot.
*/
static Vector2 overshootingDestination(const Vector2 &startPosition, const Vector2 &endPosition, const Vector2 &startVelocity, double maxVelocity, double maxAcceleration,
double targetTime);
static std::pair<Vector2, double> overshootingDestination(const Vector2 &startPosition, const Vector2 &endPosition, const Vector2 &startVelocity, double maxVelocity,
double maxAcceleration, double targetTime);

private:
/**
Expand Down
3 changes: 1 addition & 2 deletions roboteam_ai/include/roboteam_ai/stp/Play.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "PlayEvaluator.h"
#include "Role.hpp"
#include "computations/PositionComputations.h"
#include "constants/GeneralizationConstants.h"
#include "stp/evaluations/BaseEvaluation.h"
#include "utilities/Dealer.h"
#include "utilities/GameState.h"
Expand Down Expand Up @@ -110,7 +109,7 @@ class Play {
uint8_t getLastScore() const;

protected:
std::array<std::unique_ptr<Role>, rtt::ai::Constants::ROBOT_COUNT()> roles; /**< The roles, constructed in ctor of a play */
std::array<std::unique_ptr<Role>, rtt::ai::constants::MAX_ROBOT_COUNT> roles; /**< The roles, constructed in ctor of a play */

std::vector<PlayEvaluator::PlayScoring> scoring; /**< The evaluations with their weight */

Expand Down
11 changes: 1 addition & 10 deletions roboteam_ai/include/roboteam_ai/stp/PlayEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ enum class GlobalEvaluation {
KickOffThemGameState,
KickOffThemPrepareGameState,
KickOffUsGameState,
KickOffUsOrNormalGameState,
KickOffUsPrepareGameState,
NormalOrFreeKickUsGameState,
NormalPlayGameState,
PenaltyThemGameState,
PenaltyThemPrepareGameState,
Expand Down Expand Up @@ -74,14 +72,7 @@ class PlayEvaluator {
* @param cutOff Bottom bound value of true
* @return boolean if FUZZY-TRUE is high enough
*/
static bool checkEvaluation(GlobalEvaluation globalEvaluation, const rtt::world::World* world, uint8_t cutOff = control_constants::FUZZY_DEFAULT_CUTOFF) noexcept;

/**
* @brief Calculate a final weighted score given a vector of scores with their weights
* @param scoring vector withto be considered Evaluations
* @return final score (0-255)
*/
static uint8_t calculateScore(std::vector<PlayScoring>& scoring);
static bool checkEvaluation(GlobalEvaluation globalEvaluation, const rtt::world::World* world, uint8_t cutOff = constants::FUZZY_DEFAULT_CUTOFF) noexcept;

private:
static inline std::unordered_map<GlobalEvaluation, uint8_t> scoresGlobal{}; /**< Map of all loaded Global Evaluations scores */
Expand Down
2 changes: 1 addition & 1 deletion roboteam_ai/include/roboteam_ai/stp/StpInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <optional>
#include <roboteam_utils/Field.hpp>

#include "constants/GeneralizationConstants.h"
#include "computations/PositionScoring.h"
#include "utilities/StpInfoEnums.h"
#include "world/views/BallView.hpp"
#include "world/views/RobotView.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#define RTT_COMPUTATIONMANAGER_H

#include "roboteam_utils/Vector2.h"
#include "stp/constants/GeneralizationConstants.h"

namespace rtt::ai::stp {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GoalComputations {
* @param openSegments Vector of lines
* @return Longest line from openSegments
*/
static const LineSegment &getLongestSegment(const std::vector<LineSegment> &openSegments);
static const LineSegment getLongestSegment(const std::vector<LineSegment> &openSegments);
};
} // namespace rtt::ai::stp::computations
#endif // RTT_GOALCOMPUTATIONS_H
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "stp/Role.hpp"
#include "stp/StpInfo.h"
#include "stp/constants/GeneralizationConstants.h"
#include "utilities/Constants.h"
#include "world/FieldComputations.h"
#include "world/World.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <roboteam_utils/LineSegment.h>
#include <stp/computations/InterceptionComputations.h>
#include <stp/constants/GeneralizationConstants.h>

#include <roboteam_utils/Field.hpp>

Expand All @@ -20,8 +19,8 @@ struct PassInfo {
int keeperId = -1;
int passerId = -1;
int receiverId = -1;
Vector2 passLocation; // The location where the ball will be passed from, towards the receiver
Vector2 receiverLocation; // The location of the receiver, who will receive the ball from the passer
Vector2 passLocation; // The location where the ball will be passed from, towards the receiver
Vector2 receiverLocation = Vector2(6, 0); // The location of the receiver, who will receive the ball from the passer
uint8_t passScore = 0;
};

Expand All @@ -38,10 +37,10 @@ class PassComputations {
* @param profile the profile to be used when scoring the pass location
* @param world the current world state
* @param field the current field
* @param keeperCanPass indicate whether the keeper can pass and be passed to
* @param keeperMustPass indicate whether the keeper must pass
* @return a PassInfo struct which contains the relevant information needed to complete the pass
*/
static PassInfo calculatePass(gen::ScoreProfile profile, const world::World* world, const Field& field, bool keeperCanPass = false);
static PassInfo calculatePass(gen::ScoreProfile profile, const world::World* world, const Field& field, bool keeperMustPass = false);

private:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "stp/Role.hpp"
#include "stp/StpInfo.h"
#include "stp/computations/PassComputations.h"
#include "stp/constants/GeneralizationConstants.h"
#include "utilities/Constants.h"
#include "world/FieldComputations.h"
#include "world/World.hpp"
Expand Down Expand Up @@ -80,9 +79,10 @@ class PositionComputations {
* @param targetPosition The initial target position
* @param ballPosition The position of the ball
* @param field The current field
* @param avoidObj The objects to avoid
* @return A position that is not within the min allowed distance to the ball
*/
static Vector2 calculateAvoidBallPosition(Vector2 targetPosition, Vector2 ballPosition, const Field &field);
static Vector2 calculateAvoidBallPosition(Vector2 targetPosition, Vector2 ballPosition, const Field &field, const AvoidObjects &avoidObj);

/**
* @brief Calculates info for the harasser role
Expand All @@ -92,7 +92,7 @@ class PositionComputations {
* @param world The current world
* @param interceptionLocation The location where the harasser should go to
*/
static void calculateInfoForHarasser(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, stp::control_constants::MAX_ROBOT_COUNT> *roles,
static void calculateInfoForHarasser(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, constants::MAX_ROBOT_COUNT> *roles,
const Field &field, world::World *world, Vector2 interceptionLocation) noexcept;

/**
Expand All @@ -103,9 +103,8 @@ class PositionComputations {
* @param world The current world
* @param mustStayOnOurSide Whether the defenders should always stay on our side of the field, for example to prevent interference during our own attack
*/
static void calculateInfoForDefendersAndWallers(std::unordered_map<std::string, StpInfo> &stpInfos,
std::array<std::unique_ptr<Role>, stp::control_constants::MAX_ROBOT_COUNT> &roles, const Field &field, world::World *world,
bool mustStayOnOurSide) noexcept;
static void calculateInfoForDefendersAndWallers(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, constants::MAX_ROBOT_COUNT> &roles,
const Field &field, world::World *world, bool mustStayOnOurSide) noexcept;

/**
* @brief Calculates info for the attackers
Expand All @@ -114,7 +113,7 @@ class PositionComputations {
* @param field The current field
* @param world The current world
*/
static void calculateInfoForAttackers(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, stp::control_constants::MAX_ROBOT_COUNT> &roles,
static void calculateInfoForAttackers(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, constants::MAX_ROBOT_COUNT> &roles,
const Field &field, world::World *world) noexcept;

/**
Expand All @@ -124,7 +123,7 @@ class PositionComputations {
* @param field The current field
* @param world The current world
*/
static void calculateInfoForFormation(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, stp::control_constants::MAX_ROBOT_COUNT> &roles,
static void calculateInfoForFormation(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, constants::MAX_ROBOT_COUNT> &roles,
const Field &field, world::World *world) noexcept;

/**
Expand All @@ -134,9 +133,8 @@ class PositionComputations {
* @param field The current field
* @param world The current world
*/
static void calculateInfoForFormationOurSide(std::unordered_map<std::string, StpInfo> &stpInfos,
std::array<std::unique_ptr<Role>, stp::control_constants::MAX_ROBOT_COUNT> &roles, const Field &field,
world::World *world) noexcept;
static void calculateInfoForFormationOurSide(std::unordered_map<std::string, StpInfo> &stpInfos, std::array<std::unique_ptr<Role>, constants::MAX_ROBOT_COUNT> &roles,
const Field &field, world::World *world) noexcept;
/**
* @brief Recalculates info for the position of our robots to not interfere with passing
* @param stpInfos The current stpInfos
Expand All @@ -158,9 +156,10 @@ class PositionComputations {
* @param targetPosition The position where the robot wants to go
* @param field The current field
* @param avoidShape The shape to avoid
* @param avoidObj The objects to avoid
* @return A position that is outside the given shape
*/
static Vector2 calculatePositionOutsideOfShape(Vector2 targetPosition, const Field &field, const std::unique_ptr<Shape> &avoidShape);
static Vector2 calculatePositionOutsideOfShape(Vector2 targetPosition, const Field &field, const std::unique_ptr<Shape> &avoidShape, const AvoidObjects &avoidObj);
};
} // namespace rtt::ai::stp
#endif // RTT_POSITIONCOMPUTATIONS_H
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,63 @@

#include <roboteam_utils/Field.hpp>

#include "stp/constants/GeneralizationConstants.h"
#include "world/World.hpp"

namespace rtt::ai::stp {

namespace gen {
/**
* @brief Struct that is used to store computations made with this module.
* Save computations here that are usable for each robot for a position.
* DO NOT save values specific to a robot in here (like TimeToPosition).
* If a position's score for a specific evaluation already had been computed in the tick, it will
* use that value instead of recomputing it. If it was not computed yet, it will compute and save it.
* @memberof scoreOpen : uint8_t score for the Openness of a position -> evaluations/position/OpennessEvaluation
* @memberof scoreLineOfSight : uint8_t score for the LineOfSight to a position from a position -> ../LineOfSightEvaluation
* @memberof scoreGoalShot : uint8_t score for the Goal Shot opportunity for a position -> ../GoalShotEvaluation
*/
struct PositionScores {
std::optional<double> scoreOpen;
std::optional<double> scoreLineOfSight;
std::optional<double> scoreGoalShot;
};

/**
* @brief Combination of weights for each of the scores.
* This will be used to determine the final score for a robot for a position.
* All weights will be multiplied with the corresponding score and then normalized.
* @memberof weightOpen for scoreOpen
* @memberof weightLineOfSight for scoreLineOfSight
* @memberof weightGoalShot for scoreGoalShot
*/
struct ScoreProfile {
double weightOpen;
double weightLineOfSight;
double weightGoalShot;
};

/**
* @brief Structure with a position and its score
* @memberof position Vector2 coordinates of a position
* @memberof score The score for said position
*/
struct ScoredPosition {
Vector2 position;
uint8_t score;
};

/**
* Generalized Position Profiles to be used in plays.
* They consist of a generalized weight combination.
*/

constexpr ScoreProfile AttackingPass = {0.5, 1, 2}; /**< Scoring weights for Attacking Pass */
constexpr ScoreProfile SafePass = {1, 1, 0}; /**< Scoring weights for Safe Pass, used by the keeper */
constexpr ScoreProfile LineOfSight = {0, 1, 0}; /**< Scoring weights for Line of Sight score, only used for testing minimum line of sight */
constexpr ScoreProfile GoalShot = {0, 0, 1}; /**< Scoring weights for Goal Shot Score, a position where we can shoot at goal */
constexpr ScoreProfile ChippingPass = {1, 0, 1}; /**< Scoring weights for ChippingPass score */
} // namespace gen

/**
* @brief Class that manages the scoring for a position
*/
Expand Down
Loading

0 comments on commit 06561b8

Please sign in to comment.