Skip to content

Commit

Permalink
Merge pull request #22 from RoboTeamTwente/fix/possible_goal
Browse files Browse the repository at this point in the history
Fix/possible goal
  • Loading branch information
JWillegers authored Jul 1, 2024
2 parents 5fea9e9 + 9d8dfc0 commit d6ebae0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/nl/roboteamtwente/autoref/Referee.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class Referee {
private static final List<RuleValidator> RULE_VALIDATORS = List.of(
new PossibleGoalValidator(), //First validator to give priority on checking this rule
new AimlessKickValidator(),
new AttackerDoubleTouchedBallValidator(),
new AttackerTooCloseToDefenseAreaValidator(),
Expand All @@ -23,8 +24,7 @@ public class Referee {
new DefenderInDefenseAreaValidator(),
new DefenderTooCloseToKickPointValidator(),
new PenaltyKickFailedValidator(),
new PlacementSucceededValidator(),
new PossibleGoalValidator()
new PlacementSucceededValidator()
);

private List<RuleValidator> activeValidators = new ArrayList<>();
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public void processWorldState(StateOuterClass.State statePacket) {
referee.setGame(game);
time_counter += 1;
if (time_counter % 80 == 0) {
System.out.println("AUTOREF ALIVE");
String message = "AUTOREF ALIVE | ";
if (game.isBallInPlay()) {
message += "Ball in play";
} else {
message += game.getState();
}

System.out.println(message);
}
}

Expand Down Expand Up @@ -291,7 +298,8 @@ private void deriveTouch(Game game) {
Touch touch_ = ball_.getLastTouchStarted();
Robot robot_ = game.getRobot(touch_.getBy());
//if distance between robot and ball is greater than 15m/s * 60Hz + robot radius there is a false positive
if (ball_.getPosition().xy().distance(robot_.getPosition().xy()) > (15 * 1/60 + robot_.getRadius())) {
float f = (15.0f / 60.0f + robot_.getRadius());
if (ball_.getPosition().xy().distance(robot_.getPosition().xy()) > (15.0f / 60.0f + robot_.getRadius())) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,19 @@ boolean checkBallInsideGoal(Game game, Side side, Vector2 ballPos) {

String fieldLineName;
if (side.equals(Side.RIGHT)) {
fieldLineName = "RightFieldLeftPenaltyStretch";
fieldLineName = "RightGoalLine";
} else {
fieldLineName = "LeftFieldLeftPenaltyStretch";
fieldLineName = "LeftGoalLine";
}
FieldLine fieldLine = game.getField().getLineByName(fieldLineName);
if (fieldLine != null) {
// LeftToRightCoefficient if leftPenaltyStretch is positive otherwise negative
float leftToRightCoefficient = 1;
if (fieldLine.p1().getY() >= 0) {
leftToRightCoefficient = 1;
} else {
leftToRightCoefficient = -1;
}
float leftPostP1x = fieldLine.p1().getX();
float leftPostP1y = (goalWidthLength/2) * leftToRightCoefficient;

float leftPostP2x = leftPostP1x + side.getCardinality()*goalDepthLength;

float rightPostP1y = (goalWidthLength/2) * leftToRightCoefficient * -1;

// Check if ball inside right goal
if ((ballPos.getY() >= Math.min(rightPostP1y, leftPostP1y)) && (ballPos.getY() <= Math.max(rightPostP1y, leftPostP1y))
&& (ballPos.getX() >= Math.min(leftPostP1x,leftPostP2x)) && (ballPos.getX() <= Math.max(leftPostP1x,leftPostP2x))) {
float fieldLineX = side.getCardinality() * fieldLine.p1().getX();
float goalBacksideX = fieldLineX + goalDepthLength;
float goalY = goalWidthLength / 2;
float ballX = side.getCardinality() * ballPos.getX();
float ballY = ballPos.getY();

if (fieldLineX < ballX && ballX < goalBacksideX && -1 * goalY < ballY && ballY < goalY) {
System.out.println("Inside goal " + side);
return true;
}
Expand Down

0 comments on commit d6ebae0

Please sign in to comment.