Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/possible goal #22

Merged
merged 6 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading