From 72d5251e9638181a5dddec98d2cb5b882ebf2bbc Mon Sep 17 00:00:00 2001 From: DemoLaptop Date: Mon, 1 Jul 2024 13:46:28 +0200 Subject: [PATCH 1/6] integer division doesnt work if you want to get a float result --- .../java/nl/roboteamtwente/autoref/SSLAutoRef.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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; } } From 15080b34dea08855863667b16406aa16ff1bf4e0 Mon Sep 17 00:00:00 2001 From: DemoLaptop Date: Mon, 1 Jul 2024 13:48:00 +0200 Subject: [PATCH 2/6] simplyfing goal checking code --- .../validators/PossibleGoalValidator.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java index 1b650c6..d0efd8c 100644 --- a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java +++ b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java @@ -26,29 +26,21 @@ 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 = goalDepthLength / 2; + float ballX = side.getCardinality() * ballPos.getX(); + float ballY = ballPos.getY(); + + System.out.println(fieldLineX + ", " + goalBacksideX + ", " + goalY + ", " + ballX + ", " + ballY); + + if (fieldLineX < ballX && ballX < goalBacksideX && goalY < ballY && ballY < -1 * goalY) { System.out.println("Inside goal " + side); return true; } From ef4e66383c27d3942fe964b77319fe9f18c8ae47 Mon Sep 17 00:00:00 2001 From: DemoLaptop Date: Mon, 1 Jul 2024 13:58:37 +0200 Subject: [PATCH 3/6] fixing goal width --- .../autoref/validators/PossibleGoalValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java index d0efd8c..343d433 100644 --- a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java +++ b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java @@ -34,7 +34,7 @@ boolean checkBallInsideGoal(Game game, Side side, Vector2 ballPos) { if (fieldLine != null) { float fieldLineX = side.getCardinality() * fieldLine.p1().getX(); float goalBacksideX = fieldLineX + goalDepthLength; - float goalY = goalDepthLength / 2; + float goalY = goalWidthLength / 2; float ballX = side.getCardinality() * ballPos.getX(); float ballY = ballPos.getY(); From 65dc5b2a48a2c037e9ddf8ea57cc9b8690bffd34 Mon Sep 17 00:00:00 2001 From: DemoLaptop Date: Mon, 1 Jul 2024 14:08:24 +0200 Subject: [PATCH 4/6] fixing y check of goal --- .../autoref/validators/PossibleGoalValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java index 343d433..b0cef9a 100644 --- a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java +++ b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java @@ -40,7 +40,7 @@ boolean checkBallInsideGoal(Game game, Side side, Vector2 ballPos) { System.out.println(fieldLineX + ", " + goalBacksideX + ", " + goalY + ", " + ballX + ", " + ballY); - if (fieldLineX < ballX && ballX < goalBacksideX && goalY < ballY && ballY < -1 * goalY) { + if (fieldLineX < ballX && ballX < goalBacksideX && -1 * goalY < ballY && ballY < goalY) { System.out.println("Inside goal " + side); return true; } From eb61efa0232fa0612959056d0f04e0f9af92e426 Mon Sep 17 00:00:00 2001 From: DemoLaptop Date: Mon, 1 Jul 2024 14:24:06 +0200 Subject: [PATCH 5/6] removing print statement --- .../autoref/validators/PossibleGoalValidator.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java index b0cef9a..6ecdde3 100644 --- a/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java +++ b/src/main/java/nl/roboteamtwente/autoref/validators/PossibleGoalValidator.java @@ -37,8 +37,6 @@ boolean checkBallInsideGoal(Game game, Side side, Vector2 ballPos) { float goalY = goalWidthLength / 2; float ballX = side.getCardinality() * ballPos.getX(); float ballY = ballPos.getY(); - - System.out.println(fieldLineX + ", " + goalBacksideX + ", " + goalY + ", " + ballX + ", " + ballY); if (fieldLineX < ballX && ballX < goalBacksideX && -1 * goalY < ballY && ballY < goalY) { System.out.println("Inside goal " + side); From 9d8dfc042490d5b18d33fdd20889f9ebdd72a4f9 Mon Sep 17 00:00:00 2001 From: DemoLaptop Date: Mon, 1 Jul 2024 14:25:37 +0200 Subject: [PATCH 6/6] possble goal priority --- src/main/java/nl/roboteamtwente/autoref/Referee.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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<>();