Commit 522a3dfe authored by MarkG's avatar MarkG Committed by TIGERs GitLab
Browse files

Resolve "Fine-tune ER-Force simulator integration"

Closes #1630

See merge request main/Sumatra!1371

sumatra-commit: 88a755f54e7c9b09bac732631e8ef68cff1392d8
parent 1af5f483
Pipeline #16621 passed with stage
in 5 minutes and 31 seconds
/* /*
* Copyright (c) 2009 - 2018, DHBW Mannheim - TIGERs Mannheim * Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/ */
package edu.tigers.sumatra.ids; package edu.tigers.sumatra.ids;
...@@ -16,8 +16,8 @@ import lombok.Getter; ...@@ -16,8 +16,8 @@ import lombok.Getter;
@Getter @Getter
public enum EAiTeam public enum EAiTeam
{ {
BLUE(ETeamColor.BLUE),
YELLOW(ETeamColor.YELLOW), YELLOW(ETeamColor.YELLOW),
BLUE(ETeamColor.BLUE),
; ;
......
...@@ -35,45 +35,52 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector ...@@ -35,45 +35,52 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector
{ {
@Configurable(defValue = "2.0", comment = "The time [s] that a robot is allowed to stay within the forbidden area") @Configurable(defValue = "2.0", comment = "The time [s] that a robot is allowed to stay within the forbidden area")
private static double violationTime = 2.0; private static double violationTime = 2.0;
private final List<Violator> violators = new ArrayList<>(); private final List<Violator> violators = new ArrayList<>();
public BallPlacementInterferenceDetector() public BallPlacementInterferenceDetector()
{ {
super(EGameEventDetectorType.BALL_PLACEMENT_INTERFERENCE, EGameState.BALL_PLACEMENT); super(EGameEventDetectorType.BALL_PLACEMENT_INTERFERENCE, EGameState.BALL_PLACEMENT);
} }
@Override @Override
public void doReset() public void doReset()
{ {
violators.clear(); violators.clear();
} }
@Override @Override
protected Optional<IGameEvent> doUpdate() protected Optional<IGameEvent> doUpdate()
{ {
if (!frame.getWorldFrame().getBall().isOnCam(0.2))
{
// Can not see the ball
violators.clear();
return Optional.empty();
}
Set<BotID> violatingBots = violatingBots(); Set<BotID> violatingBots = violatingBots();
violators.removeIf(b -> !violatingBots.contains(b.getBotId())); violators.removeIf(b -> !violatingBots.contains(b.getBotId()));
violatingBots.stream().filter(this::isNewViolator) violatingBots.stream().filter(this::isNewViolator)
.forEach(botID -> violators.add(new Violator(botID, frame.getTimestamp()))); .forEach(botID -> violators.add(new Violator(botID, frame.getTimestamp())));
return violators.stream() return violators.stream()
.filter(this::keepsViolating) .filter(this::keepsViolating)
.filter(Violator::isUnpunished) .filter(Violator::isUnpunished)
.findAny() .findAny()
.map(this::createEvent); .map(this::createEvent);
} }
private boolean isNewViolator(BotID id) private boolean isNewViolator(BotID id)
{ {
return violators.stream().noneMatch(e -> e.getBotId() == id); return violators.stream().noneMatch(e -> e.getBotId() == id);
} }
private Set<BotID> violatingBots() private Set<BotID> violatingBots()
{ {
IVector2 ballPos = frame.getWorldFrame().getBall().getPos(); IVector2 ballPos = frame.getWorldFrame().getBall().getPos();
...@@ -90,16 +97,16 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector ...@@ -90,16 +97,16 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector
.map(ITrackedBot::getBotId) .map(ITrackedBot::getBotId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
private IGameEvent createEvent(Violator violator) private IGameEvent createEvent(Violator violator)
{ {
violator.punish(); violator.punish();
return new BotInterferedPlacement(violator.getBotId(), return new BotInterferedPlacement(violator.getBotId(),
frame.getWorldFrame().getBot(violator.getBotId()).getPos()); frame.getWorldFrame().getBot(violator.getBotId()).getPos());
} }
private boolean keepsViolating(Violator violator) private boolean keepsViolating(Violator violator)
{ {
return (frame.getTimestamp() - violator.getStartTimestamp()) / 1e9 > violationTime; return (frame.getTimestamp() - violator.getStartTimestamp()) / 1e9 > violationTime;
...@@ -125,26 +132,26 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector ...@@ -125,26 +132,26 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector
this.startTimestamp = startTimestamp; this.startTimestamp = startTimestamp;
this.punished = PunishedStatus.UNPUNISHED; this.punished = PunishedStatus.UNPUNISHED;
} }
public BotID getBotId() public BotID getBotId()
{ {
return botId; return botId;
} }
public long getStartTimestamp() public long getStartTimestamp()
{ {
return startTimestamp; return startTimestamp;
} }
public boolean isUnpunished() public boolean isUnpunished()
{ {
return punished == PunishedStatus.UNPUNISHED; return punished == PunishedStatus.UNPUNISHED;
} }
public void punish() public void punish()
{ {
this.punished = PunishedStatus.PUNISHED; this.punished = PunishedStatus.PUNISHED;
......
...@@ -60,7 +60,7 @@ public class BallSpeedingDetector extends AGameEventDetector ...@@ -60,7 +60,7 @@ public class BallSpeedingDetector extends AGameEventDetector
BallKickFitState lastKickFitState = frame.getPreviousFrame().getWorldFrame().getKickFitState().get(); BallKickFitState lastKickFitState = frame.getPreviousFrame().getWorldFrame().getKickFitState().get();
double kickSpeed = lastKickFitState.getKickVel().getLength() / 1000.; double kickSpeed = lastKickFitState.getKickVel().getLength() / 1000.;
if (isKickTooFast(kickSpeed) if (isKickTooFast(kickSpeed)
&& kickEstimateIsReady(currentKickEvent)) && kickEstimateIsReady(currentKickEvent, lastKickFitState))
{ {
lastReportedKickEvent = currentKickEvent; lastReportedKickEvent = currentKickEvent;
IGameEvent violation; IGameEvent violation;
...@@ -94,11 +94,12 @@ public class BallSpeedingDetector extends AGameEventDetector ...@@ -94,11 +94,12 @@ public class BallSpeedingDetector extends AGameEventDetector
} }
private boolean kickEstimateIsReady(final IKickEvent currentKickEvent) private boolean kickEstimateIsReady(final IKickEvent currentKickEvent, BallKickFitState lastKickFitState)
{ {
double kickEstimateAge = (frame.getTimestamp() - currentKickEvent.getTimestamp()) / 1e9; double kickEstimateAge = (frame.getTimestamp() - currentKickEvent.getTimestamp()) / 1e9;
double kickFitEstimateAge = (frame.getTimestamp() - lastKickFitState.getKickTimestamp()) / 1e9;
boolean kickEstimateIsReady = kickEstimateAge > maxWaitingTime; boolean kickEstimateIsReady = kickEstimateAge > maxWaitingTime;
boolean kickEstimateAged = kickEstimateAge > minWaitingTime; boolean kickEstimateAged = kickFitEstimateAge > minWaitingTime;
// either time is up, or ball has left the field, or ball touched another bot // either time is up, or ball has left the field, or ball touched another bot
......
/* /*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim * Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/ */
package edu.tigers.sumatra.referee.source; package edu.tigers.sumatra.referee.source;
...@@ -49,7 +49,9 @@ public class NetworkRefereeReceiver extends ARefereeMessageSource implements Run ...@@ -49,7 +49,9 @@ public class NetworkRefereeReceiver extends ARefereeMessageSource implements Run
} }
/** Constructor */ /**
* Constructor
*/
public NetworkRefereeReceiver() public NetworkRefereeReceiver()
{ {
super(ERefereeMessageSource.NETWORK); super(ERefereeMessageSource.NETWORK);
...@@ -96,19 +98,21 @@ public class NetworkRefereeReceiver extends ARefereeMessageSource implements Run ...@@ -96,19 +98,21 @@ public class NetworkRefereeReceiver extends ARefereeMessageSource implements Run
break; break;
} }
refBoxAddress = packet.getAddress(); if (packet.getLength() > 0)
final ByteArrayInputStream packetIn = new ByteArrayInputStream(packet.getData(), 0, packet.getLength());
SslGcRefereeMessage.Referee sslRefereeMsg;
try
{ {
sslRefereeMsg = SslGcRefereeMessage.Referee.parseFrom(packetIn); refBoxAddress = packet.getAddress();
// Notify the receipt of a new RefereeMessage to any other observers try
notifyNewRefereeMessage(sslRefereeMsg); {
} catch (IOException err) var packetIn = new ByteArrayInputStream(packet.getData(), 0, packet.getLength());
{ var sslRefereeMsg = SslGcRefereeMessage.Referee.parseFrom(packetIn);
log.error("Could not read referee message ", err);
// Notify the receipt of a new RefereeMessage to any other observers
notifyNewRefereeMessage(sslRefereeMsg);
} catch (IOException err)
{
log.error("Could not read referee message", err);
}
} }
} }
......
...@@ -123,6 +123,8 @@ public class WorldInfoCollector extends AWorldPredictor ...@@ -123,6 +123,8 @@ public class WorldInfoCollector extends AWorldPredictor
static static
{ {
ConfigRegistration.registerClass("wp", WorldInfoCollector.class); ConfigRegistration.registerClass("wp", WorldInfoCollector.class);
String env = SumatraModel.getInstance().getEnvironment();
ConfigRegistration.applySpezi("wp", env);
ConfigRegistration.registerConfigurableCallback("wp", new IConfigObserver() ConfigRegistration.registerConfigurableCallback("wp", new IConfigObserver()
{ {
@Override @Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment