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;
......@@ -16,8 +16,8 @@ import lombok.Getter;
@Getter
public enum EAiTeam
{
BLUE(ETeamColor.BLUE),
YELLOW(ETeamColor.YELLOW),
BLUE(ETeamColor.BLUE),
;
......
......@@ -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")
private static double violationTime = 2.0;
private final List<Violator> violators = new ArrayList<>();
public BallPlacementInterferenceDetector()
{
super(EGameEventDetectorType.BALL_PLACEMENT_INTERFERENCE, EGameState.BALL_PLACEMENT);
}
@Override
public void doReset()
{
violators.clear();
}
@Override
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();
violators.removeIf(b -> !violatingBots.contains(b.getBotId()));
violatingBots.stream().filter(this::isNewViolator)
.forEach(botID -> violators.add(new Violator(botID, frame.getTimestamp())));
return violators.stream()
.filter(this::keepsViolating)
.filter(Violator::isUnpunished)
.findAny()
.map(this::createEvent);
}
private boolean isNewViolator(BotID id)
{
return violators.stream().noneMatch(e -> e.getBotId() == id);
}
private Set<BotID> violatingBots()
{
IVector2 ballPos = frame.getWorldFrame().getBall().getPos();
......@@ -90,16 +97,16 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector
.map(ITrackedBot::getBotId)
.collect(Collectors.toSet());
}
private IGameEvent createEvent(Violator violator)
{
violator.punish();
return new BotInterferedPlacement(violator.getBotId(),
frame.getWorldFrame().getBot(violator.getBotId()).getPos());
}
private boolean keepsViolating(Violator violator)
{
return (frame.getTimestamp() - violator.getStartTimestamp()) / 1e9 > violationTime;
......@@ -125,26 +132,26 @@ public class BallPlacementInterferenceDetector extends AGameEventDetector
this.startTimestamp = startTimestamp;
this.punished = PunishedStatus.UNPUNISHED;
}
public BotID getBotId()
{
return botId;
}
public long getStartTimestamp()
{
return startTimestamp;
}
public boolean isUnpunished()
{
return punished == PunishedStatus.UNPUNISHED;
}
public void punish()
{
this.punished = PunishedStatus.PUNISHED;
......
......@@ -60,7 +60,7 @@ public class BallSpeedingDetector extends AGameEventDetector
BallKickFitState lastKickFitState = frame.getPreviousFrame().getWorldFrame().getKickFitState().get();
double kickSpeed = lastKickFitState.getKickVel().getLength() / 1000.;
if (isKickTooFast(kickSpeed)
&& kickEstimateIsReady(currentKickEvent))
&& kickEstimateIsReady(currentKickEvent, lastKickFitState))
{
lastReportedKickEvent = currentKickEvent;
IGameEvent violation;
......@@ -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 kickFitEstimateAge = (frame.getTimestamp() - lastKickFitState.getKickTimestamp()) / 1e9;
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
......
/*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.sumatra.referee.source;
......@@ -49,7 +49,9 @@ public class NetworkRefereeReceiver extends ARefereeMessageSource implements Run
}
/** Constructor */
/**
* Constructor
*/
public NetworkRefereeReceiver()
{
super(ERefereeMessageSource.NETWORK);
......@@ -96,19 +98,21 @@ public class NetworkRefereeReceiver extends ARefereeMessageSource implements Run
break;
}
refBoxAddress = packet.getAddress();
final ByteArrayInputStream packetIn = new ByteArrayInputStream(packet.getData(), 0, packet.getLength());
SslGcRefereeMessage.Referee sslRefereeMsg;
try
if (packet.getLength() > 0)
{
sslRefereeMsg = SslGcRefereeMessage.Referee.parseFrom(packetIn);
refBoxAddress = packet.getAddress();
// Notify the receipt of a new RefereeMessage to any other observers
notifyNewRefereeMessage(sslRefereeMsg);
} catch (IOException err)
{
log.error("Could not read referee message ", err);
try
{
var packetIn = new ByteArrayInputStream(packet.getData(), 0, packet.getLength());
var sslRefereeMsg = SslGcRefereeMessage.Referee.parseFrom(packetIn);
// 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
static
{
ConfigRegistration.registerClass("wp", WorldInfoCollector.class);
String env = SumatraModel.getInstance().getEnvironment();
ConfigRegistration.applySpezi("wp", env);
ConfigRegistration.registerConfigurableCallback("wp", new IConfigObserver()
{
@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