Skip to content

Commit f8e23dd

Browse files
committed
Check positions during penalty preparation
1 parent f840eca commit f8e23dd

File tree

6 files changed

+86
-5
lines changed

6 files changed

+86
-5
lines changed

config/ssl-game-controller.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ game:
5555
defense-area-depth: 1.2
5656
defense-area-width: 2.4
5757
penalty-kick-dist-to-goal: 8.0
58+
goal-width: 1.2
5859
placement-offset-touch-line: 0.2
5960
placement-offset-goal-line: 0.2
6061
placement-offset-goal-line-goal-kick: 1.0
@@ -65,6 +66,7 @@ game:
6566
defense-area-depth: 1.0
6667
defense-area-width: 2.0
6768
penalty-kick-dist-to-goal: 6.0
69+
goal-width: 1.0
6870
placement-offset-touch-line: 0.2
6971
placement-offset-goal-line: 0.2
7072
placement-offset-goal-line-goal-kick: 1.0

internal/app/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Geometry struct {
2626
DefenseAreaDepth float64 `yaml:"defense-area-depth"`
2727
DefenseAreaWidth float64 `yaml:"defense-area-width"`
2828
PenaltyKickDistToGoal float64 `yaml:"penalty-kick-dist-to-goal"`
29+
GoalWidth float64 `yaml:"goal-width"`
2930
PlacementOffsetTouchLine float64 `yaml:"placement-offset-touch-line"`
3031
PlacementOffsetGoalLine float64 `yaml:"placement-offset-goal-line"`
3132
PlacementOffsetGoalLineGoalKick float64 `yaml:"placement-offset-goal-line-goal-kick"`
@@ -196,6 +197,7 @@ func DefaultControllerConfig() (c Controller) {
196197
DefenseAreaDepth: 1.2,
197198
DefenseAreaWidth: 2.4,
198199
PenaltyKickDistToGoal: 8.0,
200+
GoalWidth: 1.2,
199201
PlacementOffsetTouchLine: 0.2,
200202
PlacementOffsetGoalLine: 0.2,
201203
PlacementOffsetGoalLineGoalKick: 1.0,
@@ -207,6 +209,7 @@ func DefaultControllerConfig() (c Controller) {
207209
DefenseAreaDepth: 1,
208210
DefenseAreaWidth: 2,
209211
PenaltyKickDistToGoal: 6.0,
212+
GoalWidth: 1.0,
210213
PlacementOffsetTouchLine: 0.2,
211214
PlacementOffsetGoalLine: 0.2,
212215
PlacementOffsetGoalLineGoalKick: 1.0,

internal/app/config/testdata/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ game:
5656
defense-area-depth: 1.2
5757
defense-area-width: 2.4
5858
penalty-kick-dist-to-goal: 8.0
59+
goal-width: 1.2
5960
placement-offset-touch-line: 0.2
6061
placement-offset-goal-line: 0.2
6162
placement-offset-goal-line-goal-kick: 1.0
@@ -66,6 +67,7 @@ game:
6667
defense-area-depth: 1.0
6768
defense-area-width: 2.0
6869
penalty-kick-dist-to-goal: 6.0
70+
goal-width: 1.0
6971
placement-offset-touch-line: 0.2
7072
placement-offset-goal-line: 0.2
7173
placement-offset-goal-line-goal-kick: 1.0

internal/app/engine/consume_geometry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func (e *Engine) ProcessGeometry(data *vision.SSL_GeometryData) {
1313

1414
newGeometry.FieldWidth = float64(*data.Field.FieldWidth) / 1000.0
1515
newGeometry.FieldLength = float64(*data.Field.FieldLength) / 1000.0
16+
newGeometry.GoalWidth = float64(*data.Field.GoalWidth) / 1000.0
1617
for _, line := range data.Field.FieldLines {
1718
if *line.Name == "LeftFieldLeftPenaltyStretch" {
1819
newGeometry.DefenseAreaDepth = math.Abs(float64(*line.P1.X-*line.P2.X)) / 1000.0

internal/app/engine/process_prepare.go

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package engine
22

33
import (
4+
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/geom"
45
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
56
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/statemachine"
67
"time"
78
)
89

910
const minPreparationTime = time.Second * 2
11+
const distanceToBallDuringPenalty = 1.0
1012

1113
func (e *Engine) processPrepare() {
1214
if !e.currentState.Command.IsPrepare() ||
@@ -38,13 +40,39 @@ func (e *Engine) processPrepare() {
3840
}
3941

4042
if *e.currentState.Command.Type == state.Command_PENALTY {
41-
// TODO check if conditions met for penalty
42-
// keeper pos
43-
44-
// kicking team positions correct
43+
keeperId := e.penaltyKeeperId()
44+
if keeperId == nil {
45+
return
46+
}
47+
keeperPos := e.robotPos(keeperId)
48+
if keeperPos == nil || !e.posInsideGoal(keeperPos) {
49+
return
50+
}
4551

46-
// opponent team positions correct
52+
keeperTeamInfo := e.currentState.TeamState[keeperId.Team.String()]
53+
ballPos := e.gcState.TrackerStateGc.Ball.Pos
4754

55+
numAttackersInFrontOfBall := 0
56+
for _, robot := range e.gcState.TrackerStateGc.Robots {
57+
if *robot.Id.Id == *keeperId.Id && *robot.Id.Team == *keeperId.Team {
58+
// its the keeper
59+
continue
60+
}
61+
if *keeperTeamInfo.OnPositiveHalf &&
62+
*robot.Pos.X < *ballPos.X-distanceToBallDuringPenalty {
63+
continue
64+
} else if !*keeperTeamInfo.OnPositiveHalf &&
65+
*robot.Pos.X > *ballPos.X+distanceToBallDuringPenalty {
66+
continue
67+
}
68+
if *robot.Id.Team == *keeperId.Team {
69+
return
70+
} else if numAttackersInFrontOfBall >= 1 {
71+
return
72+
} else {
73+
numAttackersInFrontOfBall++
74+
}
75+
}
4876
}
4977

5078
e.Enqueue(&statemachine.Change{
@@ -54,3 +82,30 @@ func (e *Engine) processPrepare() {
5482
},
5583
})
5684
}
85+
86+
func (e *Engine) penaltyKeeperId() *state.RobotId {
87+
forTeam := e.currentState.Command.ForTeam.Opposite()
88+
teamInfo := e.currentState.TeamState[forTeam.String()]
89+
keeperId := uint32(*teamInfo.Goalkeeper)
90+
return &state.RobotId{
91+
Id: &keeperId,
92+
Team: &forTeam,
93+
}
94+
}
95+
96+
func (e *Engine) robotPos(robotId *state.RobotId) *geom.Vector2 {
97+
for _, robot := range e.gcState.TrackerStateGc.Robots {
98+
if *robot.Id.Id == *robotId.Id && *robot.Id.Team == *robotId.Team {
99+
return robot.Pos
100+
}
101+
}
102+
return nil
103+
}
104+
105+
func (e *Engine) posInsideGoal(pos *geom.Vector2) bool {
106+
forTeam := *e.currentState.Command.ForTeam
107+
teamInfo := e.currentState.TeamState[forTeam.String()]
108+
goalCenter := geom.GoalCenter(e.GetGeometry(), *teamInfo.OnPositiveHalf)
109+
goalArea := geom.NewRectangleFromCenter(goalCenter, robotRadius*2, e.GetGeometry().GoalWidth)
110+
return goalArea.IsPointInside(pos)
111+
}

internal/app/geom/goal.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package geom
2+
3+
import (
4+
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/config"
5+
)
6+
7+
// GoalCenter returns the goal center using the flag for the side
8+
func GoalCenter(geometry config.Geometry, onPositiveHalf bool) *Vector2 {
9+
if onPositiveHalf {
10+
return GoalCenterBySign(geometry, 1)
11+
}
12+
return GoalCenterBySign(geometry, -1)
13+
}
14+
15+
// GoalCenterBySign returns the goal center using the sign
16+
func GoalCenterBySign(geometry config.Geometry, sign float64) *Vector2 {
17+
return NewVector2(sign*geometry.FieldLength/2, 0)
18+
}

0 commit comments

Comments
 (0)