mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Implement PLC integration for the shield generator rung.
This commit is contained in:
@@ -7,6 +7,12 @@ package game
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
powerPortAutoGracePeriodSec = 5
|
||||
powerPortTeleopGracePeriodSec = 5
|
||||
rungAssessmentDelaySec = 5
|
||||
)
|
||||
|
||||
var MatchTiming = struct {
|
||||
WarmupDurationSec int
|
||||
AutoDurationSec int
|
||||
@@ -25,7 +31,18 @@ func GetDurationToTeleopStart() time.Duration {
|
||||
time.Second
|
||||
}
|
||||
|
||||
func GetDurationToWarning() time.Duration {
|
||||
return time.Duration(MatchTiming.WarmupDurationSec+MatchTiming.AutoDurationSec+MatchTiming.PauseDurationSec+
|
||||
MatchTiming.TeleopDurationSec-MatchTiming.WarningRemainingDurationSec) * time.Second
|
||||
}
|
||||
|
||||
func GetDurationToTeleopEnd() time.Duration {
|
||||
return time.Duration(MatchTiming.WarmupDurationSec+MatchTiming.AutoDurationSec+MatchTiming.PauseDurationSec+
|
||||
MatchTiming.TeleopDurationSec) * time.Second
|
||||
}
|
||||
|
||||
// Returns true if the given time is within the proper range for assessing the level state of the shield generator rung.
|
||||
func ShouldAssessRung(matchStartTime, currentTime time.Time) bool {
|
||||
return currentTime.After(matchStartTime.Add(GetDurationToWarning())) &&
|
||||
currentTime.Before(matchStartTime.Add(GetDurationToTeleopEnd()+rungAssessmentDelaySec*time.Second))
|
||||
}
|
||||
|
||||
18
game/match_timing_test.go
Normal file
18
game/match_timing_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2020 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
|
||||
package game
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestShouldAssessRung(t *testing.T) {
|
||||
assert.Equal(t, false, ShouldAssessRung(matchStartTime, timeAfterStart(0)))
|
||||
assert.Equal(t, false, ShouldAssessRung(matchStartTime, timeAfterStart(121.9)))
|
||||
assert.Equal(t, true, ShouldAssessRung(matchStartTime, timeAfterStart(122.1)))
|
||||
assert.Equal(t, true, ShouldAssessRung(matchStartTime, timeAfterStart(152.1)))
|
||||
assert.Equal(t, true, ShouldAssessRung(matchStartTime, timeAfterStart(156.9)))
|
||||
assert.Equal(t, false, ShouldAssessRung(matchStartTime, timeAfterStart(157.1)))
|
||||
}
|
||||
@@ -9,11 +9,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
powerPortAutoGracePeriodSec = 5
|
||||
powerPortTeleopGracePeriodSec = 5
|
||||
)
|
||||
|
||||
type PowerPort struct {
|
||||
AutoCellsBottom [2]int
|
||||
AutoCellsOuter [2]int
|
||||
|
||||
Reference in New Issue
Block a user