use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.
the class ExampleSpline method run.
public void run() {
// before anything else, we have to get some stuff set up.
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
// alright! trajectory time! let's see what's up.
// as you can see, this is mostly pretty self-explanatory.
// you create an AdvancedSplineTrajectoryBuilder and use the
// add methods provided by that class to construct a trajectory.
// this method works well, but it's a bit verbose - there's a
// solution to that problem you'll see in just a moment.
Trajectory trajectory1 = new AdvancedSplineTrajectoryBuilder().setSpeed(0.5).setStep(0.1).setTolerance(2).setAngleTolerance(Angle.fromDeg(5)).add(new PointXYZ(0, 0, 0)).add(new PointXYZ(4, 6, 0)).add(new PointXYZ(6, 12, 0)).add(new PointXYZ(8, 24, 0)).build();
Trajectory trajectory2 = new AdvancedSplineTrajectoryBuilder().setSpeed(0.5).setStep(0.1).setTolerance(2).setAngleTolerance(Angle.fromDeg(5)).add(new PointXYZ(8, 24, 0)).add(new PointXYZ(6, 36, 0)).add(new PointXYZ(4, 40, 0)).add(new PointXYZ(0, 42, 0)).build();
// thankfully, there's an easier way to create trajectories just like
// that - we can make use of a "SplineBuilderFactory"
SplineBuilderFactory factory = new SplineBuilderFactory().setSpeed(0.5).setStep(0.1).setTolerance(2).setAngleTolerance(Angle.fromDeg(5));
// set the default speed, step, tolerance, and angle tolerance
// values for the factory. all of the spline builders produced by
// the factory will have have these values by default.
// now we can create new trajectories, without having to repeat
// the same 4 lines for each of the trajectories.
Trajectory trajectory3 = factory.builder().add(0, 60, Angle.fromDeg(0)).add(new PointXYZ(20, 60, 0)).add(new PointXYZ(30, 60, 0)).add(new PointXYZ(40, 70, 0)).build();
Trajectory trajectory4 = factory.builder().add(new PointXYZ(40, 70, 0)).add(new PointXYZ(30, 60, 0)).add(new PointXYZ(20, 60, 0)).add(0, 60, Angle.fromDeg(0)).build();
// time to actually make the robot move now! once again, most of
// these methods are fairly self-explanatory. basically, follow
// the first two trajectories, come to a complete stop, and then
// follow the next two trajectories, but each of those trajectories
// should have an individual timeout of 10 seconds.
pathfinder.followTrajectories(trajectory1, trajectory2).andThen(pf -> {
// any other code you want to be executed after the
// trajectory is finished
pf.setTranslation(new Translation(0, 0, 0));
}).followTrajectory(trajectory3).tickUntil(10_000).followTrajectory(trajectory4).tickUntil(10_000);
}
use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.
the class Pathfinder method followTrajectories.
/**
* Follow multiple trajectories.
*
* @param trajectories a list of trajectories to follow.
* @return this instance of Pathfinder, used for method chaining.
*/
public Pathfinder followTrajectories(List<Trajectory> trajectories) {
if (trajectories == null)
throw new NullPointerException("Cannot follow null trajectories!");
List<Follower> followers = new ArrayList<>();
for (Trajectory trajectory : trajectories) followers.add(generator.generate(robot, trajectory));
follow(followers);
return this;
}
use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.
the class Pathfinder method task.
/**
* Create a new {@link TaskTrajectory} and add it to Pathfinder's
* queue so that it can be executed
*
* @param initial code to be executed the first time the trajectory's
* {@code #isDone(PointXYZ)} method is called.
* @param during code to be executed any time the trajectory's
* {@code #isDone(PointXYZ)} method is called.
* @param onFinish code to be executed whenever the task is finished.
* @param isFinished a supplier that indicates if the task is finished.
* If the task is not finished, it should continue stop
* its execution.
* @param minTimeMs the minimum time, in milliseconds, the trajectory
* will be active for.
* @param maxTimeMs the maximum time, in milliseconds, the trajectory
* will be active for.
* @return {@code this}, used for method chaining.
*/
public Pathfinder task(Runnable initial, Runnable during, Runnable onFinish, Supplier<Boolean> isFinished, double minTimeMs, double maxTimeMs) {
Trajectory trajectory = new TaskTrajectoryBuilder().setInitial(initial).setDuring(during).setOnFinish(onFinish).setIsFinished(isFinished).setMinTimeMs(minTimeMs).setMaxTimeMs(maxTimeMs).build();
followTrajectory(trajectory);
return this;
}
use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.
the class ButtonMapper method update.
public void update() {
if (gamepad.areAnyButtonsPressed()) {
Trajectory trajectory = getTrajectory();
pathfinder.followTrajectory(trajectory);
}
if (gamepad.start()) {
pathfinder.clear();
}
}
use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.
the class TrajectoryFactory method getLinearTrajectories.
public static List<Trajectory> getLinearTrajectories(List<PointXYZ> points, double speed, double tolerance, Angle angleTolerance) {
List<Trajectory> trajectories = new ArrayList<>(points.size() - 1);
for (PointXYZ point : points) {
LinearTrajectory trajectory = new LinearTrajectory(point, speed, tolerance, angleTolerance);
trajectories.add(trajectory);
}
return trajectories;
}
Aggregations