Skip to content

Commit

Permalink
Resolve "Vision filter does not provide kick event for goals"
Browse files Browse the repository at this point in the history
Closes #1859

See merge request main/Sumatra!1686

sumatra-commit: ae96aa18cacc7139aeb5570789924df8490a70e0
  • Loading branch information
mickmack1213 authored and TIGERs GitLab committed Jul 10, 2024
1 parent 1d8c114 commit 8ed9db2
Showing 1 changed file with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import edu.tigers.sumatra.wp.data.BallLeftFieldPosition;
import edu.tigers.sumatra.wp.data.KickedBall;
import edu.tigers.sumatra.wp.data.TimedPosition;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.EnumMap;
import java.util.Map;
Expand All @@ -29,11 +27,10 @@
*/
public class GoalDetector extends AGameEventDetector
{
private final Logger log = LogManager.getLogger(GoalDetector.class.getName());

private TimedPosition lastBallLeftFieldPos = null;
private final Map<ETeamColor, Long> lastTouchedMap = new EnumMap<>(ETeamColor.class);
private final Map<ETeamColor, Double> maxBallHeightMap = new EnumMap<>(ETeamColor.class);
private KickedBall lastKickedball;

public GoalDetector()
{
Expand All @@ -48,6 +45,7 @@ public GoalDetector()
@Override
protected Optional<IGameEvent> doUpdate()
{
lastKickedball = frame.getWorldFrame().getKickedBall().orElse(lastKickedball);
for (ETeamColor team : ETeamColor.yellowBlueValues())
{
if (frame.getBotsTouchingBall().stream().anyMatch(b -> b.getBotID().getTeamColor() == team))
Expand All @@ -70,6 +68,7 @@ protected Optional<IGameEvent> doUpdate()
protected void doReset()
{
lastBallLeftFieldPos = null;
lastKickedball = null;
}


Expand All @@ -82,25 +81,14 @@ private IGameEvent processBallLeftField(final BallLeftFieldPosition ballLeftFiel
return null;
}

final var kickEvent = frame.getWorldFrame().getKickedBall();
final IVector2 kickLocation = kickEvent.map(KickedBall::getPosition).orElse(null);
final BotID kickingBot = kickEvent.map(KickedBall::getKickingBot).filter(AObjectID::isBot).orElse(null);

warnIfNoKickEventPresent();
final IVector2 kickLocation = Optional.ofNullable(lastKickedball).map(KickedBall::getPosition).orElse(null);
final BotID kickingBot = Optional.ofNullable(lastKickedball).map(KickedBall::getKickingBot)
.filter(AObjectID::isBot).orElse(null);

return createEvent(ballLeftFieldPosition, kickLocation, kickingBot);
}


private void warnIfNoKickEventPresent()
{
if (frame.getWorldFrame().getKickedBall().isEmpty())
{
log.warn("Goal detected, but no kick event found.");
}
}


private ETeamColor goalForTeam(final BallLeftFieldPosition ballLeftFieldPosition)
{
if (ballLeftFieldPosition.getPosition().getPos().x() < 0)
Expand Down

0 comments on commit 8ed9db2

Please sign in to comment.