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/bot crash #21

Merged
merged 3 commits into from
Jun 28, 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
5 changes: 5 additions & 0 deletions src/main/java/nl/roboteamtwente/autoref/SSLAutoRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class SSLAutoRef {

private int commands = 0;
private int nextTouchId = 0;
private long time_counter = 0;

public SSLAutoRef() {
this.referee = new Referee();
Expand Down Expand Up @@ -67,6 +68,10 @@ public void processWorldState(StateOuterClass.State statePacket) {
gameStateChanges(game);

referee.setGame(game);
time_counter += 1;
if (time_counter % 80 == 0) {
System.out.println("AUTOREF ALIVE");
}
}

/**
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/nl/roboteamtwente/autoref/WorldConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ public void connect() {
* Receive and process messages
*/
public void listener() {
try {
while (!Thread.currentThread().isInterrupted() && worldSocket != null) {
while (!Thread.currentThread().isInterrupted() && worldSocket != null) {
try {
byte[] buffer = worldSocket.recv();
StateOuterClass.State packet = StateOuterClass.State.parseFrom(buffer);
ref.checkViolations(packet);
}
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
} catch (ZMQException e) {
//4 is the error code when we close the connection by hand, which can be ignored
if (e.getErrorCode() != 4) {

} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
} catch (ZMQException e) {
//4 is the error code when we close the connection by hand, which can be ignored
if (e.getErrorCode() != 4) {
e.printStackTrace();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class BotCrashingValidator implements RuleValidator {

private static final float BOT_CRASH_DISTANCE = 0.2f;
private static final float BOT_CRASH_DISTANCE = 0.005f;
private static final float SPEED_VECTOR_THRESHOLD = 1.5f;
private static final float MIN_SPEED_DIFFERENCE = 0.3f;
private static final double GRACE_PERIOD = 2.0;
Expand Down Expand Up @@ -111,7 +111,7 @@ public RuleViolation validate(Game game) {
Vector2 robotBlueVel = robotBlue.getVelocity().xy();
float distanceBetweenRobots = robotYellowPos.distance(robotBluePos);

if (distanceBetweenRobots <= BOT_CRASH_DISTANCE) {
if (distanceBetweenRobots <= robotYellow.getRadius() + robotBlue.getRadius() + BOT_CRASH_DISTANCE) {
// projection length of difference between speed vector
float crashSpeed = calculateCollisionVelocity(robotBluePos, robotBlueVel, robotYellowPos, robotYellowVel);

Expand Down
Loading