Helpful Links:
https://github.com/Mechanical-Advantage
AdvantageScope is a simulation tool that allows us to simulate our code and also use logs from matches to simulate the matches.
AdvantageKit is a logging tool that interfaces with AdvantageScope.
1) Open up your VSCode project and this link (AdvantageKit install instructions)
AdvantageKit is available through GitHub Packages. To make our Maven repository available through Gradle, add the following block to the build.gradle file:
repositories {
maven {
url = uri("https://maven.pkg.github.com/Mechanical-Advantage/AdvantageKit")
credentials {
username = "Mechanical-Advantage-Bot"
password = "\u0067\u0068\u0070\u005f\u006e\u0056\u0051\u006a\u0055\u004f\u004c\u0061\u0079\u0066\u006e\u0078\u006e\u0037\u0051\u0049\u0054\u0042\u0032\u004c\u004a\u006d\u0055\u0070\u0073\u0031\u006d\u0037\u004c\u005a\u0030\u0076\u0062\u0070\u0063\u0051"
}
}
}
Downloading packages from GitHub requires authentication, even for public repositories. The configuration above includes an access token so that anyone can download AdvantageKit. The obfuscation of the string hides it from GitHub's bot; DO NOT INCLUDE THE PLAIN TEXT TOKEN IN ANY GITHUB REPOSITORY. This will cause the token to be automatically revoked and prevent anyone from downloading AdvantageKit.
AdvantageKit uses WPILib shims to inject data. Add the following block to build.gradle to replace the default implementation. This is required for the framework to function
configurations.all {
exclude group: "edu.wpi.first.wpilibj"
}
To install the main AdvantageKit packages, go to "WPILib: Manage Vendor Libraries" > "Install new libraries (online)" and paste in the URL below. The changelog for the latest release) includes the WPILib version on which it is based; you must use the same version in your robot project. You can check the selected version of WPILib at the top of build.gradle after "edu.wpi.first.GradleRIO".
https://github.com/Mechanical-Advantage/AdvantageKit/releases/latest/download/AdvantageKit.json
The main Robot class must inherit from LoggedRobot (see below). LoggedRobot performs the same functions as TimedRobot, with some exceptions:
It does not support adding extra periodic functions.
The method setUseTiming allows the user code to disable periodic timing and run cycles as fast as possible during replay. The timestamp read by methods like Timer.getFPGATimstamp() will still match the timestamp from the real robot.
public class Robot extends LoggedRobot {
...
}
The user program is responsible for configuring and initializing the logging framework. This setup should be placed in robotInit() before any other initialization. An example configuration is provided below:
Logger.getInstance().recordMetadata("ProjectName", "MyProject"); // Set a metadata value
if (isReal()) {
Logger.getInstance().addDataReceiver(new WPILOGWriter("/media/sda1/")); // Log to a USB stick
Logger.getInstance().addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
new PowerDistribution(1, ModuleType.kRev); // Enables power distribution logging
} else {
setUseTiming(false); // Run as fast as possible
String logPath = LogFileUtil.findReplayLog(); // Pull the replay log from AdvantageScope (or prompt the user)
Logger.getInstance().setReplaySource(new WPILOGReader(logPath)); // Read replay log
Logger.getInstance().addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim"))); // Save outputs to a new log
}
Logger.getInstance().start(); // Start logging! No more data receivers, replay sources, or metadata values may be added.
This setup enters replay mode for all simulator runs. If you need to run the simulator without replay (e.g. a physics simulator or Romi), extra constants or selection logic is required.
The @AutoLog annotation automatically generates classes for input logging from subsystems. To install @AutoLog, modify your build.gradle to include:
dependencies {
// ...
annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:<version>"
}
We recommend using the gversion Gradle plugin to record metadata like the git hash and build date. To install it, add the plugin at the top of build.gradle:
plugins {
// ...
id "com.peterabeles.gversion" version "1.10"
}
Add the createVersionFile task as a dependency of compileJava:
project.compileJava.dependsOn(createVersionFile)
gversion {
srcDir = "src/main/java/"
classPackage = "frc.robot"
className = "BuildConstants"
dateFormat = "yyyy-MM-dd HH:mm:ss z"
timeZone = "America/New_York" // Use preferred time zone
indent = " "
}
You should also add the BuildConstants.java file to the repository .gitignore:
src/main/java/frc/robot/BuildConstants.java
2) Follow through the website and add the changes in each file to your code
Most changes are in build.gradle and Robot.java
3) Add logging throughout your code to send log data to AdvantageScope
4) To log things to the AdvantageKit section of AdvantageScope use: Logger.putNumber(“FileName/whatYou’reLogging”, variable for thing you’re logging);
- “FileName” will show up as a tab under the AdvantageKit tab in AdvantageScope. Your variable will appear under the “FileName” tab
- Make sure you import the littltonrobotics Logger and not a different one
- You can also use recordMetadata or any other method in the Logger class
5) To log to the SmartDashboard tab in AdvantageScope use: SmartDashboard.putNumber(“FileName/whatYou’reLogging”, variable for thing you’re logging);
NOTE: You might have to do a lot of debugging and adding odometry, pose2D, and logging in different/more spots (Especially if you’re trying to simulate without robot data. It’s ok, you can do this!!!!)
1) Download this absolutely-not-a-virus link for AdvantageScope
Download the win-x64 one!!!
2) This should open an application that looks like this (Ed is watching, look busy!)
3) Click the plus sign in the top right corner, you can pick from different visuals like graphs, statistics, and 2D and 3D models of the field.
4) Connect AdvantageScope to the simulator.
Run simulator in VSCode, once loaded click “file” in AdvantageScope and then click “connect to simulation”
5) A menu appears on the left full of options.
Click “AdvantageKit” then click “LiveOutputs”
Under “LiveOutputs” should have what you named your Pose2D logs in the code, like “Robot” or “DriveTrainOdometry”
5) Drag the name of you logs over to the 2D section along the bottom to see your values in the simulation
6) If you change your simulation to autonomous (if you have paths), the robot should move in AdvantageScope on its own. You also should be able to change the simulation to Teleop and use a controller to move the robot in AdvantageScope.