Search in sources :

Example 11 with Trajectory

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);
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) Translation(me.wobblyyyy.pathfinder2.geometry.Translation) SplineBuilderFactory(me.wobblyyyy.pathfinder2.trajectory.spline.SplineBuilderFactory) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ) AdvancedSplineTrajectoryBuilder(me.wobblyyyy.pathfinder2.trajectory.spline.AdvancedSplineTrajectoryBuilder)

Example 12 with Trajectory

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;
}
Also used : Follower(me.wobblyyyy.pathfinder2.follower.Follower) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) TaskTrajectory(me.wobblyyyy.pathfinder2.trajectory.TaskTrajectory) LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)

Example 13 with Trajectory

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;
}
Also used : Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) TaskTrajectory(me.wobblyyyy.pathfinder2.trajectory.TaskTrajectory) LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) TaskTrajectoryBuilder(me.wobblyyyy.pathfinder2.trajectory.TaskTrajectoryBuilder)

Example 14 with Trajectory

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();
    }
}
Also used : LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory)

Example 15 with Trajectory

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;
}
Also used : LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) ArrayList(java.util.ArrayList) FastTrajectory(me.wobblyyyy.pathfinder2.trajectory.FastTrajectory) LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ)

Aggregations

Trajectory (me.wobblyyyy.pathfinder2.trajectory.Trajectory)30 PointXYZ (me.wobblyyyy.pathfinder2.geometry.PointXYZ)26 LinearTrajectory (me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)21 Trajectory (com.team254.lib_2014.trajectory.Trajectory)16 TrajectoryGenerator (com.team254.lib_2014.trajectory.TrajectoryGenerator)9 ArcTrajectory (me.wobblyyyy.pathfinder2.trajectory.ArcTrajectory)9 MultiSegmentTrajectory (me.wobblyyyy.pathfinder2.trajectory.multi.segment.MultiSegmentTrajectory)9 Path (com.team254.lib_2014.trajectory.Path)8 ArrayList (java.util.ArrayList)7 Controller (me.wobblyyyy.pathfinder2.control.Controller)5 Follower (me.wobblyyyy.pathfinder2.follower.Follower)5 Robot (me.wobblyyyy.pathfinder2.robot.Robot)5 AdvancedSplineTrajectoryBuilder (me.wobblyyyy.pathfinder2.trajectory.spline.AdvancedSplineTrajectoryBuilder)5 Test (org.junit.jupiter.api.Test)5 ElapsedTime (com.qualcomm.robotcore.util.ElapsedTime)4 GenericTurnController (me.wobblyyyy.pathfinder2.control.GenericTurnController)4 SimulatedDrive (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedDrive)4 SimulatedOdometry (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)4 TaskTrajectory (me.wobblyyyy.pathfinder2.trajectory.TaskTrajectory)4 TrajectoryFollower (com.team254.lib_2014.trajectory.TrajectoryFollower)3