-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start (v2)
Want to jump right in? This page provides some setup instructions and really basic examples.
Adding this library to your Gradle project is fairly simple. Since this project is not yet on Maven Central, you'll need to download a jar of the latest release from the Releases page, in this case version 2.2.0-alpha. Put the jar in a directory, say lib
, and add this line to your build.gradle
's dependencies
:
compile files("lib/RobotPathfinder-2.2.0-alpha.jar")
Your build.gradle
should then look something like this (example with FRC):
dependencies {
compile wpi.deps.wpilib()
compile wpi.deps.vendor.java()
compile files("lib/RobotPathfinder-2.2.0-alpha.jar")
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
testCompile 'junit:junit:4.12'
}
With every release, there will be 2 Jars, one named RobotPathfinder-VERSION.jar
and one named RobotPathfinder-VERSION-all.jar
. The former is recommended for use on an FRC robot or a production environment. It only contains the dependencies required for the core functionality of the library, while the latter is a fat jar, which also contains dependencies for tools such as a grapher and visualizer application.
This example program uses a set of robot specifications and path parameters to generate a trajectory. The trajectory is then displayed using Swing and JMathPlot. This demo requires the fat jar (RobotPathfinder-VERSION-all.jar
). An in-depth explanation of this example can be found in the next pages.
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import robot.pathfinder.core.RobotSpecs;
import robot.pathfinder.core.TrajectoryParams;
import robot.pathfinder.core.Waypoint;
import robot.pathfinder.core.trajectory.BasicTrajectory;
import robot.pathfinder.core.trajectory.TankDriveTrajectory;
import robot.pathfinder.tools.Grapher;
/**
* This example program generates a trajectory, graphs it, and displays it in a window.
* @author Tyler Tian
*
*/
public class TrajectoryGenerationDemo {
public static void main(String[] args) {
// Did you know that this trajectory generation code can be generated by the trajectory visualization tool?
// Give it a try!
// To create a trajectory, first we need the robot specifications object
// The hypothetical robot has max speed of 8 ft/sec, max acceleration of 6 ft/sec and a base plate 2 feet wide
RobotSpecs robotSpecs = new RobotSpecs(8.0, 6.0, 2.0);
// Now create the trajectory parameters object
TrajectoryParams params = new TrajectoryParams();
// Specify the waypoints
// Note that all angles are in radians!
params.waypoints = new Waypoint[] {
// Try changing these and see what happens!
new Waypoint(0.0, 0.0, Math.PI / 2),
new Waypoint(-10.0, 14.0, Math.PI / 2),
new Waypoint(0.0, 25.0, 0.0),
};
// The "alpha" value is the turn smoothness constant. For more information, see its documentation.
// Try tweaking this value and see what happens!
params.alpha = 20.0;
// Since we want a tank drive trajectory, set this to true
params.isTank = true;
// Finally, generate the trajectory
TankDriveTrajectory trajectory = new TankDriveTrajectory(new BasicTrajectory(robotSpecs, params));
// Now that we have the trajectory, graph it using the Grapher utility class, and show it
JFrame pathGraph = Grapher.graphPath(trajectory.getPath(), 0.01);
JFrame trajectoryGraph = Grapher.graphTrajectory(trajectory, 0.01);
// Since swing is not thread safe, the windows have to be shown on the EDT
SwingUtilities.invokeLater(() -> {
pathGraph.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
trajectoryGraph.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pathGraph.setVisible(true);
trajectoryGraph.setVisible(true);
});
}
}