Class SwerveModuleVelocity
java.lang.Object
org.wpilib.math.kinematics.SwerveModuleVelocity
- All Implemented Interfaces:
Comparable<SwerveModuleVelocity>, Interpolatable<SwerveModuleVelocity>, ProtobufSerializable, StructSerializable, WPISerializable
public class SwerveModuleVelocity
extends Object
implements Interpolatable<SwerveModuleVelocity>, Comparable<SwerveModuleVelocity>, ProtobufSerializable, StructSerializable
Represents the velocity of one swerve module.
-
Field Summary
FieldsModifier and TypeFieldDescriptionAngle of the module.static final SwerveModuleVelocityProtoSwerveModuleVelocity protobuf for serialization.static final SwerveModuleVelocityStructSwerveModuleVelocity struct for serialization.doubleVelocity of the wheel of the module in meters per second. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a SwerveModuleVelocity with zeros for velocity and angle.SwerveModuleVelocity(double velocity, Rotation2d angle) Constructs a SwerveModuleVelocity.SwerveModuleVelocity(LinearVelocity velocity, Rotation2d angle) Constructs a SwerveModuleVelocity. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(SwerveModuleVelocity other) Compares two swerve module velocities.voidcosineScale(Rotation2d currentAngle) Scales velocity by cosine of angle error.booleaninthashCode()interpolate(SwerveModuleVelocity endValue, double t) Returns the linear interpolation of this SwerveModuleVelocity and another.voidoptimize(Rotation2d currentAngle) Minimize the change in heading this swerve module velocity would require by potentially reversing the direction the wheel spins.static SwerveModuleVelocityoptimize(SwerveModuleVelocity desiredVelocity, Rotation2d currentAngle) Deprecated.Use the instance method instead.toString()
-
Field Details
-
velocity
Velocity of the wheel of the module in meters per second. -
angle
Angle of the module. -
proto
SwerveModuleVelocity protobuf for serialization. -
struct
SwerveModuleVelocity struct for serialization.
-
-
Constructor Details
-
SwerveModuleVelocity
public SwerveModuleVelocity()Constructs a SwerveModuleVelocity with zeros for velocity and angle. -
SwerveModuleVelocity
Constructs a SwerveModuleVelocity.- Parameters:
velocity- The velocity of the wheel of the module in meters per second.angle- The angle of the module.
-
SwerveModuleVelocity
Constructs a SwerveModuleVelocity.- Parameters:
velocity- The velocity of the wheel of the module.angle- The angle of the module.
-
-
Method Details
-
equals
-
hashCode
-
compareTo
Compares two swerve module velocities. One swerve module is "greater" than the other if its velocity is higher than the other.- Specified by:
compareToin interfaceComparable<SwerveModuleVelocity>- Parameters:
other- The other swerve module.- Returns:
- 1 if this is greater, 0 if both are equal, -1 if other is greater.
-
toString
-
optimize
Minimize the change in heading this swerve module velocity would require by potentially reversing the direction the wheel spins. If this is used with the PIDController class's continuous input functionality, the furthest a wheel will ever rotate is 90 degrees.- Parameters:
currentAngle- The current module angle.
-
optimize
@Deprecated public static SwerveModuleVelocity optimize(SwerveModuleVelocity desiredVelocity, Rotation2d currentAngle) Deprecated.Use the instance method instead.Minimize the change in heading the desired swerve module velocity would require by potentially reversing the direction the wheel spins. If this is used with the PIDController class's continuous input functionality, the furthest a wheel will ever rotate is 90 degrees.- Parameters:
desiredVelocity- The desired velocity.currentAngle- The current module angle.- Returns:
- Optimized swerve module velocity.
-
interpolate
Returns the linear interpolation of this SwerveModuleVelocity and another. The angle is interpolated using the shortest path between the two angles.- Specified by:
interpolatein interfaceInterpolatable<SwerveModuleVelocity>- Parameters:
endValue- The end value for the interpolation.t- How far between the two values to interpolate. This is clamped to [0, 1].- Returns:
- The interpolated value.
-
cosineScale
Scales velocity by cosine of angle error. This scales down movement perpendicular to the desired direction of travel that can occur when modules change directions. This results in smoother driving.- Parameters:
currentAngle- The current module angle.
-