Skip to content

Commit 990747d

Browse files
committed
Consistent struct naming for handlers
1 parent 84ad07e commit 990747d

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

internal/simctl/handler_geometry.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ var geometryConfigDivA string
1515
//go:embed geometry-div-b.txt
1616
var geometryConfigDivB string
1717

18-
type GeometrySetter struct {
18+
type GeometryHandler struct {
1919
c *SimulationController
2020

2121
geometryDivA *vision.SSL_GeometryData
2222
geometryDivB *vision.SSL_GeometryData
2323
timeLastSent *time.Time
2424
}
2525

26-
func NewGeometrySetter(c *SimulationController) (r *GeometrySetter) {
27-
r = new(GeometrySetter)
26+
func NewGeometryHandler(c *SimulationController) (r *GeometryHandler) {
27+
r = new(GeometryHandler)
2828
r.c = c
2929
r.loadGeometry()
3030
return r
3131
}
3232

33-
func (r *GeometrySetter) Reset() {
33+
func (r *GeometryHandler) Reset() {
3434
r.timeLastSent = nil
3535
}
3636

37-
func (r *GeometrySetter) loadGeometry() {
37+
func (r *GeometryHandler) loadGeometry() {
3838
r.geometryDivA = new(vision.SSL_GeometryData)
3939
if err := proto.UnmarshalText(geometryConfigDivA, r.geometryDivA); err != nil {
4040
log.Println("Could not unmarshal geometry file: ", err)
@@ -45,7 +45,7 @@ func (r *GeometrySetter) loadGeometry() {
4545
}
4646
}
4747

48-
func (r *GeometrySetter) handleGeometry() {
48+
func (r *GeometryHandler) handleGeometry() {
4949
if *r.c.lastRefereeMsg.Stage != referee.Referee_NORMAL_FIRST_HALF_PRE {
5050
// Only before the game starts
5151
return
@@ -71,7 +71,7 @@ func (r *GeometrySetter) handleGeometry() {
7171
}
7272
}
7373

74-
func (r *GeometrySetter) sendConfig(geometry *vision.SSL_GeometryData) {
74+
func (r *GeometryHandler) sendConfig(geometry *vision.SSL_GeometryData) {
7575
log.Printf("Sending geometry %v", geometry)
7676

7777
command := SimulatorCommand{

internal/simctl/handler_replace_ball.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ import (
88
"time"
99
)
1010

11-
type BallReplacer struct {
11+
type BallReplaceHandler struct {
1212
c *SimulationController
1313

1414
lastTimePlacedBall time.Time
1515
haltTime *time.Time
1616
}
1717

18-
func NewBallReplacer(c *SimulationController) (r *BallReplacer) {
19-
r = new(BallReplacer)
18+
func NewBallReplaceHandler(c *SimulationController) (r *BallReplaceHandler) {
19+
r = new(BallReplaceHandler)
2020
r.c = c
2121
return r
2222
}
2323

24-
func (r *BallReplacer) Reset() {
24+
func (r *BallReplaceHandler) Reset() {
2525
r.lastTimePlacedBall = time.Time{}
2626
r.haltTime = nil
2727
}
2828

29-
func (r *BallReplacer) handleReplaceBall() {
29+
func (r *BallReplaceHandler) handleReplaceBall() {
3030
if *r.c.lastRefereeMsg.Command != referee.Referee_HALT {
3131
// Only during HALT
3232
r.haltTime = nil
@@ -72,7 +72,7 @@ func (r *BallReplacer) handleReplaceBall() {
7272
}
7373
}
7474

75-
func (r *BallReplacer) placeBall(ballPos *geom.Vector2) {
75+
func (r *BallReplaceHandler) placeBall(ballPos *geom.Vector2) {
7676

7777
zero := float32(0)
7878
command := SimulatorCommand{

internal/simctl/handler_robot_count.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ import (
1111
"time"
1212
)
1313

14-
type RobotCountMaintainer struct {
14+
type RobotCountHandler struct {
1515
c *SimulationController
1616

1717
lastTimeSendCommand time.Time
1818
robotCountMismatchSince map[referee.Team]time.Time
1919
}
2020

21-
func NewRobotCountMaintainer(c *SimulationController) (r *RobotCountMaintainer) {
22-
r = new(RobotCountMaintainer)
21+
func NewRobotCountHandler(c *SimulationController) (r *RobotCountHandler) {
22+
r = new(RobotCountHandler)
2323
r.c = c
2424
return r
2525
}
2626

27-
func (r *RobotCountMaintainer) Reset() {
27+
func (r *RobotCountHandler) Reset() {
2828
r.lastTimeSendCommand = time.Now()
2929
r.robotCountMismatchSince = map[referee.Team]time.Time{}
3030
r.robotCountMismatchSince[referee.Team_BLUE] = time.Time{}
3131
r.robotCountMismatchSince[referee.Team_YELLOW] = time.Time{}
3232
}
3333

34-
func (r *RobotCountMaintainer) handleRobotCount() {
34+
func (r *RobotCountHandler) handleRobotCount() {
3535

3636
if time.Now().Sub(r.lastTimeSendCommand) < 500*time.Millisecond {
3737
// Placed ball just recently
@@ -59,7 +59,7 @@ func (r *RobotCountMaintainer) handleRobotCount() {
5959
r.updateRobotCount(yellowRobots, int(*r.c.lastRefereeMsg.Yellow.MaxAllowedBots), referee.Team_YELLOW)
6060
}
6161

62-
func (r *RobotCountMaintainer) updateRobotCount(robots []*tracker.TrackedRobot, maxRobots int, team referee.Team) {
62+
func (r *RobotCountHandler) updateRobotCount(robots []*tracker.TrackedRobot, maxRobots int, team referee.Team) {
6363
substCenterPos := geom.NewVector2(0, float64(*r.c.fieldSize.FieldWidth)/2000+float64(*r.c.fieldSize.BoundaryWidth)/2000.0-0.1)
6464
substCenterNeg := geom.NewVector2Float32(0, -*substCenterPos.Y)
6565
substRectPos := geom.NewRectangleFromCenter(substCenterPos, 2, float64(*r.c.fieldSize.BoundaryWidth)/1000+0.2)
@@ -106,7 +106,7 @@ func (r *RobotCountMaintainer) updateRobotCount(robots []*tracker.TrackedRobot,
106106
}
107107
}
108108

109-
func (r *RobotCountMaintainer) nextFreeRobotId(team referee.Team) *referee.RobotId {
109+
func (r *RobotCountHandler) nextFreeRobotId(team referee.Team) *referee.RobotId {
110110
for i := 0; i < 16; i++ {
111111
id := uint32(i)
112112
robotId := &referee.RobotId{
@@ -120,7 +120,7 @@ func (r *RobotCountMaintainer) nextFreeRobotId(team referee.Team) *referee.Robot
120120
return nil
121121
}
122122

123-
func (r *RobotCountMaintainer) isRobotIdFree(id *referee.RobotId) bool {
123+
func (r *RobotCountHandler) isRobotIdFree(id *referee.RobotId) bool {
124124

125125
for _, robot := range r.c.lastTrackedFrame.TrackedFrame.Robots {
126126
if *robot.RobotId.Id == *id.Id && *robot.RobotId.Team == *id.Team {
@@ -130,7 +130,7 @@ func (r *RobotCountMaintainer) isRobotIdFree(id *referee.RobotId) bool {
130130
return true
131131
}
132132

133-
func (r *RobotCountMaintainer) isFreeOfObstacles(pos *geom.Vector2) bool {
133+
func (r *RobotCountHandler) isFreeOfObstacles(pos *geom.Vector2) bool {
134134
for _, robot := range r.c.lastTrackedFrame.TrackedFrame.Robots {
135135
if robot.Pos.DistanceTo(pos) < 0.2 {
136136
return false
@@ -145,7 +145,7 @@ func (r *RobotCountMaintainer) isFreeOfObstacles(pos *geom.Vector2) bool {
145145
return true
146146
}
147147

148-
func (r *RobotCountMaintainer) sortRobotsByDistanceToSubstitutionPos(robots []*tracker.TrackedRobot) {
148+
func (r *RobotCountHandler) sortRobotsByDistanceToSubstitutionPos(robots []*tracker.TrackedRobot) {
149149
negSubstPos := geom.NewVector2(0, -float64(*r.c.fieldSize.FieldWidth)/2000)
150150
posSubstPos := geom.NewVector2(0, +float64(*r.c.fieldSize.FieldWidth)/2000)
151151
sort.Slice(robots, func(i, j int) bool {
@@ -155,7 +155,7 @@ func (r *RobotCountMaintainer) sortRobotsByDistanceToSubstitutionPos(robots []*t
155155
})
156156
}
157157

158-
func (r *RobotCountMaintainer) removeRobot(id *referee.RobotId) {
158+
func (r *RobotCountHandler) removeRobot(id *referee.RobotId) {
159159
log.Printf("Remove robot %v", id)
160160

161161
present := false
@@ -173,7 +173,7 @@ func (r *RobotCountMaintainer) removeRobot(id *referee.RobotId) {
173173
r.sendControlCommand(&command)
174174
}
175175

176-
func (r *RobotCountMaintainer) addRobot(id *referee.RobotId, pos *geom.Vector2) {
176+
func (r *RobotCountHandler) addRobot(id *referee.RobotId, pos *geom.Vector2) {
177177
log.Printf("Add robot %v @ %v", id, pos)
178178

179179
present := true
@@ -195,7 +195,7 @@ func (r *RobotCountMaintainer) addRobot(id *referee.RobotId, pos *geom.Vector2)
195195
r.sendControlCommand(&command)
196196
}
197197

198-
func (r *RobotCountMaintainer) sendControlCommand(command *SimulatorCommand) {
198+
func (r *RobotCountHandler) sendControlCommand(command *SimulatorCommand) {
199199

200200
if data, err := proto.Marshal(command); err != nil {
201201
log.Println("Could not marshal command: ", err)

internal/simctl/handler_robot_specs.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ type CustomRobotSpecErForce struct {
3939
DribblerWidth float32 `yaml:"dribbler_width"`
4040
}
4141

42-
type RobotSpecSetter struct {
42+
type RobotSpecHandler struct {
4343
c *SimulationController
4444

4545
teamRobotSpecs TeamRobotSpecs
4646
appliedTeams map[referee.Team]string
4747
}
4848

49-
func NewRobotSpecSetter(c *SimulationController, configFile string) (r *RobotSpecSetter) {
50-
r = new(RobotSpecSetter)
49+
func NewRobotSpecHandler(c *SimulationController, configFile string) (r *RobotSpecHandler) {
50+
r = new(RobotSpecHandler)
5151
r.c = c
5252
r.loadRobotSpecs(configFile)
5353
return r
5454
}
5555

56-
func (r *RobotSpecSetter) Reset() {
56+
func (r *RobotSpecHandler) Reset() {
5757
r.appliedTeams = map[referee.Team]string{}
5858
}
5959

60-
func (r *RobotSpecSetter) loadRobotSpecs(configFile string) {
60+
func (r *RobotSpecHandler) loadRobotSpecs(configFile string) {
6161
data, err := ioutil.ReadFile(configFile)
6262
if err != nil {
6363
log.Println("Could not read robot spec file: ", err)
@@ -66,7 +66,7 @@ func (r *RobotSpecSetter) loadRobotSpecs(configFile string) {
6666
}
6767
}
6868

69-
func (r *RobotSpecSetter) handleRobotSpecs() {
69+
func (r *RobotSpecHandler) handleRobotSpecs() {
7070
switch *r.c.lastRefereeMsg.Stage {
7171
case referee.Referee_NORMAL_FIRST_HALF_PRE,
7272
referee.Referee_NORMAL_SECOND_HALF_PRE,
@@ -82,7 +82,7 @@ func (r *RobotSpecSetter) handleRobotSpecs() {
8282
r.updateTeam(referee.Team_YELLOW, *r.c.lastRefereeMsg.Yellow.Name)
8383
}
8484

85-
func (r *RobotSpecSetter) updateTeam(team referee.Team, teamName string) {
85+
func (r *RobotSpecHandler) updateTeam(team referee.Team, teamName string) {
8686
if r.appliedTeams[team] != teamName {
8787
if spec, ok := r.teamRobotSpecs.Teams[teamName]; ok {
8888
var protoSpecs []*RobotSpecs
@@ -101,7 +101,7 @@ func (r *RobotSpecSetter) updateTeam(team referee.Team, teamName string) {
101101
}
102102
}
103103

104-
func (r *RobotSpecSetter) sendConfig(robotSpec []*RobotSpecs) {
104+
func (r *RobotSpecHandler) sendConfig(robotSpec []*RobotSpecs) {
105105
log.Printf("Sending robot spec %v", robotSpec)
106106

107107
command := SimulatorCommand{

internal/simctl/simctl.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ type SimulationController struct {
2727
fieldSize *vision.SSL_GeometryFieldSize
2828
lastVisionFrameIds map[uint32]uint32
2929

30-
ballReplacer *BallReplacer
31-
robotCountMaintainer *RobotCountMaintainer
32-
robotSpecsSetter *RobotSpecSetter
33-
geometrySetter *GeometrySetter
30+
ballReplaceHandler *BallReplaceHandler
31+
robotCountHandler *RobotCountHandler
32+
robotSpecsHandler *RobotSpecHandler
33+
geometryHandler *GeometryHandler
3434
}
3535

3636
func NewSimulationController(visionAddress, refereeAddress, trackerAddress, simControlPort, robotSpecConfig string) (c *SimulationController) {
@@ -42,15 +42,15 @@ func NewSimulationController(visionAddress, refereeAddress, trackerAddress, simC
4242
c.simulatorRestarted = true
4343
c.lastVisionFrameIds = map[uint32]uint32{}
4444

45-
c.ballReplacer = NewBallReplacer(c)
46-
c.robotCountMaintainer = NewRobotCountMaintainer(c)
47-
c.robotSpecsSetter = NewRobotSpecSetter(c, robotSpecConfig)
48-
c.geometrySetter = NewGeometrySetter(c)
45+
c.ballReplaceHandler = NewBallReplaceHandler(c)
46+
c.robotCountHandler = NewRobotCountHandler(c)
47+
c.robotSpecsHandler = NewRobotSpecHandler(c, robotSpecConfig)
48+
c.geometryHandler = NewGeometryHandler(c)
4949

50-
c.ballReplacer.c = c
51-
c.robotCountMaintainer.c = c
52-
c.robotSpecsSetter.c = c
53-
c.geometrySetter.c = c
50+
c.ballReplaceHandler.c = c
51+
c.robotCountHandler.c = c
52+
c.robotSpecsHandler.c = c
53+
c.geometryHandler.c = c
5454
return
5555
}
5656

@@ -138,17 +138,17 @@ func (c *SimulationController) handle() {
138138
}
139139

140140
if c.simulatorRestarted {
141-
c.ballReplacer.Reset()
142-
c.robotCountMaintainer.Reset()
143-
c.robotSpecsSetter.Reset()
144-
c.geometrySetter.Reset()
141+
c.ballReplaceHandler.Reset()
142+
c.robotCountHandler.Reset()
143+
c.robotSpecsHandler.Reset()
144+
c.geometryHandler.Reset()
145145
c.simulatorRestarted = false
146146
}
147147

148-
c.ballReplacer.handleReplaceBall()
149-
c.robotCountMaintainer.handleRobotCount()
150-
c.robotSpecsSetter.handleRobotSpecs()
151-
c.geometrySetter.handleGeometry()
148+
c.ballReplaceHandler.handleReplaceBall()
149+
c.robotCountHandler.handleRobotCount()
150+
c.robotSpecsHandler.handleRobotSpecs()
151+
c.geometryHandler.handleGeometry()
152152
}
153153

154154
func (c *SimulationController) Start() {

0 commit comments

Comments
 (0)