Skip to content

Commit

Permalink
Getting robot radius from SSL-vision
Browse files Browse the repository at this point in the history
  • Loading branch information
JWillegers committed Mar 18, 2024
1 parent 8e83815 commit 2df1ef2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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());
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/nl/roboteamtwente/autoref/model/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2df1ef2

Please sign in to comment.