Search in sources :

Example 1 with State

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

the class AutoUtil method getInvertedStates.

/**
 * Returns a cloned, reversed list of the given states.
 * Each state is reconstructed with negative velocity and
 * the correct timepoint for the following backwards
 */
public static List<State> getInvertedStates(List<State> states) {
    List<State> invertedStates = new ArrayList<State>(states);
    Collections.reverse(invertedStates);
    for (int i = 0; i < invertedStates.size(); i++) {
        State currState = invertedStates.get(i);
        State newState = new State(states.get(i).timeSeconds, currState.velocityMetersPerSecond * -1, currState.accelerationMetersPerSecondSq, currState.poseMeters, currState.curvatureRadPerMeter);
        invertedStates.set(i, newState);
    }
    return invertedStates;
}
Also used : State(edu.wpi.first.math.trajectory.Trajectory.State) ArrayList(java.util.ArrayList)

Example 2 with State

use of edu.wpi.first.math.trajectory.Trajectory.State in project RobotCode2022 by Mechanical-Advantage.

the class MotionProfileCommand method execute.

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
    State setpoint = trajectory.sample(timer.get());
    Logger.getInstance().recordOutput("Odometry/ProfileSetpoint", new double[] { setpoint.poseMeters.getX(), setpoint.poseMeters.getY(), setpoint.poseMeters.getRotation().getRadians() });
    ChassisSpeeds chassisSpeeds = controller.calculate(drive.getPose(), setpoint);
    DifferentialDriveWheelSpeeds wheelSpeeds = kinematics.toWheelSpeeds(chassisSpeeds);
    drive.driveVelocity(wheelSpeeds.leftMetersPerSecond, wheelSpeeds.rightMetersPerSecond);
}
Also used : DifferentialDriveWheelSpeeds(edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds) State(edu.wpi.first.math.trajectory.Trajectory.State) ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Aggregations

State (edu.wpi.first.math.trajectory.Trajectory.State)2 ChassisSpeeds (edu.wpi.first.math.kinematics.ChassisSpeeds)1 DifferentialDriveWheelSpeeds (edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds)1 ArrayList (java.util.ArrayList)1