Skip to content

Commit 7a1b737

Browse files
committed
Avoid using the PLC register values before a match starts.
1 parent 3c0910d commit 7a1b737

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

field/arena.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,12 @@ func (arena *Arena) handlePlcInputOutput() {
972972

973973
// Get all the game-specific inputs and update the score.
974974
redAmplifyButton, redCoopButton, blueAmplifyButton, blueCoopButton := arena.Plc.GetAmpButtons()
975-
redAmpNoteCount, redSpeakerNoteCount, blueAmpNoteCount, blueSpeakerNoteCount := arena.Plc.GetAmpSpeakerNoteCounts()
975+
var redAmpNoteCount, redSpeakerNoteCount, blueAmpNoteCount, blueSpeakerNoteCount int
976+
if arena.MatchState != PreMatch {
977+
// Don't read the registers pre-match to avoid messing up the amp/speaker state from any manual testing.
978+
redAmpNoteCount, redSpeakerNoteCount, blueAmpNoteCount, blueSpeakerNoteCount =
979+
arena.Plc.GetAmpSpeakerNoteCounts()
980+
}
976981
redAmpSpeaker := &arena.RedRealtimeScore.CurrentScore.AmpSpeaker
977982
blueAmpSpeaker := &arena.BlueRealtimeScore.CurrentScore.AmpSpeaker
978983
redAmpSpeaker.UpdateState(

plc/plc.go

+6
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ func (plc *ModbusPlc) GetEthernetConnected() ([3]bool, [3]bool) {
259259
func (plc *ModbusPlc) ResetMatch() {
260260
plc.coils[matchReset] = true
261261
plc.matchResetCycles = 0
262+
263+
// Clear register variables (other than fieldIoConnection) so that any values from pre-match testing don't carry
264+
// over.
265+
for i := 1; i < int(registerCount); i++ {
266+
plc.registers[i] = 0
267+
}
262268
}
263269

264270
// Sets the on/off state of the stack lights on the scoring table.

plc/plc_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,22 @@ func TestPlcCoils(t *testing.T) {
446446
assert.Equal(t, true, client.coils[0])
447447

448448
assert.Equal(t, false, client.coils[1])
449+
client.registers[fieldIoConnection] = 31
450+
plc.registers[fieldIoConnection] = 31
451+
plc.registers[redSpeaker] = 1
452+
plc.registers[blueSpeaker] = 2
453+
plc.registers[redAmp] = 3
454+
plc.registers[blueAmp] = 4
455+
plc.registers[miscounts] = 5
449456
plc.ResetMatch()
450457
plc.update()
451458
assert.Equal(t, true, client.coils[1])
459+
assert.Equal(t, 31, int(plc.registers[fieldIoConnection]))
460+
assert.Equal(t, 0, int(plc.registers[redSpeaker]))
461+
assert.Equal(t, 0, int(plc.registers[blueSpeaker]))
462+
assert.Equal(t, 0, int(plc.registers[redAmp]))
463+
assert.Equal(t, 0, int(plc.registers[blueAmp]))
464+
assert.Equal(t, 0, int(plc.registers[miscounts]))
452465

453466
plc.SetStackLights(false, false, false, false)
454467
plc.update()

0 commit comments

Comments
 (0)