Skip to content

Commit 90f8859

Browse files
committed
[#140] Fix: Reset currentActionTimeRemaining correctly
The time was not changed on commands like stop or force_start. So the timer of e.g. ball placement could effect the timer of the no progress detector.
1 parent 557ebd2 commit 90f8859

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

internal/app/statemachine/change_command.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package statemachine
22

33
import (
4+
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/config"
45
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
56
"google.golang.org/protobuf/types/known/durationpb"
67
"google.golang.org/protobuf/types/known/timestamppb"
@@ -12,14 +13,12 @@ func (s *StateMachine) processChangeNewCommand(newState *state.State, newCommand
1213
newState.GameState = s.newGameState(newState, newCommand)
1314
newState.Command = newCommand.Command
1415

15-
switch *newState.Command.Type {
16-
case state.Command_BALL_PLACEMENT:
17-
newState.CurrentActionTimeRemaining = durationpb.New(s.gameConfig.BallPlacementTime)
18-
case state.Command_DIRECT:
19-
newState.CurrentActionTimeRemaining = durationpb.New(s.gameConfig.FreeKickTimeout[newState.Division.Div()])
20-
case state.Command_KICKOFF, state.Command_PENALTY:
21-
newState.CurrentActionTimeRemaining = durationpb.New(s.gameConfig.PrepareTimeout)
22-
case state.Command_TIMEOUT:
16+
newState.CurrentActionTimeRemaining = s.currentActionTimeRemainingForCommand(
17+
*newState.Command.Type,
18+
newState.Division.Div(),
19+
)
20+
21+
if *newState.Command.Type == state.Command_TIMEOUT {
2322
*newState.TeamInfo(*newState.Command.ForTeam).TimeoutsLeft--
2423
newState.TeamInfo(*newState.Command.ForTeam).RequestsTimeoutSince = nil
2524
}
@@ -77,6 +76,19 @@ func (s *StateMachine) processChangeNewCommand(newState *state.State, newCommand
7776
return
7877
}
7978

79+
func (s *StateMachine) currentActionTimeRemainingForCommand(command state.Command_Type, division config.Division) *durationpb.Duration {
80+
switch command {
81+
case state.Command_BALL_PLACEMENT:
82+
return durationpb.New(s.gameConfig.BallPlacementTime)
83+
case state.Command_DIRECT:
84+
return durationpb.New(s.gameConfig.FreeKickTimeout[division])
85+
case state.Command_KICKOFF, state.Command_PENALTY:
86+
return durationpb.New(s.gameConfig.PrepareTimeout)
87+
default:
88+
return durationpb.New(0)
89+
}
90+
}
91+
8092
func (s *StateMachine) newGameState(newState *state.State, newCommand *Change_NewCommand) *state.GameState {
8193
switch *newCommand.Command.Type {
8294
case state.Command_HALT:

0 commit comments

Comments
 (0)