Search in sources :

Example 11 with Trajectory

use of edu.wpi.first.math.trajectory.Trajectory in project Entropy2022 by Team138Entropy.

the class TrajectoryLibrary method get_New_T35_B5.

public Trajectory get_New_T35_B5() {
    Trajectory traj = null;
    String fileName = "New-T35_B5.wpilib.json";
    try {
        Path trajectoryPath = getTrajectoryPath(fileName);
        traj = TrajectoryUtil.fromPathweaverJson(trajectoryPath);
    } catch (IOException ex) {
        System.out.println("Unable to open trajectory: " + fileName);
    }
    return traj;
}
Also used : Path(java.nio.file.Path) Trajectory(edu.wpi.first.math.trajectory.Trajectory) IOException(java.io.IOException)

Example 12 with Trajectory

use of edu.wpi.first.math.trajectory.Trajectory in project FRC2022 by 2202Programming.

the class getTrajectoryFollowTest method initialize.

// Called when the command is initially scheduled.
@Override
public void initialize() {
    // An example trajectory to follow. All units in feet.
    Rotation2d current_angle = new Rotation2d(sensors.getYaw());
    Trajectory exampleTrajectory = TrajectoryGenerator.generateTrajectory(new Pose2d(0.0, 0.0, current_angle), List.of(), new Pose2d(0, 3.0, current_angle), // max velocity, max accel
    new TrajectoryConfig(2.0, 0.5));
    SwerveControllerCommand swerveControllerCommand = new SwerveControllerCommand(exampleTrajectory, // Functional interface to feed supplier
    drivetrain::getPose, drivetrain.getKinematics(), // Position controllers
    new PIDController(4.0, 0.0, 0.0), new PIDController(4.0, 0.0, 0.0), new ProfiledPIDController(4, 0, 0, new TrapezoidProfile.Constraints(.3, .3)), // per second squared
    drivetrain::drive, drivetrain);
    // Reset odometry to the starting pose of the trajectory.
    drivetrain.setPose(exampleTrajectory.getInitialPose());
    // Run path following command, then stop at the end.
    work = swerveControllerCommand.andThen(() -> drivetrain.stop()).withTimeout(10);
}
Also used : Rotation2d(edu.wpi.first.math.geometry.Rotation2d) Pose2d(edu.wpi.first.math.geometry.Pose2d) SwerveControllerCommand(edu.wpi.first.wpilibj2.command.SwerveControllerCommand) TrajectoryConfig(edu.wpi.first.math.trajectory.TrajectoryConfig) Trajectory(edu.wpi.first.math.trajectory.Trajectory) ProfiledPIDController(edu.wpi.first.math.controller.ProfiledPIDController) PIDController(edu.wpi.first.math.controller.PIDController) ProfiledPIDController(edu.wpi.first.math.controller.ProfiledPIDController)

Example 13 with Trajectory

use of edu.wpi.first.math.trajectory.Trajectory in project FRC2022 by Team2338.

the class FiveBallTerminalRight method pickupTerminal.

public Command pickupTerminal() {
    Trajectory trajectory = TrajectoryGenerator.generateTrajectory(List.of(new Pose2dFeet().set(-1.5, 13.0, 55.0), // 3rd cargo (terminal) location
    new Pose2dFeet().set(-5.5, 21.0, 43.0)), RobotTrajectory.getInstance().configReverseFast);
    // create the command using the trajectory
    RamseteCommand rc = RobotTrajectory.getInstance().createRamseteCommand(trajectory);
    // Run path following command, then stop at the end.
    return rc.andThen(() -> Robot.drivetrain.tankDriveVolts(0, 0));
}
Also used : Pose2dFeet(team.gif.lib.Pose2dFeet) Trajectory(edu.wpi.first.math.trajectory.Trajectory) RobotTrajectory(team.gif.lib.RobotTrajectory)

Example 14 with Trajectory

use of edu.wpi.first.math.trajectory.Trajectory in project FRC2022 by Team2338.

the class FiveBallTerminalRight method reverse.

public Command reverse() {
    Trajectory trajectory = TrajectoryGenerator.generateTrajectory(List.of(new Pose2dFeet().set(0.0, 0.0, 0.0), // 1st cargo location
    new Pose2dFeet().set(-3.4, 0.0, 0.0)), RobotTrajectory.getInstance().configReverseSlow);
    // create the command using the trajectory
    RamseteCommand rc = RobotTrajectory.getInstance().createRamseteCommand(trajectory);
    // Run path following command, then stop at the end.
    return rc.andThen(() -> Robot.drivetrain.tankDriveVolts(0, 0));
}
Also used : Pose2dFeet(team.gif.lib.Pose2dFeet) Trajectory(edu.wpi.first.math.trajectory.Trajectory) RobotTrajectory(team.gif.lib.RobotTrajectory)

Example 15 with Trajectory

use of edu.wpi.first.math.trajectory.Trajectory in project FRC2022 by Team2338.

the class FiveBallTerminalRight method forward.

public Command forward() {
    Trajectory trajectory = TrajectoryGenerator.generateTrajectory(List.of(new Pose2dFeet().set(-5.5, 21.0, 43.0), // shooting location
    new Pose2dFeet().set(0.0, 13.0, 55.0)), RobotTrajectory.getInstance().configForwardFast);
    // create the command using the trajectory
    RamseteCommand rc = RobotTrajectory.getInstance().createRamseteCommand(trajectory);
    // Run path following command, then stop at the end.
    return rc.andThen(() -> Robot.drivetrain.tankDriveVolts(0, 0));
}
Also used : Pose2dFeet(team.gif.lib.Pose2dFeet) Trajectory(edu.wpi.first.math.trajectory.Trajectory) RobotTrajectory(team.gif.lib.RobotTrajectory)

Aggregations

Trajectory (edu.wpi.first.math.trajectory.Trajectory)48 IOException (java.io.IOException)24 Path (java.nio.file.Path)24 Pose2dFeet (team.gif.lib.Pose2dFeet)19 RobotTrajectory (team.gif.lib.RobotTrajectory)19 PIDController (edu.wpi.first.math.controller.PIDController)5 Pose2d (edu.wpi.first.math.geometry.Pose2d)5 TrajectoryConfig (edu.wpi.first.math.trajectory.TrajectoryConfig)5 ProfiledPIDController (edu.wpi.first.math.controller.ProfiledPIDController)3 Rotation2d (edu.wpi.first.math.geometry.Rotation2d)3 Translation2d (edu.wpi.first.math.geometry.Translation2d)3 RamseteController (edu.wpi.first.math.controller.RamseteController)2 SimpleMotorFeedforward (edu.wpi.first.math.controller.SimpleMotorFeedforward)2 RamseteCommand (edu.wpi.first.wpilibj2.command.RamseteCommand)2 DifferentialDriveKinematics (edu.wpi.first.math.kinematics.DifferentialDriveKinematics)1 DifferentialDriveVoltageConstraint (edu.wpi.first.math.trajectory.constraint.DifferentialDriveVoltageConstraint)1 Waypoint (edu.wpi.first.pathweaver.Waypoint)1 MecanumControllerCommand (edu.wpi.first.wpilibj2.command.MecanumControllerCommand)1 SwerveControllerCommand (edu.wpi.first.wpilibj2.command.SwerveControllerCommand)1 File (java.io.File)1