Add PLC integration for field sensors, motors, and lights.

This commit is contained in:
Patrick Fairbank
2017-09-03 20:51:20 -07:00
parent fa70323b85
commit d5ec68b77e
23 changed files with 713 additions and 59 deletions

View File

@@ -98,7 +98,7 @@ func (web *Web) audienceDisplayWebsocketHandler(w http.ResponseWriter, r *http.R
BlueScore *game.Score
RedScoreSummary *game.ScoreSummary
BlueScoreSummary *game.ScoreSummary
}{web.arena.RedRealtimeScore.CurrentScore, web.arena.BlueRealtimeScore.CurrentScore,
}{&web.arena.RedRealtimeScore.CurrentScore, &web.arena.BlueRealtimeScore.CurrentScore,
web.arena.RedScoreSummary(), web.arena.BlueScoreSummary()}
err = websocket.Write("realtimeScore", data)
if err != nil {
@@ -160,7 +160,7 @@ func (web *Web) audienceDisplayWebsocketHandler(w http.ResponseWriter, r *http.R
BlueScore *game.Score
RedScoreSummary *game.ScoreSummary
BlueScoreSummary *game.ScoreSummary
}{web.arena.RedRealtimeScore.CurrentScore, web.arena.BlueRealtimeScore.CurrentScore,
}{&web.arena.RedRealtimeScore.CurrentScore, &web.arena.BlueRealtimeScore.CurrentScore,
web.arena.RedScoreSummary(), web.arena.BlueScoreSummary()}
case _, ok := <-scorePostedListener:
if !ok {

View File

@@ -415,7 +415,7 @@ func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request
}
// Send out the status again after handling the command, as it most likely changed as a result.
err = websocket.Write("status", web.arena)
err = websocket.Write("status", web.arena.GetStatus())
if err != nil {
log.Printf("Websocket error: %s", err)
return
@@ -541,7 +541,7 @@ func (web *Web) commitMatchScore(match *model.Match, matchResult *model.MatchRes
func (web *Web) getCurrentMatchResult() *model.MatchResult {
return &model.MatchResult{MatchId: web.arena.CurrentMatch.Id, MatchType: web.arena.CurrentMatch.Type,
RedScore: web.arena.RedRealtimeScore.CurrentScore, BlueScore: web.arena.BlueRealtimeScore.CurrentScore,
RedScore: &web.arena.RedRealtimeScore.CurrentScore, BlueScore: &web.arena.BlueRealtimeScore.CurrentScore,
RedCards: web.arena.RedRealtimeScore.Cards, BlueCards: web.arena.BlueRealtimeScore.Cards}
}

View File

@@ -129,8 +129,8 @@ func (web *Web) matchReviewEditPostHandler(w http.ResponseWriter, r *http.Reques
if isCurrent {
// If editing the current match, just save it back to memory.
web.arena.RedRealtimeScore.CurrentScore = matchResult.RedScore
web.arena.BlueRealtimeScore.CurrentScore = matchResult.BlueScore
web.arena.RedRealtimeScore.CurrentScore = *matchResult.RedScore
web.arena.BlueRealtimeScore.CurrentScore = *matchResult.BlueScore
web.arena.RedRealtimeScore.Cards = matchResult.RedCards
web.arena.BlueRealtimeScore.Cards = matchResult.BlueCards

View File

@@ -6,6 +6,7 @@
package web
import (
"github.com/Team254/cheesy-arena/field"
"github.com/Team254/cheesy-arena/model"
"net/http"
)
@@ -24,7 +25,12 @@ func (web *Web) fieldGetHandler(w http.ResponseWriter, r *http.Request) {
data := struct {
*model.EventSettings
AllianceStationDisplays map[string]string
}{web.arena.EventSettings, web.arena.AllianceStationDisplays}
FieldTestMode string
Inputs []bool
Counters []uint16
Coils []bool
}{web.arena.EventSettings, web.arena.AllianceStationDisplays, web.arena.FieldTestMode, web.arena.Plc.Inputs[:],
web.arena.Plc.Counters[:], web.arena.Plc.Coils[:]}
err = template.ExecuteTemplate(w, "base", data)
if err != nil {
handleWebErr(w, err)
@@ -54,3 +60,64 @@ func (web *Web) fieldReloadDisplaysHandler(w http.ResponseWriter, r *http.Reques
web.arena.ReloadDisplaysNotifier.Notify(nil)
http.Redirect(w, r, "/setup/field", 303)
}
// Controls the field LEDs for testing or effect.
func (web *Web) fieldTestPostHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) {
return
}
if web.arena.MatchState != field.PreMatch {
http.Error(w, "Arena must be in pre-match state", 400)
return
}
mode := r.PostFormValue("mode")
switch mode {
case "boiler":
web.arena.Plc.SetBoilerMotors(true)
web.arena.Plc.SetRotorMotors(0, 0)
web.arena.Plc.SetRotorLights(0, 0)
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{false, false, false})
case "rotor1":
web.arena.Plc.SetBoilerMotors(false)
web.arena.Plc.SetRotorMotors(1, 1)
web.arena.Plc.SetRotorLights(1, 1)
web.arena.Plc.SetTouchpadLights([3]bool{true, false, false}, [3]bool{true, false, false})
case "rotor2":
web.arena.Plc.SetBoilerMotors(false)
web.arena.Plc.SetRotorMotors(2, 2)
web.arena.Plc.SetRotorLights(2, 2)
web.arena.Plc.SetTouchpadLights([3]bool{false, true, false}, [3]bool{false, true, false})
case "rotor3":
web.arena.Plc.SetBoilerMotors(false)
web.arena.Plc.SetRotorMotors(3, 3)
web.arena.Plc.SetRotorLights(2, 2)
web.arena.Plc.SetTouchpadLights([3]bool{false, false, true}, [3]bool{false, false, true})
case "rotor4":
web.arena.Plc.SetBoilerMotors(false)
web.arena.Plc.SetRotorMotors(4, 4)
web.arena.Plc.SetRotorLights(2, 2)
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{false, false, false})
case "red":
web.arena.Plc.SetBoilerMotors(false)
web.arena.Plc.SetRotorMotors(4, 0)
web.arena.Plc.SetRotorLights(2, 0)
web.arena.Plc.SetTouchpadLights([3]bool{true, true, true}, [3]bool{false, false, false})
case "blue":
web.arena.Plc.SetBoilerMotors(false)
web.arena.Plc.SetRotorMotors(0, 4)
web.arena.Plc.SetRotorLights(0, 2)
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{true, true, true})
case "flash":
fallthrough
default:
web.arena.Plc.SetBoilerMotors(false)
web.arena.Plc.SetRotorMotors(0, 0)
web.arena.Plc.SetRotorLights(0, 0)
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{false, false, false})
}
web.arena.FieldTestMode = mode
http.Redirect(w, r, "/setup/field", 303)
}

