Skip to content

Commit

Permalink
Add A-Stop to DS protocol and logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed May 12, 2024
1 parent d093474 commit 55f9c47
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ func (arena *Arena) sendDsPacket(auto bool, enabled bool) {
dsConn.Enabled = enabled && !allianceStation.EStop && !(auto && allianceStation.AStop) &&
!allianceStation.Bypass
dsConn.EStop = allianceStation.EStop
dsConn.AStop = allianceStation.AStop
err := dsConn.update(arena)
if err != nil {
log.Printf("Unable to send driver station packet for team %d.", allianceStation.Team.Id)
Expand Down
6 changes: 6 additions & 0 deletions field/arena_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ func TestPlcEStopAStop(t *testing.T) {
arena.lastDsPacketTime = time.Unix(0, 0) // Force a DS packet.
arena.Update()
assert.Equal(t, false, arena.AllianceStations["R1"].DsConn.Enabled)
assert.Equal(t, false, arena.AllianceStations["R1"].DsConn.EStop)
assert.Equal(t, true, arena.AllianceStations["R1"].DsConn.AStop)
assert.Equal(t, true, arena.AllianceStations["R2"].DsConn.Enabled)

// Unpress the R1 A-stop and press the R2 E-stop.
Expand All @@ -708,7 +710,11 @@ func TestPlcEStopAStop(t *testing.T) {
arena.lastDsPacketTime = time.Unix(0, 0) // Force a DS packet.
arena.Update()
assert.Equal(t, false, arena.AllianceStations["R1"].DsConn.Enabled)
assert.Equal(t, false, arena.AllianceStations["R1"].DsConn.EStop)
assert.Equal(t, true, arena.AllianceStations["R1"].DsConn.AStop)
assert.Equal(t, false, arena.AllianceStations["R2"].DsConn.Enabled)
assert.Equal(t, true, arena.AllianceStations["R2"].DsConn.EStop)
assert.Equal(t, false, arena.AllianceStations["R2"].DsConn.AStop)

// Unpress the R2 E-stop.
plc.redAStops[0] = false
Expand Down
5 changes: 4 additions & 1 deletion field/driver_station_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type DriverStationConnection struct {
Auto bool
Enabled bool
EStop bool
AStop bool
DsLinked bool
RadioLinked bool
RioLinked bool
Expand Down Expand Up @@ -176,6 +177,9 @@ func (dsConn *DriverStationConnection) encodeControlPacket(arena *Arena) [22]byt
if dsConn.EStop {
packet[3] |= 0x80
}
if dsConn.AStop {
packet[3] |= 0x40
}

// Unknown or unused.
packet[4] = 0
Expand Down Expand Up @@ -258,7 +262,6 @@ func (dsConn *DriverStationConnection) decodeStatusPacket(data [36]byte) {

// Number of missed packets sent from the DS to the robot.
dsConn.MissedPacketCount = int(data[2]) - dsConn.missedPacketOffset

}

// Listens for TCP connection requests to Cheesy Arena from driver stations.
Expand Down
4 changes: 4 additions & 0 deletions field/driver_station_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func TestEncodeControlPacket(t *testing.T) {
data = dsConn.encodeControlPacket(arena)
assert.Equal(t, byte(132), data[3])

dsConn.AStop = true
data = dsConn.encodeControlPacket(arena)
assert.Equal(t, byte(196), data[3])

// Check different match types.
arena.CurrentMatch.Type = model.Practice
data = dsConn.encodeControlPacket(arena)
Expand Down
10 changes: 7 additions & 3 deletions field/team_match_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ func NewTeamMatchLog(teamId int, match *model.Match, wifiStatus *network.TeamWif
}

log := TeamMatchLog{log.New(logFile, "", 0), logFile, wifiStatus}
log.logger.Println("matchTimeSec,packetType,teamId,allianceStation,dsLinked,radioLinked,rioLinked,robotLinked,auto,enabled," +
"emergencyStop,batteryVoltage,missedPacketCount,dsRobotTripTimeMs,rxRate,txRate,signalNoiseRatio")
log.logger.Println(
"matchTimeSec,packetType,teamId,allianceStation,dsLinked,radioLinked,rioLinked,robotLinked,auto,enabled," +
"emergencyStop,autonomousStop,batteryVoltage,missedPacketCount,dsRobotTripTimeMs,rxRate,txRate," +
"signalNoiseRatio",
)

return &log, nil
}

// Adds a line to the log when a packet is received.
func (log *TeamMatchLog) LogDsPacket(matchTimeSec float64, packetType int, dsConn *DriverStationConnection) {
log.logger.Printf(
"%f,%d,%d,%s,%v,%v,%v,%v,%v,%v,%v,%f,%d,%d,%f,%f,%d",
"%f,%d,%d,%s,%v,%v,%v,%v,%v,%v,%v,%v,%f,%d,%d,%f,%f,%d",
matchTimeSec,
packetType,
dsConn.TeamId,
Expand All @@ -60,6 +63,7 @@ func (log *TeamMatchLog) LogDsPacket(matchTimeSec float64, packetType int, dsCon
dsConn.Auto,
dsConn.Enabled,
dsConn.EStop,
dsConn.AStop,
dsConn.BatteryVoltage,
dsConn.MissedPacketCount,
dsConn.DsRobotTripTimeMs,
Expand Down
4 changes: 3 additions & 1 deletion templates/view_match_log.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ <h3>Match Log: {{.Match.ShortName}} - {{ .MatchLogs.TeamId}} ({{.MatchLogs.Allia
<th>Robot Linked</th>
<th>Mode</th>
<th>Enabled</th>
<th>E-Stop</th>
<th class="nowrap">E-Stop</th>
<th class="nowrap">A-Stop</th>
<th>Voltage</th>
<th>Missed Packets</th>
<th>Latency</th>
Expand All @@ -50,6 +51,7 @@ <h3>Match Log: {{.Match.ShortName}} - {{ .MatchLogs.TeamId}} ({{.MatchLogs.Allia
<td>{{if $row.Auto}}Auto{{else}}Telop{{end}}</td>
<td>{{$row.Enabled}}</td>
<td>{{$row.EmergencyStop}}</td>
<td>{{$row.AutonomousStop}}</td>
<td>{{printf "%.3f" $row.BatteryVoltage}}</td>
<td>{{$row.MissedPacketCount}}</td>
<td>{{$row.DsRobotTripTimeMs}}</td>
Expand Down
2 changes: 2 additions & 0 deletions web/match_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type MatchLogRow struct {
Auto bool
Enabled bool
EmergencyStop bool
AutonomousStop bool
BatteryVoltage float64
MissedPacketCount int
DsRobotTripTimeMs int
Expand Down Expand Up @@ -206,6 +207,7 @@ func (web *Web) getMatchLogFromRequest(r *http.Request) (*model.Match, *MatchLog
curRow.Auto, _ = strconv.ParseBool(record[headerMap["auto"]])
curRow.Enabled, _ = strconv.ParseBool(record[headerMap["enabled"]])
curRow.EmergencyStop, _ = strconv.ParseBool(record[headerMap["emergencyStop"]])
curRow.AutonomousStop, _ = strconv.ParseBool(record[headerMap["autonomousStop"]])
curRow.BatteryVoltage, _ = strconv.ParseFloat(record[headerMap["batteryVoltage"]], 64)
curRow.MissedPacketCount, _ = strconv.Atoi(record[headerMap["missedPacketCount"]])
curRow.DsRobotTripTimeMs, _ = strconv.Atoi(record[headerMap["dsRobotTripTimeMs"]])
Expand Down

0 comments on commit 55f9c47

Please sign in to comment.