Skip to content

Commit 645c174

Browse files
committed
Code cleanup and documentation
1 parent a318ab4 commit 645c174

33 files changed

+118
-140
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"crypto/rsa"
66
"flag"
77
"fmt"
8-
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/client"
98
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/geom"
109
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon"
1110
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
11+
"github.com/RoboCup-SSL/ssl-game-controller/pkg/client"
1212
"github.com/RoboCup-SSL/ssl-go-tools/pkg/sslconn"
1313
"log"
1414
"net"

cmd/ssl-team-client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"crypto/rsa"
55
"flag"
6-
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/client"
76
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon"
7+
"github.com/RoboCup-SSL/ssl-game-controller/pkg/client"
88
"github.com/RoboCup-SSL/ssl-go-tools/pkg/sslconn"
99
"github.com/golang/protobuf/proto"
1010
"log"

internal/app/engine/common.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import (
44
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/geom"
55
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
66
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/statemachine"
7+
"github.com/golang/protobuf/ptypes"
8+
"github.com/golang/protobuf/ptypes/duration"
9+
"github.com/golang/protobuf/ptypes/timestamp"
10+
"log"
711
"time"
812
)
913

@@ -43,3 +47,34 @@ func (e *Engine) timeSinceLastChange() time.Duration {
4347
}
4448
return 0
4549
}
50+
51+
func goDur(duration *duration.Duration) time.Duration {
52+
goDur, err := ptypes.Duration(duration)
53+
if err != nil {
54+
log.Printf("Could not parse duration: %v", duration)
55+
}
56+
return goDur
57+
}
58+
59+
func goTime(timestamp *timestamp.Timestamp) time.Time {
60+
goTime, err := ptypes.Timestamp(timestamp)
61+
if err != nil {
62+
log.Printf("Could not parse timestamp: %v", timestamp)
63+
}
64+
return goTime
65+
}
66+
67+
func addDur(duration *duration.Duration, delta time.Duration) {
68+
goDur, err := ptypes.Duration(duration)
69+
if err != nil {
70+
log.Printf("Could not parse duration: %v", duration)
71+
}
72+
*duration = *ptypes.DurationProto(goDur + delta)
73+
}
74+
75+
func (e *Engine) ballSteady() bool {
76+
if e.gcState.TrackerStateGc.Ball.Vel == nil {
77+
return true
78+
}
79+
return e.gcState.TrackerStateGc.Ball.Vel.ToVector2().Length() < ballSteadyThreshold
80+
}

internal/app/gc/geometry.go renamed to internal/app/engine/consume_geometry.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package gc
1+
package engine
22

33
import (
44
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/vision"
55
"log"
66
"math"
77
)
88

