Added placeholder LED logic until we know how to interface with the hardware.

This commit is contained in:
Patrick Fairbank
2014-08-18 20:23:30 -07:00
parent 5b8ff606c6
commit 18d24b6d7b
2 changed files with 91 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ package main
import (
"fmt"
"log"
"math/rand"
"time"
)
@@ -85,6 +86,7 @@ type Arena struct {
lastMatchTimeSec float64
savedMatch *Match
savedMatchResult *MatchResult
leftGoalHotFirst bool
}
var mainArena Arena // Named thusly to avoid polluting the global namespace with something more generic.
@@ -129,6 +131,8 @@ func (arena *Arena) Setup() {
arena.savedMatchResult = &MatchResult{}
arena.allianceStationDisplays = make(map[string]string)
arena.allianceStationDisplayScreen = "blank"
SetupLights()
}
// Loads a team into an alliance station, cleaning up the previous team there if there is one.
@@ -375,6 +379,7 @@ func (arena *Arena) Update() {
arena.MatchState = AUTO_PERIOD
arena.matchStartTime = time.Now()
arena.lastMatchTimeSec = -1
arena.leftGoalHotFirst = rand.Intn(2) == 1
auto = true
enabled = true
sendDsPacket = true
@@ -448,6 +453,9 @@ func (arena *Arena) Update() {
// TODO(pat): Come up with better criteria for sending robot status updates.
arena.robotStatusNotifier.Notify(nil)
}
arena.handleLighting("red", arena.redRealtimeScore)
arena.handleLighting("blue", arena.blueRealtimeScore)
}
// Loops indefinitely to track and update the arena components.
@@ -482,3 +490,22 @@ func (realtimeScore *RealtimeScore) Score(opponentFouls []Foul) int {
}
return score
}
// Manipulates the arena LED lighting based on the current state of the match.
func (arena *Arena) handleLighting(alliance string, score *RealtimeScore) {
switch arena.MatchState {
case AUTO_PERIOD:
leftSide := arena.MatchTimeSec() < float64(arena.matchTiming.AutoDurationSec)/2 == arena.leftGoalHotFirst
SetHotGoalLights(alliance, leftSide)
case TELEOP_PERIOD:
if score.AutoLeftoverBalls == 0 && score.CurrentCycle.Assists == 0 {
SetPedestalLight(alliance)
} else {
ClearPedestalLight(alliance)
}
SetAssistGoalLights(alliance, score.CurrentCycle.Assists)
default:
ClearGoalLights(alliance)
ClearPedestalLight(alliance)
}
}

64
lights.go Normal file
View File

@@ -0,0 +1,64 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Methods for controlling the field LED lighting.
package main
import (
"fmt"
)
var hotGoalLights map[string]bool
var assistLights map[string]int
var pedestalLights map[string]bool
func SetupLights() {
hotGoalLights = make(map[string]bool)
assistLights = make(map[string]int)
pedestalLights = make(map[string]bool)
}
func SetHotGoalLights(alliance string, leftSide bool) {
if hotGoalLights[alliance] == leftSide {
return
}
hotGoalLights[alliance] = leftSide
if leftSide {
fmt.Printf("Setting left %s goal hot\n", alliance)
} else {
fmt.Printf("Setting right %s goal hot\n", alliance)
}
}
func SetAssistGoalLights(alliance string, numAssists int) {
if assistLights[alliance] == numAssists {
return
}
assistLights[alliance] = numAssists
if numAssists <= 0 {
fmt.Printf("Clearing %s goal lights\n", alliance)
} else if numAssists < 3 {
fmt.Printf("Setting %s goal to %d assists\n", alliance, numAssists)
} else {
fmt.Printf("Setting %s goal to 3 assists\n", alliance)
}
}
func ClearGoalLights(alliance string) {
SetAssistGoalLights(alliance, 0)
}
func SetPedestalLight(alliance string) {
if pedestalLights[alliance] == false {
pedestalLights[alliance] = true
fmt.Printf("Setting %s pedestal\n", alliance)
}
}
func ClearPedestalLight(alliance string) {
if pedestalLights[alliance] == true {
pedestalLights[alliance] = false
fmt.Printf("Clearing %s pedestal\n", alliance)
}
}