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

Resolve "Goal detection during penalty kick does not work"

Closes #1689

See merge request main/Sumatra!1454

sumatra-commit: c2fcc89547446cbb7adfaa4e649a1d0e15d99927
parent ca628d2f
Pipeline #17109 passed with stage
in 4 minutes and 13 seconds
/*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.autoreferee.engine.detector;
import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import edu.tigers.sumatra.geometry.Geometry;
import edu.tigers.sumatra.ids.AObjectID;
import edu.tigers.sumatra.ids.BotID;
......@@ -22,6 +15,13 @@ import edu.tigers.sumatra.referee.gameevent.PossibleGoal;
import edu.tigers.sumatra.vision.data.IKickEvent;
import edu.tigers.sumatra.wp.data.BallLeftFieldPosition;
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;
import java.util.Optional;
import java.util.Set;
/**
......@@ -37,7 +37,7 @@ public class GoalDetector extends AGameEventDetector
public GoalDetector()
{
super(EGameEventDetectorType.GOAL, EGameState.RUNNING);
super(EGameEventDetectorType.GOAL, Set.of(EGameState.RUNNING, EGameState.PENALTY));
lastTouchedMap.put(ETeamColor.BLUE, 0L);
lastTouchedMap.put(ETeamColor.YELLOW, 0L);
maxBallHeightMap.put(ETeamColor.BLUE, 0.0);
......@@ -94,7 +94,7 @@ public class GoalDetector extends AGameEventDetector
private void warnIfNoKickEventPresent()
{
if (!frame.getWorldFrame().getKickEvent().isPresent())
if (frame.getWorldFrame().getKickEvent().isEmpty())
{
log.warn("Goal detected, but no kick event found.");
}
......
/*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.autoreferee.engine.detector;
import edu.tigers.autoreferee.generic.BotPosition;
import edu.tigers.sumatra.ids.ETeamColor;
import edu.tigers.sumatra.math.AngleMath;
import edu.tigers.sumatra.math.vector.IVector2;
import edu.tigers.sumatra.referee.data.EGameState;
import edu.tigers.sumatra.referee.gameevent.IGameEvent;
......@@ -17,12 +18,10 @@ import java.util.Optional;
public class PenaltyKickFailedDetector extends AGameEventDetector
{
public PenaltyKickFailedDetector()
{
super(EGameEventDetectorType.PENALTY_KICK_FAILED, EGameState.PENALTY);
setDeactivateOnFirstGameEvent(true);
}
......@@ -30,12 +29,10 @@ public class PenaltyKickFailedDetector extends AGameEventDetector
public Optional<IGameEvent> doUpdate()
{
Optional<Double> angle = frame.getWorldFrame().getBall().getVel()
.angleTo(frame.getPreviousFrame().getWorldFrame().getBall().getVel());
.angleToAbs(frame.getPreviousFrame().getWorldFrame().getBall().getVel());
if (angle.isPresent() && Math.abs(angle.get()) >= Math.PI * 0.5)
if (frame.isBallInsideField() && angle.isPresent() && angle.get() >= AngleMath.DEG_090_IN_RAD)
{
boolean failed = false;
List<BotPosition> lastBots = frame.getBotsLastTouchedBall();
ETeamColor attackingTeam = frame.getGameState().getForTeam();
......@@ -45,16 +42,10 @@ public class PenaltyKickFailedDetector extends AGameEventDetector
{
if (bot.getBotID().getTeamColor() == defendingTeam)
{
failed = true;
break;
IVector2 pos = frame.getWorldFrame().getBall().getPos();
return Optional.of(new PenaltyKickFailed(attackingTeam, pos));
}
}
if (failed && frame.isBallInsideField())
{
IVector2 pos = frame.getWorldFrame().getBall().getPos();
return Optional.of(new PenaltyKickFailed(attackingTeam, pos));
}
}
return Optional.empty();
......
......@@ -42,5 +42,5 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.19.0'
runtimeOnly "com.github.TIGERs-Mannheim:ssl-game-controller-maven:2.12.7.0:${osClassifier}"
runtimeOnly "com.github.TIGERs-Mannheim:ssl-game-controller-maven:2.12.8.1:${osClassifier}"
}
Markdown is supported
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