Skip to content

Commit

Permalink
Merge pull request #98 from RoboTeamTwente/update/pass-defender
Browse files Browse the repository at this point in the history
[roboteam_ai] Change of tactics
  • Loading branch information
JornJorn authored Jan 9, 2024
2 parents f470587 + 886fd93 commit 57a6ceb
Show file tree
Hide file tree
Showing 139 changed files with 1,938 additions and 4,182 deletions.
6 changes: 0 additions & 6 deletions docs/Ball.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ serves the purpose of representing the ball. Things like position and velocity a

`expectedEndPosition` -> End position that we _think_ the ball will lay at when it comes to a stop.

`filteredVelocity` -> Velocity but adjusted to match up with physics n stuff, it's used to determine a more realistic end position.

## Functions ##

`initializeCalculations` -> Calls the 4 calculation methods.

`initBallAtRobotPosition` -> If there is no position for the ball we look at the robot ball sensors for this.

`filterBallVelocity` -> Sets `filteredVelocity`

`updateExpectedBallEndPosition` -> Sets `expectedEndPosition`.

`updateBallAtRobotPosition` -> Updates `expectedEndPosition` and draws to the interface.
Expand All @@ -35,8 +31,6 @@ serves the purpose of representing the ball. Things like position and velocity a

`getExpectedEndPositionBall` -> Returns `expectedEndPosition`

`getFilteredVelocity` -> Returns `filteredVelocity`

`Ball(proto::WorldBall, World*)` -> Constructs a ball from a proto message + the world data.

