From ad509aed5ae4cfd696474eacdb96e1ade50593aa Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Tue, 14 Apr 2020 20:09:09 -0700 Subject: [PATCH] Send reset signal to PLC on match load and again on match start. --- field/arena.go | 2 ++ plc/plc.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/field/arena.go b/field/arena.go index 1cfbf48..8dc27c3 100644 --- a/field/arena.go +++ b/field/arena.go @@ -214,6 +214,7 @@ func (arena *Arena) LoadMatch(match *model.Match) error { arena.FieldVolunteers = false arena.FieldReset = false arena.ScoringPanelRegistry.resetScoreCommitted() + arena.Plc.ResetMatch() // Notify any listeners about the new match. arena.MatchLoadNotifier.Notify() @@ -404,6 +405,7 @@ func (arena *Arena) Update() { enabled = true sendDsPacket = true } + arena.Plc.ResetMatch() case WarmupPeriod: auto = true enabled = false diff --git a/plc/plc.go b/plc/plc.go index ec77361..00c9790 100644 --- a/plc/plc.go +++ b/plc/plc.go @@ -28,6 +28,7 @@ type Plc struct { oldRegisters [registerCount]uint16 oldCoils [coilCount]bool cycleCounter int + matchResetCycles int } const ( @@ -231,6 +232,12 @@ func (plc *Plc) GetEthernetConnected() ([3]bool, [3]bool) { } } +// Resets the internal state of the PLC to start a new match. +func (plc *Plc) ResetMatch() { + plc.coils[matchReset] = true + plc.matchResetCycles = 0 +} + // Returns the total number of power cells scored since match start in each level of the red and blue power ports. func (plc *Plc) GetPowerPorts() ([3]int, [3]int) { return [3]int{ @@ -408,6 +415,11 @@ func (plc *Plc) writeCoils() bool { return false } + if plc.matchResetCycles > 5 { + plc.coils[matchReset] = false // Only need a short pulse to reset the internal state of the PLC. + } else { + plc.matchResetCycles++ + } return true }