From 2df1ef2970d1d9d39a204c76835d8207be643726 Mon Sep 17 00:00:00 2001 From: Jonathan <148167.jw@gmail.com> Date: Mon, 18 Mar 2024 17:07:12 +0100 Subject: [PATCH] Getting robot radius from SSL-vision --- .../java/nl/roboteamtwente/autoref/SSLAutoRef.java | 12 +++++++++--- .../java/nl/roboteamtwente/autoref/model/Robot.java | 8 ++++++-- .../AttackerTooCloseToDefenseAreaValidator.java | 4 ++-- .../DefenderTooCloseToKickPointValidator.java | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java b/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java index 6a9a678..b74176e 100644 --- a/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java +++ b/src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java @@ -54,11 +54,11 @@ public void processWorldState(StateOuterClass.State statePacket) { deriveRefereeMessage(game, statePacket); deriveBall(game, world); for (WorldRobotOuterClass.WorldRobot robot : world.getBlueList()) { - deriveRobot(game, TeamColor.BLUE, robot); + deriveRobot(game, TeamColor.BLUE, robot, statePacket); } for (WorldRobotOuterClass.WorldRobot robot : world.getYellowList()) { - deriveRobot(game, TeamColor.YELLOW, robot); + deriveRobot(game, TeamColor.YELLOW, robot, statePacket); } deriveTeamData(game, statePacket); deriveField(game, statePacket); @@ -194,7 +194,7 @@ private void deriveBall(Game game, WorldOuterClass.World world) { * @param teamColor team color * @param worldRobot robot */ - private void deriveRobot(Game game, TeamColor teamColor, WorldRobotOuterClass.WorldRobot worldRobot) { + private void deriveRobot(Game game, TeamColor teamColor, WorldRobotOuterClass.WorldRobot worldRobot, StateOuterClass.State statePacket) { Robot robot = game.getTeam(teamColor).getRobotById(worldRobot.getId()); if (robot == null) { robot = new Robot(worldRobot.getId()); @@ -206,6 +206,12 @@ private void deriveRobot(Game game, TeamColor teamColor, WorldRobotOuterClass.Wo robot.getPosition().setY(worldRobot.getPos().getY()); robot.getVelocity().setX(worldRobot.getVel().getX()); robot.getVelocity().setY(worldRobot.getVel().getY()); + if (teamColor == TeamColor.BLUE) { + robot.setRadius(statePacket.getBlueRobotParameters().getParameters().getRadius()); + System.out.println(robot.getRadius()); + } else { + robot.setRadius(statePacket.getYellowRobotParameters().getParameters().getRadius()); + } robot.setAngle(worldRobot.getAngle()); } diff --git a/src/main/java/nl/roboteamtwente/autoref/model/Robot.java b/src/main/java/nl/roboteamtwente/autoref/model/Robot.java index 61f9e47..2f6b288 100644 --- a/src/main/java/nl/roboteamtwente/autoref/model/Robot.java +++ b/src/main/java/nl/roboteamtwente/autoref/model/Robot.java @@ -14,7 +14,7 @@ public class Robot extends Entity { /** * Maximum radius of the robot in meters */ - private final double radius = 0.09; + private float radius; /** * A robot has an angle that it is facing during any point of the game. @@ -128,11 +128,15 @@ public RobotIdentifier getIdentifier() { return new RobotIdentifier(team.getColor(), id); } + public void setRadius(float r) { + this.radius = r; + } + /** * * @return radius of robot */ - public double getRadius() { + public float getRadius() { return radius; } diff --git a/src/main/java/nl/roboteamtwente/autoref/validators/AttackerTooCloseToDefenseAreaValidator.java b/src/main/java/nl/roboteamtwente/autoref/validators/AttackerTooCloseToDefenseAreaValidator.java index 65dadbb..bccc364 100644 --- a/src/main/java/nl/roboteamtwente/autoref/validators/AttackerTooCloseToDefenseAreaValidator.java +++ b/src/main/java/nl/roboteamtwente/autoref/validators/AttackerTooCloseToDefenseAreaValidator.java @@ -86,10 +86,10 @@ public RuleViolation validate(Game game) { if (abs(robotY) - robot.getRadius() < abs(lineY)) { // Robot is in front of the line - distance = lineX - (robotX + (float) robot.getRadius()); + distance = lineX - (robotX + robot.getRadius()); } else if (robotX > lineX) { // Robot is above or below the defender area, within 0.2m - distance = abs(robotY) - (float) robot.getRadius() - abs(lineY); + distance = abs(robotY) - robot.getRadius() - abs(lineY); } // Check if robot is within one of the corners and calculate distance to the corner diff --git a/src/main/java/nl/roboteamtwente/autoref/validators/DefenderTooCloseToKickPointValidator.java b/src/main/java/nl/roboteamtwente/autoref/validators/DefenderTooCloseToKickPointValidator.java index 05a00d9..4c6473d 100644 --- a/src/main/java/nl/roboteamtwente/autoref/validators/DefenderTooCloseToKickPointValidator.java +++ b/src/main/java/nl/roboteamtwente/autoref/validators/DefenderTooCloseToKickPointValidator.java @@ -42,7 +42,7 @@ public RuleViolation validate(Game game) { Vector2 robotPos = robot.getPosition().xy(); // Calculate distance to ball - float distanceToBall = ball.distance(robotPos) - (float) robot.getRadius(); + float distanceToBall = ball.distance(robotPos) - robot.getRadius(); // If robot is within 0.5m of the ball, it is too close if (distanceToBall < 0.5) {