Skip to content

Commit beaad2e

Browse files
committed
[feature] Add an option to use vision detection frames as time provider
1 parent cf0395c commit beaad2e

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

config/ssl-game-controller.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
timeFromVision: false
12
network:
23
publish-address: 224.5.23.1:10003
34
vision-address: 224.5.23.2:10006

internal/app/config/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ type ServerTeam struct {
6969

7070
// Controller structure for the game controller
7171
type Controller struct {
72-
Network Network `yaml:"network"`
73-
Game Game `yaml:"game"`
74-
Server Server `yaml:"server"`
72+
Network Network `yaml:"network"`
73+
Game Game `yaml:"game"`
74+
Server Server `yaml:"server"`
75+
TimeFromVision bool `yaml:"timeFromVision"`
7576
}
7677

7778
// LoadControllerConfig loads a config from given file
@@ -152,6 +153,8 @@ func DefaultControllerConfig() (c Controller) {
152153
c.Game.MaxBots[DivA] = 8
153154
c.Game.MaxBots[DivB] = 6
154155

156+
c.TimeFromVision = false
157+
155158
return
156159
}
157160

internal/app/controller/controller.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon"
66
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/vision"
77
"github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
8+
"github.com/RoboCup-SSL/ssl-go-tools/pkg/sslproto"
89
"log"
910
"sync"
1011
"time"
@@ -51,6 +52,8 @@ func NewGameController() (c *GameController) {
5152
c.Engine = NewEngine(c.Config.Game)
5253
c.timer = timer.NewTimer()
5354

55+
c.setupTimeProvider()
56+
5457
return
5558
}
5659

@@ -82,6 +85,24 @@ func (c *GameController) Run() {
8285
go c.TeamServer.Listen(c.Config.Server.Team.Address)
8386
}
8487

88+
// setupTimeProvider changes the time provider to the vision receiver, if configured
89+
func (c *GameController) setupTimeProvider() {
90+
if c.Config.TimeFromVision {
91+
c.timer.TimeProvider = func() time.Time {
92+
return time.Unix(0, 0)
93+
}
94+
c.Engine.TimeProvider = c.timer.TimeProvider
95+
c.VisionReceiver.DetectionCallback = func(frame *sslproto.SSL_DetectionFrame) {
96+
sec := int64(*frame.TCapture)
97+
nsec := int64((*frame.TCapture - float64(sec)) * 1e9)
98+
c.timer.TimeProvider = func() time.Time {
99+
return time.Unix(sec, nsec)
100+
}
101+
c.Engine.TimeProvider = c.timer.TimeProvider
102+
}
103+
}
104+
}
105+
85106
// mainLoop updates several states every full second and publishes the new state
86107
func (c *GameController) mainLoop() {
87108
defer c.historyPreserver.Close()

0 commit comments

Comments
 (0)