View File

@@ -23,10 +23,7 @@ func TestSetupField(t *testing.T) {
assert.Contains(t, recorder.Body.String(), "12345")
assert.Contains(t, recorder.Body.String(), "selected")
// TODO(patrick): Replace with PLC mode.
/*
recorder = web.postHttpResponse("/setup/field/lights", "mode=strobe")
assert.Equal(t, 303, recorder.Code)
assert.Equal(t, "strobe", web.arena.Lights.currentMode)
*/
recorder = web.postHttpResponse("/setup/field/test", "mode=rotor2")
assert.Equal(t, 303, recorder.Code)
assert.Equal(t, "rotor2", web.arena.FieldTestMode)
}

View File

@@ -64,6 +64,7 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
eventSettings.SwitchAddress = r.PostFormValue("switchAddress")
eventSettings.SwitchPassword = r.PostFormValue("switchPassword")
eventSettings.BandwidthMonitoringEnabled = r.PostFormValue("bandwidthMonitoringEnabled") == "on"
eventSettings.PlcAddress = r.PostFormValue("plcAddress")
eventSettings.AdminPassword = r.PostFormValue("adminPassword")
eventSettings.ReaderPassword = r.PostFormValue("readerPassword")

View File

@@ -150,6 +150,7 @@ func (web *Web) newHandler() http.Handler {
router.HandleFunc("/setup/field", web.fieldGetHandler).Methods("GET")
router.HandleFunc("/setup/field", web.fieldPostHandler).Methods("POST")
router.HandleFunc("/setup/field/reload_displays", web.fieldReloadDisplaysHandler).Methods("GET")
router.HandleFunc("/setup/field/test", web.fieldTestPostHandler).Methods("POST")
router.HandleFunc("/setup/lower_thirds", web.lowerThirdsGetHandler).Methods("GET")
router.HandleFunc("/setup/lower_thirds/websocket", web.lowerThirdsWebsocketHandler).Methods("GET")
router.HandleFunc("/setup/sponsor_slides", web.sponsorSlidesGetHandler).Methods("GET")