Skip to content

Commit

Permalink
Allow a match to start with the A-Stop pressed but require it to have…
Browse files Browse the repository at this point in the history
… been reset since the previous match.
  • Loading branch information
patfair committed May 12, 2024
1 parent 55f9c47 commit 504e2e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 10 additions & 2 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type AllianceStation struct {
Bypass bool
Team *model.Team
WifiStatus network.TeamWifiStatus
aStopReset bool
}

// Creates the arena and sets it to its initial state.
Expand Down Expand Up @@ -688,6 +689,9 @@ func (arena *Arena) assignTeam(teamId int, station string) error {
return fmt.Errorf("Invalid alliance station '%s'.", station)
}

// Force the A-stop to be reset by the new team if it is already pressed (if the PLC is enabled).
arena.AllianceStations[station].aStopReset = !arena.Plc.IsEnabled()

// Do nothing if the station is already assigned to the requested team.
dsConn := arena.AllianceStations[station].DsConn
if dsConn != nil && dsConn.TeamId == teamId {
Expand Down Expand Up @@ -822,8 +826,11 @@ func (arena *Arena) checkCanStartMatch() error {
func (arena *Arena) checkAllianceStationsReady(stations ...string) error {
for _, station := range stations {
allianceStation := arena.AllianceStations[station]
if allianceStation.EStop || allianceStation.AStop {
return fmt.Errorf("cannot start match while an emergency or autonomous stop is active")
if allianceStation.EStop {
return fmt.Errorf("cannot start match while an emergency stop is active")
}
if !allianceStation.aStopReset {
return fmt.Errorf("cannot start match if an autonomous stop has not been reset since the previous match")
}
if !allianceStation.Bypass {
if allianceStation.DsConn == nil || !allianceStation.DsConn.RobotLinked {
Expand Down Expand Up @@ -987,6 +994,7 @@ func (arena *Arena) handleTeamStop(station string, eStopState, aStopState bool)
} else if arena.MatchState != AutoPeriod {
// Keep the A-stop latched until the autonomous period is over.
allianceStation.AStop = false
allianceStation.aStopReset = true
}
}

Expand Down
15 changes: 11 additions & 4 deletions field/arena_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,16 @@ func TestMatchStartRobotLinkEnforcement(t *testing.T) {
arena.AllianceStations["R1"].EStop = true
err = arena.StartMatch()
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "while an emergency or autonomous stop is active")
assert.Contains(t, err.Error(), "while an emergency stop is active")
}
arena.AllianceStations["R1"].EStop = false
arena.AllianceStations["R1"].aStopReset = false
arena.AllianceStations["R1"].AStop = true
err = arena.StartMatch()
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "while an emergency or autonomous stop is active")
assert.Contains(t, err.Error(), "if an autonomous stop has not been reset since the previous match")
}
arena.AllianceStations["R1"].AStop = false
arena.AllianceStations["R1"].aStopReset = true
arena.AllianceStations["R1"].DsConn.RobotLinked = false
err = arena.StartMatch()
if assert.NotNil(t, err) {
Expand Down Expand Up @@ -378,7 +379,7 @@ func TestMatchStartRobotLinkEnforcement(t *testing.T) {
arena.AllianceStations["B3"].EStop = true
err = arena.StartMatch()
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "while an emergency or autonomous stop is active")
assert.Contains(t, err.Error(), "while an emergency stop is active")
}
arena.AllianceStations["B3"].EStop = false
err = arena.StartMatch()
Expand Down Expand Up @@ -667,11 +668,17 @@ func TestPlcEStopAStop(t *testing.T) {
arena.AllianceStations["R2"].DsConn = dummyDs

arena.AllianceStations["R1"].DsConn.RobotLinked = true
arena.AllianceStations["R1"].aStopReset = true
arena.AllianceStations["R2"].DsConn.RobotLinked = true
arena.AllianceStations["R2"].aStopReset = true
arena.AllianceStations["R3"].Bypass = true
arena.AllianceStations["R3"].aStopReset = true
arena.AllianceStations["B1"].Bypass = true
arena.AllianceStations["B1"].aStopReset = true
arena.AllianceStations["B2"].Bypass = true
arena.AllianceStations["B2"].aStopReset = true
arena.AllianceStations["B3"].Bypass = true
arena.AllianceStations["B3"].aStopReset = true
err = arena.StartMatch()
assert.Nil(t, err)
arena.Update()
Expand Down

0 comments on commit 504e2e7

Please sign in to comment.