## Advice ##
Expand Down
14 changes: 3 additions & 11 deletions docs/Robot.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ The enum Team in [team.hpp](https://github.com/RoboTeamTwente/roboteam_ai/blob/d

`angle` -> Current angle of the robot

`pidPreviousVel` -> The previous pid velocity.

`distanceToBall` -> Distance from the robot to the ball

`angleDiffToBall` -> Angle offset between the kicker and the ball.
Expand All @@ -27,19 +25,13 @@ The enum Team in [team.hpp](https://github.com/RoboTeamTwente/roboteam_ai/blob/d

`batteryLow` -> Flag that indicates whether the battery of the robot is low.

`dribblerState` -> State of the dribbler, essentially the number indicates how fast it goes.

`previousDribblerState` -> State of dribbler in the previous tick, dito.

`timeDribblerChanged` -> The time at which the state of the dribbler changed.

`timeToChangeOneDribblerLevel` -> The time which it takes to change from for example 0 to 1 for the dribbler.

`workingDribbler` -> True if dribbler works, false if not.

`workingBallSensor` -> Dito but for sensor.

`seesBall` -> True if the ball sensor picks up the ball, false if not.
`BallSensorSeesBall` -> True if the ball sensor picks up the ball, false if not.

`DribblerSeesBall` -> True if the dribbler picks up the ball, false if not.

`ballPos` -> Position of the ball (if seesBall == true)

Expand Down
2 changes: 1 addition & 1 deletion format.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
find -L | grep -E "^./roboteam.*?\.(c|cpp|h|hpp)$" --color=never | xargs clang-format -i -style="{BasedOnStyle : Google, IndentWidth : 4, ColumnLimit : 180}"
find -L . -not -path "./roboteam_autoref/*" -not -path "./roboteam_robothub/roboteam_embedded_messages/*" | grep -E "^./roboteam.*?\.(c|cpp|h|hpp)$" --color=never | xargs clang-format -i -style="{BasedOnStyle : Google, IndentWidth : 4, ColumnLimit : 180}"
25 changes: 3 additions & 22 deletions roboteam_ai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ add_library(roboteam_ai_tactics
${PROJECT_SOURCE_DIR}/src/stp/tactics/active/OrbitKick.cpp
${PROJECT_SOURCE_DIR}/src/stp/tactics/active/Receive.cpp
# passive/
${PROJECT_SOURCE_DIR}/src/stp/tactics/passive/AvoidBall.cpp
${PROJECT_SOURCE_DIR}/src/stp/tactics/passive/BlockBall.cpp
${PROJECT_SOURCE_DIR}/src/stp/tactics/passive/BlockRobot.cpp
${PROJECT_SOURCE_DIR}/src/stp/tactics/passive/Formation.cpp
${PROJECT_SOURCE_DIR}/src/stp/tactics/passive/Halt.cpp
${PROJECT_SOURCE_DIR}/src/stp/tactics/passive/BallStandBack.cpp)
Expand All @@ -84,7 +82,7 @@ add_library(roboteam_ai_roles
${PROJECT_SOURCE_DIR}/src/stp/roles/Keeper.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/PenaltyKeeper.cpp
# active
${PROJECT_SOURCE_DIR}/src/stp/roles/active/Attacker.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/active/Striker.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/active/Harasser.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/active/BallPlacer.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/active/FreeKickTaker.cpp
Expand All @@ -94,11 +92,9 @@ add_library(roboteam_ai_roles
${PROJECT_SOURCE_DIR}/src/stp/roles/active/PassReceiver.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/active/PenaltyTaker.cpp
# passive
${PROJECT_SOURCE_DIR}/src/stp/roles/passive/BallAvoider.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/passive/BallDefender.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/passive/Defender.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/passive/Formation.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/passive/Halt.cpp
${PROJECT_SOURCE_DIR}/src/stp/roles/passive/RobotDefender.cpp
)
target_include_directories(roboteam_ai_roles
PRIVATE include/roboteam_ai
Expand Down Expand Up @@ -139,7 +135,6 @@ add_library(roboteam_ai_plays
${PROJECT_SOURCE_DIR}/src/stp/plays/referee_specific/PenaltyThemPrepare.cpp
${PROJECT_SOURCE_DIR}/src/stp/plays/referee_specific/PenaltyUs.cpp
${PROJECT_SOURCE_DIR}/src/stp/plays/referee_specific/PenaltyUsPrepare.cpp
${PROJECT_SOURCE_DIR}/src/stp/plays/referee_specific/FormationPreHalf.cpp
)
target_include_directories(roboteam_ai_plays
PRIVATE include/roboteam_ai
Expand All @@ -156,26 +151,13 @@ target_compile_options(roboteam_ai_plays PRIVATE "${COMPILER_FLAGS}")
###### EVALUATION #######
add_library(roboteam_ai_evaluation
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/WeHaveBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/WeDoNotHaveBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/TheyHaveBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/TheyDoNotHaveBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallGotShotGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallMovesSlowGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallOnOurSideGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallOnTheirSideGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallInOurDefenseAreaAndStillGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallNotInOurDefenseAreaAndStillGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/FreedomOfRobotsGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallCloseToUsGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallCloseToThemGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/DistanceFromBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/WeHaveMajorityGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/GoalVisionGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/GoalVisionFromBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallIsFreeGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/TheyHaveBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/TheyDoNotHaveBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/NoGoalVisionFromBallGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/global/BallClosestToUsGlobalEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/game_states/BallPlacementUsGameStateEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/game_states/BallPlacementThemGameStateEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/game_states/HaltGameStateEvaluation.cpp
Expand All @@ -197,7 +179,6 @@ add_library(roboteam_ai_evaluation
${PROJECT_SOURCE_DIR}/src/stp/evaluations/position/OpennessEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/position/LineOfSightEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/position/GoalShotEvaluation.cpp
${PROJECT_SOURCE_DIR}/src/stp/evaluations/position/BlockingEvaluation.cpp
)
target_include_directories(roboteam_ai_evaluation
PRIVATE include/roboteam_ai
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ class WorldObjects {
* @param field Used for information about the field
* @param collisionDatas std::vector which rtt::BB::CollisionData can be added to
* @param pathPoints std::vector with path points
* @param robotId ID of the robot
* @param timeStep Time between pathpoints
* @param completedTimeSteps Number of completed time steps
*/
void calculateFieldCollisions(const rtt::Field &field, std::vector<CollisionData> &collisionDatas, const std::vector<Vector2> &pathPoints, int robotId, double timeStep);
void calculateFieldCollisions(const rtt::Field &field, std::vector<CollisionData> &collisionDatas, const std::vector<Vector2> &pathPoints, double timeStep,
size_t completedTimeSteps);

/**
* @brief Takes a calculated path and checks points along the path if they are inside the defensearea if
Expand All @@ -83,8 +84,10 @@ class WorldObjects {
* @param pathPoints std::vector with path points
* @param robotId ID of the robot
* @param timeStep Time between pathpoints
* @param completedTimeSteps Number of completed time steps
*/
void calculateDefenseAreaCollisions(const rtt::Field &field, std::vector<CollisionData> &collisionDatas, const std::vector<Vector2> &pathPoints, int robotId, double timeStep);
void calculateDefenseAreaCollisions(const rtt::Field &field, std::vector<CollisionData> &collisionDatas, const std::vector<Vector2> &pathPoints, int robotId, double timeStep,
size_t completedTimeSteps);

/**
* @brief Takes a calculated path of a robot and checks points along the path if they are too close to an
Expand All @@ -94,22 +97,24 @@ class WorldObjects {
* @param collisionDatas std::vector which rtt::BB::CollisionData can be added to
* @param pathPoints std::vector with path points
* @param timeStep Time between pathpoints
* @param dist Distance to the ball
* @param completedTimeSteps Number of completed time steps
*/
void calculateBallCollisions(const rtt::world::World *world, std::vector<CollisionData> &collisionDatas, std::vector<Vector2> pathPoints, double timeStep, double dist);
void calculateBallCollisions(const rtt::world::World *world, std::vector<CollisionData> &collisionDatas, std::vector<Vector2> pathPoints, double timeStep, double dist,
size_t completedTimeSteps);

/**
* @brief Takes a calculated path of a robot and checks points along the path if they are too close to an
* approximation of the enemy robot paths. Adds these points and the time to collisionDatas and collisionTimes if
* the difference in velocity between the two robots is more than 1.5 ms/s and we are driving faster
* @param world Used for information about the enemy robots
* @param BBTrajectory BBTrajectory which is used for getting the velocity of the robot
* @param collisionDatas std::vector which rtt::BB::CollisionData can be added to
* @param pathPoints std::vector with path points
* @param timeStep Time between pathpoints
* @param timeStepsDone Amount of seconds of the trajectory already completed by the robot
* @param completedTimeSteps Amount of seconds of the trajectory already completed by the robot
*/
void calculateEnemyRobotCollisions(const rtt::world::World *world, rtt::Trajectory2D Trajectory, std::vector<CollisionData> &collisionDatas,
const std::vector<Vector2> &pathPoints, double timeStep, size_t timeStepsDone);
void calculateEnemyRobotCollisions(const rtt::world::World *world, std::vector<CollisionData> &collisionDatas, const std::vector<Vector2> &pathPoints, double timeStep,
size_t completedTimeSteps);

/**
* @brief Takes a path from the array of stored paths and checks points along the path if they are too close to
Expand All @@ -121,10 +126,10 @@ class WorldObjects {
* @param computedPaths The paths of our own robots
* @param robotId ID of the robot
* @param timeStep Time between pathpoints
* @param timeStepsDone how many seconds of the trajectory is already completed by the robot
* @param completedTimeSteps how many seconds of the trajectory is already completed by the robot
*/
void calculateOurRobotCollisions(const rtt::world::World *world, std::vector<CollisionData> &collisionDatas, const std::vector<Vector2> &pathPoints,
const std::unordered_map<int, std::vector<Vector2>> &computedPaths, int robotId, double timeStep, size_t timeStepsDone);
const std::unordered_map<int, std::vector<Vector2>> &computedPaths, int robotId, double timeStep, size_t completedTimeSteps);

/**
* @brief Inserts collisionData in the vector collisionDatas such that they are ordered from lowest collisionTime to highest
Expand Down
5 changes: 2 additions & 3 deletions roboteam_ai/include/roboteam_ai/stp/Play.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ class Play {
*/
virtual bool shouldEndPlay() noexcept;

std::optional<gen::PlayInfos> previousPlayInfos; /**< Map that holds info from the previous play */

private:
/**
* @brief This function refreshes the RobotViews, BallViews, and Fields for all StpInfo's. This also sets the maxRobotVelocity.
Expand All @@ -160,7 +158,8 @@ class Play {

size_t previousRobotNum{}; /**< The previous amount of robots. This is used to check if we need to re-deal (if a robot disappears for example) */

int previousKeeperId = -1; /**< The previous keeperId. This is used to check if we need to re-deal (if keeper id was changed from UI or GameController) */
int previousKeeperId = -1; /**< The previous keeperId. This is used to check if we need to re-deal (if keeper id was changed from UI or GameController) */
int previousMaxRobots = -1; /**< The previous maxRobots. This is used to check if we need to re-deal */
};
} // namespace rtt::ai::stp

Expand Down
14 changes: 1 addition & 13 deletions roboteam_ai/include/roboteam_ai/stp/PlayEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,15 @@ enum class GlobalEvaluation {
PenaltyUsGameState,
PenaltyUsPrepareGameState,
StopGameState,
PreHalfGameState,
/// Global Evaluations
BallCloseToThem,
BallCloseToUs,
BallClosestToUs,
BallGotShot,
BallIsFree,
BallMovesSlow,
BallOnOurSide,
BallOnTheirSide,
BallInOurDefenseAreaAndStill,
BallNotInOurDefenseAreaAndStill,
DistanceFromBall,
FreedomOfRobots,
GoalVisionFromBall,
GoalVision,
NoGoalVisionFromBall,
WeHaveBall,
WeDoNotHaveBall,
TheyHaveBall,
TheyDoNotHaveBall,
WeHaveMajority
};

/**
Expand Down
8 changes: 8 additions & 0 deletions roboteam_ai/include/roboteam_ai/stp/StpInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ struct StpInfo {
const std::optional<Vector2>& getPositionToDefend() const { return positionToDefend; }
void setPositionToDefend(const std::optional<Vector2>& position) { this->positionToDefend = position; }

const Vector2& getTargetLocationSpeed() const { return targetLocationSpeed; }
void setTargetLocationSpeed(const Vector2& speed) { this->targetLocationSpeed = speed; }

double getKickChipVelocity() const { return kickChipVelocity; }
void setKickChipVelocity(double kickChipVelocity) { this->kickChipVelocity = kickChipVelocity; }

Expand Down Expand Up @@ -132,6 +135,11 @@ struct StpInfo {
*/
std::optional<Vector2> positionToDefend;

/**
* Speed of the target location (e.g. speed of the robot or speed of the ball)
*/
Vector2 targetLocationSpeed = Vector2(0, 0);

/**
* Velocity of the kick/chip
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ComputationManager {

inline static std::unordered_map<Vector2, gen::PositionScores> calculatedScores{}; /**< vector of calculated position scores */
inline static std::vector<Vector2> calculatedWallPositions{}; /**< vector of determined wall positions */
inline static std::vector<int> calculatedEnemyMapIds{}; /**< vector of enemyMap id */
};
} // namespace rtt::ai::stp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ class PassComputations {
*/
static PassInfo calculatePass(gen::ScoreProfile profile, const world::World* world, const Field& field, bool keeperCanPass = false);

/**
* @brief Scores a given pass based on how likely it is to score from the passLocation, adjusted for the riskiness of the pass
* @param passInfo The passInfo of the pass to be scored
* @param world pointer to world
* @param field the current field
* @return the score of the pass (0 - 255)
*/
static uint8_t scorePass(PassInfo passInfo, const world::World* world, const rtt::Field& field);

private:
/**
* @brief Gets the grid of points containing all possible pass locations
Expand Down
Loading

0 comments on commit 57a6ceb

Please sign in to comment.