9-
func (c *GameController) ProcessGeometry(data *vision.SSL_GeometryData) {
9+
func (e *Engine) ProcessGeometry(data *vision.SSL_GeometryData) {
1010

11-
currentGeometry := c.gcEngine.GetGeometry()
11+
currentGeometry := e.GetGeometry()
1212
newGeometry := currentGeometry
1313

1414
newGeometry.FieldWidth = float64(*data.Field.FieldWidth) / 1000.0
@@ -21,7 +21,7 @@ func (c *GameController) ProcessGeometry(data *vision.SSL_GeometryData) {
2121
}
2222
}
2323

24-
c.gcEngine.SetGeometry(newGeometry)
24+
e.SetGeometry(newGeometry)
2525

2626
if currentGeometry != newGeometry {
2727
log.Printf("Geometry changed from %v to %v", currentGeometry, newGeometry)

internal/app/engine/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (e *Engine) processChanges() {
166166
}
167167
e.processChange(change)
168168
case <-time.After(10 * time.Millisecond):
169-
e.tick()
169+
e.processTick()
170170

171171
e.noProgressDetector.process()
172172
e.ballPlacementCoordinator.process()

internal/app/engine/process_runningtostop.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,3 @@ func (e *Engine) ballPlacementRequired() bool {
6565

6666
return false
6767
}
68-
69-
func (e *Engine) ballSteady() bool {
70-
if e.gcState.TrackerStateGc.Ball.Vel == nil {
71-
return true
72-
}
73-
return e.gcState.TrackerStateGc.Ball.Vel.ToVector2().Length() < ballSteadyThreshold
74-
}

internal/app/engine/timed.go renamed to internal/app/engine/process_tick.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ import (
44
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
55
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/statemachine"
66
"github.com/golang/protobuf/ptypes"
7-
"github.com/golang/protobuf/ptypes/duration"
8-
"github.com/golang/protobuf/ptypes/timestamp"
9-
"log"
107
"time"
118
)
129

13-
// tick updates the timers of the state and triggers changes if required
14-
func (e *Engine) tick() {
10+
// processTick updates the timers of the state and triggers changes if required
11+
func (e *Engine) processTick() {
1512
currentTime := e.timeProvider()
1613
delta := currentTime.Sub(e.lastTimeUpdate)
1714
e.lastTimeUpdate = currentTime
@@ -64,27 +61,3 @@ func (e *Engine) updateYellowCardTimes(teamState *state.TeamInfo, delta time.Dur
6461
}
6562
}
6663
}
67-
68-
func goDur(duration *duration.Duration) time.Duration {
69-
goDur, err := ptypes.Duration(duration)
70-
if err != nil {
71-
log.Printf("Could not parse duration: %v", duration)
72-
}
73-
return goDur
74-
}
75-
76-
func goTime(timestamp *timestamp.Timestamp) time.Time {
77-
goTime, err := ptypes.Timestamp(timestamp)
78-
if err != nil {
79-
log.Printf("Could not parse timestamp: %v", timestamp)
80-
}
81-
return goTime
82-
}
83-
84-
func addDur(duration *duration.Duration, delta time.Duration) {
85-
goDur, err := ptypes.Duration(duration)
86-
if err != nil {
87-
log.Printf("Could not parse duration: %v", duration)
88-
}
89-
*duration = *ptypes.DurationProto(goDur + delta)
90-
}

internal/app/gc/gc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewGameController(cfg config.Controller) (c *GameController) {
3838
c.teamServerTls = rcon.NewTeamServer(cfg.Server.Team.AddressTls, c.gcEngine)
3939
c.teamServerTls.Tls = true
4040
c.visionReceiver = vision.NewReceiver(cfg.Network.VisionAddress)
41-
c.visionReceiver.GeometryCallback = c.ProcessGeometry
41+
c.visionReceiver.GeometryCallback = c.gcEngine.ProcessGeometry
4242
c.trackerReceiver = tracker.NewReceiver(cfg.Network.TrackerAddress)
4343
c.trackerReceiver.Callback = c.gcEngine.ProcessTrackerFrame
4444
return
@@ -55,10 +55,12 @@ func (c *GameController) Start() {
5555
c.teamServer.Server.Start()
5656
c.teamServerTls.Server.Start()
5757
c.visionReceiver.Start()
58+
c.trackerReceiver.Start()
5859
}
5960

6061
// Stop stops all go routines
6162
func (c *GameController) Stop() {
63+
c.trackerReceiver.Stop()
6264
c.visionReceiver.Stop()
6365
c.autoRefServer.Server.Stop()
6466
c.autoRefServerTls.Server.Stop()

internal/app/geom/defensearea.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/config"
55
)
66

7+
// NewDefenseArea creates a rectangle representing a defense area, using the flag for the side
78
func NewDefenseArea(geometry config.Geometry, onPositiveHalf bool) *Rectangle {
89
if onPositiveHalf {
910
return NewDefenseAreaBySign(geometry, 1)
1011
}
1112
return NewDefenseAreaBySign(geometry, -1)
1213
}
1314

15+
// NewDefenseAreaBySign creates a rectangle representing a defense area, using the sign for the side
1416
func NewDefenseAreaBySign(geometry config.Geometry, sign float64) *Rectangle {
1517
center := NewVector2(sign*(geometry.FieldLength/2.0-geometry.DefenseAreaDepth/2.0), 0)
1618
return NewRectangleFromCenter(center, geometry.DefenseAreaDepth, geometry.DefenseAreaWidth)

0 commit comments

Comments
 (0)