diff --git a/src/main/java/nl/roboteamtwente/autoref/Referee.java b/src/main/java/nl/roboteamtwente/autoref/Referee.java index 63b26b8..2c09fe7 100644 --- a/src/main/java/nl/roboteamtwente/autoref/Referee.java +++ b/src/main/java/nl/roboteamtwente/autoref/Referee.java @@ -8,6 +8,7 @@ public class Referee { private static final List RULE_VALIDATORS = List.of( + new PossibleGoalValidator(), //First validator to give priority on checking this rule new AimlessKickValidator(), new AttackerDoubleTouchedBallValidator(), new AttackerTooCloseToDefenseAreaValidator(), @@ -23,8 +24,7 @@ public class Referee { new DefenderInDefenseAreaValidator(), new DefenderTooCloseToKickPointValidator(), new PenaltyKickFailedValidator(), - new PlacementSucceededValidator(), - new PossibleGoalValidator() + new PlacementSucceededValidator() ); private List activeValidators = new ArrayList<>(); diff --git a/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java b/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java index ba6ba99..ecab67c 100644 --- a/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java +++ b/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java @@ -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); } } @@ -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; } } diff --git a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java index 1b650c6..6ecdde3 100644 --- a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java +++ b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java @@ -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; }