- OpenCSV (tested on 4.1)
- Apache Commons Lang (tested on 3.7)
- WPILibJ
- Cross The Road Electronics Phoenix Lib(5.8.1)
- Download the latest release of SharkMacro from here.
- Download Apache Commons Lang from here.
- Download OpenCSV from here.
- Repeat the process below for each downloaded file:
- Copy the downloaded file to
C:\Users\<YourUser>\wpilib\user\java\lib
. - Right click on your robot code project in Eclipse > Build Path > Add External Archives...
- Select the file just copied to
lib
.
- Copy the downloaded file to
-
In order to play back recorded motion profiles, the Talons' PID must be tuned for your drivetrain.
-
Configure left and right talon settings
-
SharkMacro uses 10ms trajectory points by default so no extra trajectory time must be added:
talon.configMotionProfileTrajectoryPeriod(0, 0);
-
Correct feedback sensor must be set:
talon.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0);
-
Sensor values will not be updated fast enough for the recorder unless the feedback status frame is set manually:
talon.setStatusFramePeriod(StatusFrameEnhanced.Status_2_Feedback0, 5, 0);
-
- Record a profile
ProfileRecorder recorder = new ProfileRecorder(leftTalon, rightTalon, RecordingType.VOLTAGE/VELOCITY); recorder.start();
- Save a profile to file
Profile p = recorder.stop().toProfile(); ProfileParser parser = new ProfileParser(filename); parser.writeToFile(p);
- Load and play a profile from file
ProfileParser parser = new ProfileParser(filenameToLoad); Profile p = parser.toObject(leftTalon, rightTalon, leftPIDSlotIdx, rightPIDSlotIdx); p.execute();
Teams can use a Command to toggle recording:
public class ToggleProfileRecording extends InstantCommand {
public ToggleProfileRecording() {
super();
requires(Robot.driveTrain);
}
protected void initialize() {
Robot.driveTrain.toggleRecording();
}
}
In this example the logic for toggling the motion profile recording is contained in the DriveTrain subsystem.
public class DriveTrain extends Subsystem {
private TalonSRX leftTalon = new TalonSRX(RobotMap.DT_FL_MOTOR);
private TalonSRX rightTalon = new TalonSRX(RobotMap.DT_FR_MOTOR);
private ProfileRecorder r = new ProfileRecorder(leftTalon, rightTalon, RecordingType.VOLTAGE);
public void toggleRecording() {
if (r.isRecording()) {
ProfileParser p = new ProfileParser(ProfileParser.getNewFilename());
p.writeToFile(r.stop().toProfile(leftPIDSlotIdx, rightPIDSlotIdx));
} else {
// Zero both encoders before recording
leftTalon.setSelectedSensorPosition(0, 0, 0);
rightTalon.setSelectedSensorPosition(0, 0, 0);
r.start();
}
}
}
SharkMacro's action recording framework piggybacks off of the WPILib Command system, meaning teams won't have to learn a new format for robot commands.
All robot commands that are going to be recorded should extend SharkMacro.RecordableCommand
instead of Command
and should call super.initialize()
in initialize()
, super.end()
in end()
, and super.interrupted()
in interrupted()
.
Example command class:
public class ExampleCommand extends RecordableCommand {
public ExampleCommand() {
}
protected void initialize() {
super.initialize();
// Your code here
}
protected void execute() {
}
protected boolean isFinished() {
return false;
}
protected void end() {
super.end();
// Your code here
}
protected void interrupted() {
super.interrupted();
// Your code here
}
}
- Record a list of actions
ActionRecorder.start(); // Run your commands as usual...
- Save a list of actions to file
ActionListParser parser = new ActionListParser(filename); parser.writeToFile(ActionRecorder.stop());
- Load and play a list of actions from file
ActionListParser parser = new ActionListParser(filenameToLoad); ActionList al = parser.toObject(); al.execute();
Teams can use a Command to toggle recording:
public class ToggleActionRecording extends InstantCommand {
public ToggleActionRecording() {
super();
}
protected void initialize() {
Robot.driveTrain.toggleActionRecording();
}
}
In this example the logic for toggling the action recording is contained in the DriveTrain subsystem.
public class DriveTrain extends Subsystem {
public void toggleActionRecording() {
if (ActionRecorder.isRecording()) {
ActionListParser al = new ActionListParser(ActionListParser.getNewFilename());
al.writeToFile(ActionRecorder.stop());
} else {
ActionRecorder.start();
}
}
}
SharkMacro saves profiles directly to the roboRIO internal storage
-
Motion profiles:
/home/lvuser/profiles
-
Action lists:
/home/lvuser/actionlists
You can access the saved files via the roboRIO web dashboard's file system browser, but it is recommended that you use an external SFTP client such as WinSCP.
The default naming convention for files saved by SharkMacro is:
prefix####.csv
Where prefix is the specific keyword for each type of recorded file.
-
Motion profiles:
profile
-
Action lists:
actionlist
And ####
is the number of the saved file, starting with 0001
.
So, three motion profiles saved with the SharkMacro naming convention would look like:
profile0001.csv
profile0002.csv
profile0003.csv
There are a couple different methods that can be used to access/generate SharkMacro-named files.
-
ProfileParser.getNewFilename()
&ActionListParser.getNewFilename()
- Generates a new filename in the SharkMacro convention by looking through the directory for already-existing files and returning a filename with a number equal to the current greatest number plus one. For example, callingProfileParser.getNewFilename()
with the motion profile save directory containing-
profile0001.csv
-
profile0002.csv
-
profile0003.csv
would return
profile0004
.
-
-
ProfileParser.getNewestFilename()
&ActionListParser.getNewestFilename()
- Get the filename of the current newest (highest numbered) file in the save directory. For example, callingProfileParser.getNewestFilename()
with the motion profile save directory containingprofile0001.csv
profile0002.csv
profile0003.csv
would return profile0003
.
-
Be sure to have your code call
actionList.execute()
andprofile.execute()
at the same time. If not called close to simultaneously, the robot's movement and its actions will be out of sync. -
Be sure to set PID gains in the talons that will be playing back your recorded profile. Not much, if any, PID tuning is required with motion profiling. I found that a P gain of between 0.5 and 1.5 on both talons and I, D and F gains of 0 worked well. (Tested on 4-CIM West Coast drivetrain with a total robot weight of ~100 lbs.)