Search in sources :

Example 11 with SwerveModuleState

use of edu.wpi.first.math.kinematics.SwerveModuleState in project Pathfinder2 by Wobblyyyy.

the class WPISwerveOdometry method update.

/**
 * Update the odometry once. This will use the robot's translation over
 * time to determine its position based on elapsed time.
 */
public void update() {
    Rotation2d rotation = WPIAdapter.rotationFromAngle(gyroscope.getAngle());
    SwerveModuleState[] states = new SwerveModuleState[driveEncoders.length];
    WPISwerveModule[] modules = chassis.getModules();
    for (int i = 0; i < modules.length; i++) states[i] = new SwerveModuleState(driveEncoders[i].getVelocity() * velocityToUnitsPerSec, modules[i].getTurnRotation());
    pose = odometry.update(rotation, states);
    position = WPIAdapter.pointXYZFromPose(pose);
}
Also used : Rotation2d(edu.wpi.first.math.geometry.Rotation2d) SwerveModuleState(edu.wpi.first.math.kinematics.SwerveModuleState)

Aggregations

SwerveModuleState (edu.wpi.first.math.kinematics.SwerveModuleState)11 Rotation2d (edu.wpi.first.math.geometry.Rotation2d)3 ChassisSpeeds (edu.wpi.first.math.kinematics.ChassisSpeeds)1