Search in sources :

Example 36 with Trajectory

use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.

the class TestExecutorManager method testExecutorManager.

@Test
public void testExecutorManager() {
    SimulatedOdometry odometry = new SimulatedOdometry();
    SimulatedDrive drive = new SimulatedDrive();
    Robot robot = new Robot(drive, odometry);
    Trajectory trajectory = new LinearTrajectory(new PointXYZ(10, 10, 0), 1.0, 0.1, Angle.fromDeg(3));
    Controller controller = new GenericTurnController(0.1);
    GenericFollowerGenerator generator = new GenericFollowerGenerator(controller);
    Follower follower = generator.generate(robot, trajectory);
    List<Follower> list = new ArrayList<Follower>() {

        {
            add(follower);
        }
    };
    FollowerExecutor executor = new FollowerExecutor(odometry, drive, list);
    Assertions.assertFalse(executor.tick());
    ExecutorManager manager = new ExecutorManager(robot);
    Assertions.assertFalse(manager.isActive());
    manager.addExecutor(list);
    Assertions.assertTrue(manager.isActive());
    Assertions.assertFalse(manager.isInactive());
    Assertions.assertFalse(manager.tick());
    odometry.setRawPosition(new PointXYZ(10, 10, 0));
    Assertions.assertEquals(1, manager.howManyExecutors());
    Assertions.assertTrue(manager.tick());
    Assertions.assertFalse(manager.isActive());
    Assertions.assertTrue(manager.isInactive());
}
Also used : LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) SimulatedDrive(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedDrive) GenericTurnController(me.wobblyyyy.pathfinder2.control.GenericTurnController) ArrayList(java.util.ArrayList) Follower(me.wobblyyyy.pathfinder2.follower.Follower) SimulatedOdometry(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ) GenericTurnController(me.wobblyyyy.pathfinder2.control.GenericTurnController) Controller(me.wobblyyyy.pathfinder2.control.Controller) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) Robot(me.wobblyyyy.pathfinder2.robot.Robot) GenericFollowerGenerator(me.wobblyyyy.pathfinder2.follower.generators.GenericFollowerGenerator) Test(org.junit.jupiter.api.Test)

Example 37 with Trajectory

use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.

the class CircleSurrounder method surround.

/**
 * Surround the circle. This will find the closest point, create a new
 * {@link me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory} to that
 * point, and then instruct Pathfinder to follow it.
 */
public void surround() {
    PointXYZ robotPosition = pathfinder.getPosition();
    double speed = pathfinder.getSpeed();
    double tolerance = pathfinder.getTolerance();
    Angle angleTolerance = pathfinder.getAngleTolerance();
    Trajectory trajectory = CircleSurround.trajectoryToClosestPoint(robotPosition, center, radius, speed, tolerance, angleTolerance);
    pathfinder.followTrajectory(trajectory);
}
Also used : Angle(me.wobblyyyy.pathfinder2.geometry.Angle) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory)

Example 38 with Trajectory

use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.

the class CircleSurrounder method fastSurround.

/**
 * Surround the circle. This will find the closest point, create a new
 * {@link me.wobblyyyy.pathfinder2.trajectory.FastTrajectory} to that
 * point, and then instruct Pathfinder to follow it.
 */
public void fastSurround() {
    PointXYZ robotPosition = pathfinder.getPosition();
    double speed = pathfinder.getSpeed();
    double tolerance = pathfinder.getTolerance();
    Angle angleTolerance = pathfinder.getAngleTolerance();
    Trajectory trajectory = CircleSurround.fastTrajectoryToClosestPoint(robotPosition, center, radius, speed);
    pathfinder.followTrajectory(trajectory);
}
Also used : Angle(me.wobblyyyy.pathfinder2.geometry.Angle) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory)

Example 39 with Trajectory

use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.

the class PathBuilder method fastPath.

public List<Trajectory> fastPath(PointXYZ start, double speed) {
    List<Trajectory> trajectories = new ArrayList<>(targets.size());
    PointXYZ previousPoint = start;
    for (PointXYZ target : targets) {
        trajectories.add(new FastTrajectory(previousPoint, target, speed));
        previousPoint = target;
    }
    return trajectories;
}
Also used : FastTrajectory(me.wobblyyyy.pathfinder2.trajectory.FastTrajectory) 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)

Example 40 with Trajectory

use of com.team254.lib_2014.trajectory.Trajectory in project Pathfinder2 by Wobblyyyy.

the class Scheduler method tick.

/**
 * Tick the scheduler once.
 *
 * @see Scheduler
 */
public void tick() {
    if (this.tasks.size() == 0)
        return;
    Task currentTask = this.tasks.get(0);
    double currentTimeMilliseconds = Time.ms();
    if (!currentTask.hasStarted()) {
        currentTask.start(currentTimeMilliseconds);
        this.pathfinder.followTrajectory(currentTask.getTrajectory());
    } else {
        if (!(Math.abs(currentTask.getMinTimeMilliseconds()) > 1_000_000)) {
            if (!currentTask.isMinimumTimeLimitValid(currentTimeMilliseconds)) {
                this.pathfinder.tick();
                return;
            }
            Trajectory currentTrajectory = currentTask.getTrajectory();
            PointXYZ currentRobotPosition = this.pathfinder.getOdometry().getPosition();
            boolean isMaximumTimeInvalid = !currentTask.isMaximumTimeLimitValid(currentTimeMilliseconds);
            boolean isTrajectoryCompleted = currentTrajectory.isDone(currentRobotPosition);
            if (isMaximumTimeInvalid || isTrajectoryCompleted) {
                this.dequeueTask(currentTask);
            } else {
                this.pathfinder.tick();
            }
        }
    }
}
Also used : 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