FRC2706 / 2024-2706-Robot-Code

Code for the 2024 game.
Other
3 stars 0 forks source link

Programming Advantagescope logging #14

Open lchangGH opened 5 months ago

LuisFerArredondo commented 5 months ago

AdvantageKit is a logging, telemetry, and replay framework developed by Team 6328. AdvantageKit enables log replay, where the full state of the robot code can be replayed in simulation based on a log file.

A variety of logging frameworks already exist in FRC, from built-in tools like the Driver Station and WPILib logging all the way to fully custom solutions. Most of these frameworks follow a similar structure, which looks this:

Image

A limited set of values are provided by the robot code and stored in the log. That could include sensor data, PID error, odometry pose, output commands, etc. While this has enormous value, it doesn't solve the eternal sentiment when something goes wrong: "If only we were logging one extra field!" Notice above that there is data flowing in and out of the robot code without being saved to the log file.

AdvantageKit takes a different approach. This is what logging looks like with AdvantageKit:

Image

Instead of logging a limited set of values from the user code, AdvantageKit records all of the data flowing into the robot code. Every sensor value, button press, and much more is logged every loop cycle. After a match, these values can be replayed to the robot code in a simulator. Since every input command is the same, all of the internal logic of the code is replayed exactly. This allows you to log extra fields after the fact, or modify pipelines to see how they would have functioned during the match. This technique means that logging is more than just a tool for checking on specific issues; it's also a safety net that can be used to verify how any part of the code functions.

In other words, we could replay the original logs, along with a new log file generated, which is based on the code that was used in that moment but with the new data generated. When replaying the logs we should not change the behavior of the robot, but we can log new values based on the ones we already have, and see how they would have behaved in that moment.

Code example: Now with advantage kit working https://github.com/LuisFerArredondo/2706_2024.git

LuisFerArredondo commented 5 months ago

Something to point out, is that we would be required to have a USB stick on the RoboRIO's USB port so the code could be logged with advantage kit.

LuisFerArredondo commented 5 months ago

Also another comment on this. If we want to log the battery, Network Table Clients, current commands, etc. We have to add that code manually.

Fortunate enough, out friends from Mechanical Advantage already did that, so we just have to write a similar code(the exact same) of what they have in theirs, but in ours.

LuisFerArredondo commented 5 months ago

To be implement it into the code, the recommended way is:

  1. For each mechanism, there should be 3 types of files:

    • The high level programming file(Here the callout of the Logger will occur)
    • The IO Layer, which is the bridge of communication between the high level programming file and the hardware/simulator files
    • The hardware/simulator file
  2. In the "RobotContainer" is where we will define whether is simulation, real or replay, so the mechanism knows which file to use

  3. The Logger and Log writing must be set up in the "Robot" file