mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Fix issues from testing PLC integration.
This commit is contained in:
@@ -733,9 +733,9 @@ func (arena *Arena) handlePlcInput() {
|
||||
|
||||
// Handle scale and switch ownership.
|
||||
scale, redSwitch, blueSwitch := arena.Plc.GetScaleAndSwitches()
|
||||
arena.Scale.UpdateState(scale, currentTime)
|
||||
arena.RedSwitch.UpdateState(redSwitch, currentTime)
|
||||
arena.BlueSwitch.UpdateState(blueSwitch, currentTime)
|
||||
ownershipChanged := arena.Scale.UpdateState(scale, currentTime)
|
||||
ownershipChanged = arena.RedSwitch.UpdateState(redSwitch, currentTime) || ownershipChanged
|
||||
ownershipChanged = arena.BlueSwitch.UpdateState(blueSwitch, currentTime) || ownershipChanged
|
||||
if arena.MatchState == AutoPeriod {
|
||||
redScore.AutoOwnershipPoints = 2 * int(arena.RedSwitch.GetRedSeconds(matchStartTime, currentTime)+
|
||||
arena.Scale.GetRedSeconds(matchStartTime, currentTime))
|
||||
@@ -773,7 +773,7 @@ func (arena *Arena) handlePlcInput() {
|
||||
arena.PlaySoundNotifier.Notify("match-" + newBluePowerUp)
|
||||
}
|
||||
|
||||
if !oldRedScore.Equals(redScore) || !oldBlueScore.Equals(blueScore) {
|
||||
if !oldRedScore.Equals(redScore) || !oldBlueScore.Equals(blueScore) || ownershipChanged {
|
||||
arena.RealtimeScoreNotifier.Notify(nil)
|
||||
}
|
||||
}
|
||||
@@ -789,8 +789,9 @@ func (arena *Arena) handleLeds() {
|
||||
// Set the stack light state -- blinking green if ready, or solid alliance color(s) if not.
|
||||
redAllianceReady := arena.checkAllianceStationsReady("R1", "R2", "R3") == nil
|
||||
blueAllianceReady := arena.checkAllianceStationsReady("B1", "B2", "B3") == nil
|
||||
greenStackLight := redAllianceReady && blueAllianceReady && arena.Plc.GetCycleState(2, 0, 25)
|
||||
greenStackLight := redAllianceReady && blueAllianceReady && arena.Plc.GetCycleState(2, 0, 2)
|
||||
arena.Plc.SetStackLights(!redAllianceReady, !blueAllianceReady, greenStackLight)
|
||||
arena.Plc.SetStackBuzzer(redAllianceReady && blueAllianceReady)
|
||||
|
||||
// Turn off each alliance switch if all teams become ready.
|
||||
if redAllianceReady && !arena.lastRedAllianceReady {
|
||||
|
||||
@@ -4,9 +4,9 @@ package field
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _coil_name = "heartbeatmatchResetstackLightGreenstackLightOrangestackLightRedstackLightBluered1EthernetDisablered2EthernetDisablered3EthernetDisableblue1EthernetDisableblue2EthernetDisableblue3EthernetDisablecoilCount"
|
||||
const _coil_name = "heartbeatmatchResetstackLightGreenstackLightOrangestackLightRedstackLightBluestackLightBuzzerred1EthernetDisablered2EthernetDisablered3EthernetDisableblue1EthernetDisableblue2EthernetDisableblue3EthernetDisablecoilCount"
|
||||
|
||||
var _coil_index = [...]uint8{0, 9, 19, 34, 50, 63, 77, 96, 115, 134, 154, 174, 194, 203}
|
||||
var _coil_index = [...]uint8{0, 9, 19, 34, 50, 63, 77, 93, 112, 131, 150, 170, 190, 210, 219}
|
||||
|
||||
func (i coil) String() string {
|
||||
if i < 0 || i >= coil(len(_coil_index)-1) {
|
||||
|
||||
@@ -95,6 +95,7 @@ const (
|
||||
stackLightOrange
|
||||
stackLightRed
|
||||
stackLightBlue
|
||||
stackLightBuzzer
|
||||
red1EthernetDisable
|
||||
red2EthernetDisable
|
||||
red3EthernetDisable
|
||||
@@ -208,6 +209,11 @@ func (plc *Plc) SetStackLights(red, blue, green bool) {
|
||||
plc.Coils[stackLightGreen] = green
|
||||
}
|
||||
|
||||
// Set the on/off state of the stack lights on the scoring table.
|
||||
func (plc *Plc) SetStackBuzzer(state bool) {
|
||||
plc.Coils[stackLightBuzzer] = state
|
||||
}
|
||||
|
||||
func (plc *Plc) GetCycleState(max, index, duration int) bool {
|
||||
return plc.cycleCounter/duration%max == index
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@ type Ownership struct {
|
||||
endTime *time.Time
|
||||
}
|
||||
|
||||
// Updates the internal timing state of the scale or switch given the current state of the sensors.
|
||||
func (seesaw *Seesaw) UpdateState(state [2]bool, currentTime time.Time) {
|
||||
// Updates the internal timing state of the scale or switch given the current state of the sensors. Returns true if
|
||||
// ownership has changed since the last cycle.
|
||||
func (seesaw *Seesaw) UpdateState(state [2]bool, currentTime time.Time) bool {
|
||||
ownedBy := NeitherAlliance
|
||||
|
||||
// Check if there is an active force power up for this seesaw.
|
||||
@@ -61,7 +62,9 @@ func (seesaw *Seesaw) UpdateState(state [2]bool, currentTime time.Time) {
|
||||
newOwnership := &Ownership{seesaw: seesaw, ownedBy: ownedBy, startTime: currentTime}
|
||||
seesaw.ownerships = append(seesaw.ownerships, newOwnership)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (seesaw *Seesaw) GetOwnedBy() Alliance {
|
||||
|
||||
Reference in New Issue
Block a user