Skip to content

Commit

Permalink
Merge pull request #21 from RoboTeamTwente/fix/bot-crash
Browse files Browse the repository at this point in the history
Fix/bot crash
  • Loading branch information
JWillegers authored Jun 28, 2024
2 parents 4152b08 + 4fe0cd0 commit 5fea9e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
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

0 comments on commit 5fea9e9

Please sign in to comment.