Send reset signal to PLC on match load and again on match start.

This commit is contained in:
Patrick Fairbank
2020-04-14 20:09:09 -07:00
parent 4e74a7a4cd
commit ad509aed5a
2 changed files with 14 additions and 0 deletions

View File

@@ -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
}