Skip to content

Commit 91608bf

Browse files
committed
Add a config flag to continue from halt (ie after goal) automatically
1 parent 54efd04 commit 91608bf

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

config/ssl-game-controller.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ game:
4545
ball-placement-min-robot-distance: 0.05
4646
distance-to-ball-in-stop: 0.5
4747
auto-approve-goals: false
48+
continue-from-halt: false
4849
challenge-flags: 3
4950
emergency-stop-grace-period: 10s
5051
normal:

internal/app/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Game struct {
5959
BallPlacementMinRobotDistance float64 `yaml:"ball-placement-min-robot-distance"`
6060
DistanceToBallInStop float64 `yaml:"distance-to-ball-in-stop"`
6161
AutoApproveGoals bool `yaml:"auto-approve-goals"`
62+
ContinueFromHalt bool `yaml:"continue-from-halt"`
6263
ChallengeFlags int32 `yaml:"challenge-flags"`
6364
EmergencyStopGracePeriod time.Duration `yaml:"emergency-stop-grace-period"`
6465
}

internal/app/config/testdata/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ game:
4545
ball-placement-min-robot-distance: 0.05
4646
distance-to-ball-in-stop: 0.5
4747
auto-approve-goals: false
48+
continue-from-halt: false
4849
challenge-flags: 3
4950
emergency-stop-grace-period: 10s
5051
normal:

internal/app/engine/process_continue.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const minPreparationTime = time.Second * 2
1111
const distanceToBallDuringPenalty = 1.0
1212

1313
func (e *Engine) processContinue() {
14-
if !(e.currentState.Command.IsPrepare() || *e.currentState.Command.Type == state.Command_STOP) ||
14+
if !(e.currentState.Command.IsPrepare() ||
15+
*e.currentState.Command.Type == state.Command_STOP ||
16+
(e.gameConfig.ContinueFromHalt && *e.currentState.Command.Type == state.Command_HALT)) ||
1517
e.gcState.TrackerStateGc.Ball == nil {
1618
e.gcState.ReadyToContinue = nil
1719
return
@@ -89,6 +91,12 @@ func (e *Engine) processContinue() {
8991
return
9092
}
9193

94+
if *e.currentState.Command.Type == state.Command_STOP &&
95+
(e.currentState.NextCommand == nil ||
96+
!e.readyToContinueFromHalt()) {
97+
return
98+
}
99+
92100
readyToContinue = true
93101

94102
if e.currentState.GetAutoContinue() {
@@ -138,6 +146,24 @@ func (e *Engine) readyToContinueFromStop() bool {
138146
return true
139147
}
140148

149+
func (e *Engine) readyToContinueFromHalt() bool {
150+
if e.gcState.TrackerStateGc.Ball == nil ||
151+
e.currentState.PlacementPos == nil ||
152+
!e.ballSteady() ||
153+
e.currentState.PlacementPos.DistanceTo(e.gcState.TrackerStateGc.Ball.Pos.ToVector2()) > e.gameConfig.BallPlacementTolerance ||
154+
e.tooManyRobots(state.Team_BLUE) ||
155+
e.tooManyRobots(state.Team_YELLOW) {
156+
return false
157+
}
158+
return true
159+
}
160+
161+
func (e *Engine) tooManyRobots(team state.Team) bool {
162+
maxAllowed := *e.currentState.TeamState[team.String()].MaxAllowedBots
163+
current := numRobotsOfTeam(e.gcState.TrackerStateGc.Robots, team)
164+
return current > maxAllowed
165+
}
166+
141167
func (e *Engine) timeSinceLastChange() time.Duration {
142168
if e.stateStore.LatestEntry() != nil {
143169
lastChangeTs := goTime(e.stateStore.LatestEntry().Timestamp)

0 commit comments

Comments
 (0)