Skip to content

Commit 891871d

Browse files
committed
Integrate tracker messages
1 parent ed7d63e commit 891871d

40 files changed

+2599
-1643
lines changed

cmd/ssl-auto-ref-client/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"flag"
77
"fmt"
88
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/client"
9+
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/geom"
910
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon"
1011
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
1112
"github.com/RoboCup-SSL/ssl-go-tools/pkg/sslconn"
@@ -154,7 +155,7 @@ func (c *Client) sendBallLeftField() {
154155
*event.BallLeftFieldTouchLine.ByBot = 2
155156
event.BallLeftFieldTouchLine.ByTeam = new(state.Team)
156157
*event.BallLeftFieldTouchLine.ByTeam = state.Team_BLUE
157-
event.BallLeftFieldTouchLine.Location = &state.Location{X: new(float32), Y: new(float32)}
158+
event.BallLeftFieldTouchLine.Location = &geom.Vector2{X: new(float32), Y: new(float32)}
158159
*event.BallLeftFieldTouchLine.Location.X = 1
159160
*event.BallLeftFieldTouchLine.Location.Y = 4.5
160161
gameEvent := state.GameEvent{Event: &event, Type: new(state.GameEvent_Type)}
@@ -170,7 +171,7 @@ func (c *Client) sendDoubleTouch() {
170171
*event.AttackerDoubleTouchedBall.ByBot = 2
171172
event.AttackerDoubleTouchedBall.ByTeam = new(state.Team)
172173
*event.AttackerDoubleTouchedBall.ByTeam = state.Team_BLUE
173-
event.AttackerDoubleTouchedBall.Location = &state.Location{X: new(float32), Y: new(float32)}
174+
event.AttackerDoubleTouchedBall.Location = &geom.Vector2{X: new(float32), Y: new(float32)}
174175
*event.AttackerDoubleTouchedBall.Location.X = 1
175176
*event.AttackerDoubleTouchedBall.Location.Y = 4.5
176177
gameEvent := state.GameEvent{Event: &event, Type: new(state.GameEvent_Type)}
@@ -188,7 +189,7 @@ func (c *Client) sendBotCrashUnique() {
188189
*event.BotCrashUnique.Victim = 5
189190
event.BotCrashUnique.ByTeam = new(state.Team)
190191
*event.BotCrashUnique.ByTeam = state.Team_BLUE
191-
event.BotCrashUnique.Location = &state.Location{X: new(float32), Y: new(float32)}
192+
event.BotCrashUnique.Location = &geom.Vector2{X: new(float32), Y: new(float32)}
192193
*event.BotCrashUnique.Location.X = 1
193194
*event.BotCrashUnique.Location.Y = 4.5
194195
gameEvent := state.GameEvent{Event: &event, Type: new(state.GameEvent_Type)}

generateProto.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@ set -x
88
echo "Update to latest Go protobuf compiler"
99
go get -u github.com/golang/protobuf/protoc-gen-go
1010

11+
# common GC
12+
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_common.proto
13+
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_geometry.proto
14+
1115
# vision
1216
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_vision_detection.proto
1317
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_vision_geometry.proto
1418
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_vision_wrapper.proto
1519

20+
# tracked vision
21+
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_vision_detection_tracked.proto
22+
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_vision_wrapper_tracked.proto
23+
1624
# game events
17-
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_game_event.proto
25+
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_game_event.proto
1826

1927
# referee message
20-
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_referee.proto
21-
22-
# geometry
23-
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_geometry.proto
28+
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_referee_message.proto
2429

2530
# remote communication
2631
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_rcon.proto
@@ -34,4 +39,12 @@ protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_api.proto
3439
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_engine.proto
3540

3641
# generate javascript code
37-
pbjs -t static-module -w es6 -o src/proto.js proto/ssl_game_event.proto proto/ssl_referee.proto proto/ssl_gc_change.proto proto/ssl_gc_state.proto proto/ssl_gc_api.proto
42+
pbjs -t static-module -w es6 -o src/proto.js \
43+
proto/ssl_gc_common.proto \
44+
proto/ssl_gc_geometry.proto \
45+
proto/ssl_gc_game_event.proto \
46+
proto/ssl_gc_referee_message.proto \
47+
proto/ssl_gc_change.proto \
48+
proto/ssl_gc_state.proto \
49+
proto/ssl_gc_api.proto \
50+
proto/ssl_gc_engine.proto

internal/app/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Game struct {
6262
type Network struct {
6363
PublishAddress string `yaml:"publish-address"`
6464
VisionAddress string `yaml:"vision-address"`
65+
TrackerAddress string `yaml:"tracker-address"`
6566
}
6667

6768
// Server holds configs for the available server services
@@ -147,6 +148,7 @@ func (c *Controller) WriteTo(fileName string) (err error) {
147148
func DefaultControllerConfig() (c Controller) {
148149
c.Network.PublishAddress = "224.5.23.1:10003"
149150
c.Network.VisionAddress = "224.5.23.2:10006"
151+
c.Network.TrackerAddress = "224.5.23.2:10010"
150152
c.Game.StateStoreFile = "state-store.json.stream"
151153
c.Game.YellowCardDuration = 2 * time.Minute
152154
c.Game.TeamChoiceTimeout = 200 * time.Millisecond

internal/app/config/testdata/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ time-acquisition-mode: system
22
network:
33
publish-address: 224.5.23.1:10003
44
vision-address: 224.5.23.2:10006
5+
tracker-address: 224.5.23.2:10010
56
server:
67
auto-ref:
78
address: :10007

internal/app/engine/common.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ func (e *Engine) robotsInsideRadius(robots []*Robot, pos *geom.Vector2, radius f
3535
return false
3636
}
3737

38-
func vector2ToLocation(v *geom.Vector2) state.Location {
39-
return state.NewLocation64(*v.X, *v.Y)
40-
}
41-
42-
func locationToVector2(l *state.Location) *geom.Vector2 {
43-
return geom.NewVector2(float64(*l.X), float64(*l.Y))
44-
}
45-
4638
func (e *Engine) timeSinceLastChange() time.Duration {
4739
if e.stateStore.LatestEntry() != nil {
4840
lastChangeTs := goTime(e.stateStore.LatestEntry().Timestamp)

internal/app/engine/process_ballplacement.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ type BallPlacementCoordinator struct {
1515
func (c *BallPlacementCoordinator) process() {
1616
e := c.gcEngine
1717

18-
if *e.currentState.Command.Type != state.Command_BALL_PLACEMENT {
18+
if *e.currentState.Command.Type != state.Command_BALL_PLACEMENT ||
19+
e.gcState.TrackerStateGc.Ball == nil {
1920
return
2021
}
2122

2223
if c.ballPlacementStartPos == nil || c.ballPlacementStartTime == nil {
23-
c.ballPlacementStartPos = e.gcState.TrackerStateGc.Ball.Pos
24+
c.ballPlacementStartPos = e.gcState.TrackerStateGc.Ball.Pos.ToVector2()
2425
c.ballPlacementStartTime = new(time.Time)
2526
*c.ballPlacementStartTime = e.timeProvider()
2627
}
@@ -36,7 +37,7 @@ func (c *BallPlacementCoordinator) process() {
3637
var distance *float32
3738
if c.ballPlacementStartPos != nil && e.gcState.TrackerStateGc.Ball.Pos != nil {
3839
distance = new(float32)
39-
*distance = float32(c.ballPlacementStartPos.DistanceTo(e.gcState.TrackerStateGc.Ball.Pos))
40+
*distance = float32(c.ballPlacementStartPos.DistanceTo(e.gcState.TrackerStateGc.Ball.Pos.ToVector2()))
4041
}
4142
e.Enqueue(createGameEventChange(state.GameEvent_PLACEMENT_SUCCEEDED, state.GameEvent{
4243
Event: &state.GameEvent_PlacementSucceeded_{
@@ -65,8 +66,8 @@ func (c *BallPlacementCoordinator) remainingPlacementDistance() float32 {
6566
if c.gcEngine.currentState.PlacementPos == nil || c.gcEngine.gcState.TrackerStateGc.Ball.Pos == nil {
6667
return -1
6768
}
68-
placementPos := locationToVector2(c.gcEngine.currentState.PlacementPos)
69-
ballPos := c.gcEngine.gcState.TrackerStateGc.Ball.Pos
69+
placementPos := c.gcEngine.currentState.PlacementPos
70+
ballPos := c.gcEngine.gcState.TrackerStateGc.Ball.Pos.ToVector2()
7071
return float32(placementPos.DistanceTo(ballPos))
7172
}
7273

@@ -83,7 +84,7 @@ func (e *Engine) teamInFavorKeepsSufficientDistance() bool {
8384
}
8485
}
8586

86-
return !e.robotsInsideRadius(robots, e.gcState.TrackerStateGc.Ball.Pos, radius)
87+
return !e.robotsInsideRadius(robots, e.gcState.TrackerStateGc.Ball.Pos.ToVector2(), radius)
8788
}
8889

8990
func (e *Engine) opponentTeamKeepsSufficientDistance() bool {
@@ -96,5 +97,5 @@ func (e *Engine) opponentTeamKeepsSufficientDistance() bool {
9697
}
9798
}
9899

99-
return !e.robotsInsideRadius(robots, e.gcState.TrackerStateGc.Ball.Pos, radius)
100+
return !e.robotsInsideRadius(robots, e.gcState.TrackerStateGc.Ball.Pos.ToVector2(), radius)
100101
}

internal/app/engine/process_noprogress.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ type NoProgressDetector struct {
1717
func (d *NoProgressDetector) process() {
1818

1919
if !d.gcEngine.currentState.Command.IsRunning() ||
20+
d.gcEngine.gcState.TrackerStateGc.Ball == nil ||
2021
(d.gcEngine.currentState.CurrentActionTimeRemaining != nil && goDur(d.gcEngine.currentState.CurrentActionTimeRemaining) > 0) {
2122
d.lastBallPos = nil
2223
d.lastTime = nil
2324
return
2425
}
2526

2627
if d.lastBallPos == nil {
27-
d.lastBallPos = d.gcEngine.gcState.TrackerStateGc.Ball.Pos
28+
d.lastBallPos = d.gcEngine.gcState.TrackerStateGc.Ball.Pos.ToVector2()
2829
return
2930
}
3031

31-
if d.lastBallPos.DistanceTo(d.gcEngine.gcState.TrackerStateGc.Ball.Pos) > distanceTolerance {
32+
if d.lastBallPos.DistanceTo(d.gcEngine.gcState.TrackerStateGc.Ball.Pos.ToVector2()) > distanceTolerance {
3233
d.lastTime = nil
33-
d.lastBallPos = d.gcEngine.gcState.TrackerStateGc.Ball.Pos
34+
d.lastBallPos = d.gcEngine.gcState.TrackerStateGc.Ball.Pos.ToVector2()
3435
return
3536
}
3637

@@ -43,15 +44,15 @@ func (d *NoProgressDetector) process() {
4344
timeSinceLastProgress := d.gcEngine.timeProvider().Sub(*d.lastTime)
4445
if timeSinceLastProgress > d.gcEngine.gameConfig.NoProgressTimeout[d.gcEngine.currentState.Division.Div()] {
4546
duration := float32(timeSinceLastProgress.Seconds())
46-
location := vector2ToLocation(d.gcEngine.gcState.TrackerStateGc.Ball.Pos)
47+
location := d.gcEngine.gcState.TrackerStateGc.Ball.Pos.ToVector2()
4748
for _, team := range state.BothTeams() {
4849
defenseArea := geom.NewDefenseArea(d.gcEngine.GetGeometry(), *d.gcEngine.currentState.TeamState[team.String()].OnPositiveHalf)
49-
if defenseArea.IsPointInside(d.gcEngine.gcState.TrackerStateGc.Ball.Pos) {
50+
if defenseArea.IsPointInside(d.gcEngine.gcState.TrackerStateGc.Ball.Pos.ToVector2()) {
5051
d.gcEngine.Enqueue(createGameEventChange(state.GameEvent_KEEPER_HELD_BALL, state.GameEvent{
5152
Event: &state.GameEvent_KeeperHeldBall_{
5253
KeeperHeldBall: &state.GameEvent_KeeperHeldBall{
5354
ByTeam: &team,
54-
Location: &location,
55+
Location: location,
5556
Duration: &duration,
5657
},
5758
},
@@ -62,7 +63,7 @@ func (d *NoProgressDetector) process() {
6263
d.gcEngine.Enqueue(createGameEventChange(state.GameEvent_NO_PROGRESS_IN_GAME, state.GameEvent{
6364
Event: &state.GameEvent_NoProgressInGame_{
6465
NoProgressInGame: &state.GameEvent_NoProgressInGame{
65-
Location: &location,
66+
Location: location,
6667
Time: &duration,
6768
},
6869
},

internal/app/engine/process_prepare.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const minPreparationTime = time.Second * 2
1010

1111
func (e *Engine) processPrepare() {
1212
if !e.currentState.Command.IsPrepare() ||
13+
e.gcState.TrackerStateGc.Ball == nil ||
1314
!e.readyToContinue() ||
1415
e.currentState.NextCommand == nil ||
1516
!e.currentState.GetAutoContinue() ||
@@ -19,7 +20,7 @@ func (e *Engine) processPrepare() {
1920

2021
if *e.currentState.Command.Type == state.Command_KICKOFF {
2122
// ball in center circle
22-
if e.gcState.TrackerStateGc.Ball.Pos.Length() > e.gameConfig.DistanceToBallInStop {
23+
if e.gcState.TrackerStateGc.Ball.Pos.ToVector2().Length() > e.gameConfig.DistanceToBallInStop {
2324
return
2425
}
2526

@@ -56,7 +57,7 @@ func (e *Engine) processPrepare() {
5657
func (e *Engine) readyToContinue() bool {
5758
radius := e.gameConfig.DistanceToBallInStop + robotRadius + distanceThreshold
5859
if !e.ballSteady() ||
59-
e.robotsInsideRadius(e.gcState.TrackerStateGc.Robots, e.gcState.TrackerStateGc.Ball.Pos, radius) {
60+
e.robotsInsideRadius(e.gcState.TrackerStateGc.Robots, e.gcState.TrackerStateGc.Ball.Pos.ToVector2(), radius) {
6061
return false
6162
}
6263
return false

internal/app/engine/process_runningtostop.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ func (e *Engine) processRunningToStop() {
3131
}
3232

3333
func (e *Engine) ballPlacementRequired() bool {
34-
if e.currentState.PlacementPos == nil || e.gcState.TrackerStateGc.Ball.Pos == nil {
34+
if e.currentState.PlacementPos == nil || e.gcState.TrackerStateGc.Ball == nil {
3535
// fallback if the fields are not set
3636
return false
3737
}
38-
placementPos := locationToVector2(e.currentState.PlacementPos)
39-
ballPos := e.gcState.TrackerStateGc.Ball.Pos
38+
placementPos := e.currentState.PlacementPos
39+
ballPos := e.gcState.TrackerStateGc.Ball.Pos.ToVector2()
4040

4141
// The ball is closer than 1m to the designated position.
4242
if ballPos.DistanceTo(placementPos) > e.gameConfig.BallPlacementRequiredDistance {
@@ -70,5 +70,5 @@ func (e *Engine) ballSteady() bool {
7070
if e.gcState.TrackerStateGc.Ball.Vel == nil {
7171
return true
7272
}
73-
return e.gcState.TrackerStateGc.Ball.Vel.Length() < ballSteadyThreshold
73+
return e.gcState.TrackerStateGc.Ball.Vel.ToVector2().Length() < ballSteadyThreshold
7474
}

0 commit comments

Comments
 (0)