Class MecanumDriveKinematics
- All Implemented Interfaces:
Interpolator<MecanumDriveWheelPositions>, Kinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>, ProtobufSerializable, StructSerializable, WPISerializable
The inverse kinematics (converting from a desired chassis velocity to individual wheel velocities) uses the relative locations of the wheels with respect to the center of rotation. The center of rotation for inverse kinematics is also variable. This means that you can set your center of rotation in a corner of the robot to perform special evasion maneuvers.
Forward kinematics (converting an array of wheel velocities into the overall chassis motion) is performs the exact opposite of what inverse kinematics does. Since this is an overdetermined system (more equations than variables), we use a least-squares approximation.
The inverse kinematics: [wheelVelocities] = [wheelLocations] * [chassisVelocities] We take the Moore-Penrose pseudoinverse of [wheelLocations] and then multiply by [wheelVelocities] to get our chassis velocities.
Forward kinematics is also used for odometry -- determining the position of the robot on the field using encoders and a gyro.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MecanumDriveKinematicsProtoMecanumDriveKinematics protobuf for serialization.static final MecanumDriveKinematicsStructMecanumDriveKinematics struct for serialization. -
Constructor Summary
ConstructorsConstructorDescriptionMecanumDriveKinematics(Translation2d frontLeftWheel, Translation2d frontRightWheel, Translation2d rearLeftWheel, Translation2d rearRightWheel) Constructs a mecanum drive kinematics object. -
Method Summary
Modifier and TypeMethodDescriptioncopy(MecanumDriveWheelPositions positions) Returns a copy of the wheel positions object.voidcopyInto(MecanumDriveWheelPositions positions, MecanumDriveWheelPositions output) Copies the value of the wheel positions object into the output.Returns the front-left wheel translation.Returns the front-right wheel translation.Returns the rear-left wheel translation.Returns the rear-right wheel translation.interpolate(MecanumDriveWheelPositions startValue, MecanumDriveWheelPositions endValue, double t) Perform interpolation between two values.toChassisAccelerations(MecanumDriveWheelAccelerations wheelAccelerations) Performs forward kinematics to return the resulting chassis accelerations from the given wheel accelerations.toChassisVelocities(MecanumDriveWheelVelocities wheelVelocities) Performs forward kinematics to return the resulting chassis state from the given wheel velocities.toTwist2d(MecanumDriveWheelPositions wheelDeltas) Performs forward kinematics to return the resulting Twist2d from the given wheel deltas.Performs forward kinematics to return the resulting Twist2d from the given change in wheel positions.toWheelAccelerations(ChassisAccelerations chassisAccelerations) Performs inverse kinematics.toWheelAccelerations(ChassisAccelerations chassisAccelerations, Translation2d centerOfRotation) Performs inverse kinematics to return the wheel accelerations from a desired chassis acceleration.toWheelVelocities(ChassisVelocities chassisVelocities) Performs inverse kinematics.toWheelVelocities(ChassisVelocities chassisVelocities, Translation2d centerOfRotation) Performs inverse kinematics to return the wheel velocities from a desired chassis velocity.
-
Field Details
-
proto
MecanumDriveKinematics protobuf for serialization. -
struct
MecanumDriveKinematics struct for serialization.
-
-
Constructor Details
-
MecanumDriveKinematics
public MecanumDriveKinematics(Translation2d frontLeftWheel, Translation2d frontRightWheel, Translation2d rearLeftWheel, Translation2d rearRightWheel) Constructs a mecanum drive kinematics object.- Parameters:
frontLeftWheel- The location of the front-left wheel relative to the physical center of the robot, in meters.frontRightWheel- The location of the front-right wheel relative to the physical center of the robot, in meters.rearLeftWheel- The location of the rear-left wheel relative to the physical center of the robot, in meters.rearRightWheel- The location of the rear-right wheel relative to the physical center of the robot, in meters.
-
-
Method Details
-
toWheelVelocities
public MecanumDriveWheelVelocities toWheelVelocities(ChassisVelocities chassisVelocities, Translation2d centerOfRotation) Performs inverse kinematics to return the wheel velocities from a desired chassis velocity. This method is often used to convert joystick values into wheel velocities.This function also supports variable centers of rotation. During normal operations, the center of rotation is usually the same as the physical center of the robot; therefore, the argument is defaulted to that use case. However, if you wish to change the center of rotation for evasive maneuvers, vision alignment, or for any other use case, you can do so.
- Parameters:
chassisVelocities- The desired chassis velocity.centerOfRotation- The center of rotation. For example, if you set the center of rotation at one corner of the robot and provide a chassis velocity that only has a dtheta component, the robot will rotate around that corner.- Returns:
- The wheel velocities. Use caution because they are not normalized. Sometimes, a user
input may cause one of the wheel velocities to go above the attainable max velocity. Use
the
MecanumDriveWheelVelocities.desaturate(double)function to rectify this issue.
-
toWheelVelocities
Performs inverse kinematics. SeetoWheelVelocities(ChassisVelocities, Translation2d)for more information.- Specified by:
toWheelVelocitiesin interfaceKinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>- Parameters:
chassisVelocities- The desired chassis velocity.- Returns:
- The wheel velocities.
-
toChassisVelocities
Performs forward kinematics to return the resulting chassis state from the given wheel velocities. This method is often used for odometry -- determining the robot's position on the field using data from the real-world velocity of each wheel on the robot.- Specified by:
toChassisVelocitiesin interfaceKinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>- Parameters:
wheelVelocities- The current mecanum drive wheel velocities.- Returns:
- The resulting chassis velocity.
-
toWheelAccelerations
public MecanumDriveWheelAccelerations toWheelAccelerations(ChassisAccelerations chassisAccelerations, Translation2d centerOfRotation) Performs inverse kinematics to return the wheel accelerations from a desired chassis acceleration. This method is often used for dynamics calculations -- converting desired robot accelerations into individual wheel accelerations.This function also supports variable centers of rotation. During normal operations, the center of rotation is usually the same as the physical center of the robot; therefore, the argument is defaulted to that use case. However, if you wish to change the center of rotation for evasive maneuvers, vision alignment, or for any other use case, you can do so.
- Parameters:
chassisAccelerations- The desired chassis accelerations.centerOfRotation- The center of rotation. For example, if you set the center of rotation at one corner of the robot and provide a chassis acceleration that only has a dtheta component, the robot will rotate around that corner.- Returns:
- The wheel accelerations.
-
toWheelAccelerations
public MecanumDriveWheelAccelerations toWheelAccelerations(ChassisAccelerations chassisAccelerations) Performs inverse kinematics. SeetoWheelAccelerations(ChassisAccelerations, Translation2d)for more information.- Specified by:
toWheelAccelerationsin interfaceKinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>- Parameters:
chassisAccelerations- The desired chassis accelerations.- Returns:
- The wheel accelerations.
-
toChassisAccelerations
public ChassisAccelerations toChassisAccelerations(MecanumDriveWheelAccelerations wheelAccelerations) Performs forward kinematics to return the resulting chassis accelerations from the given wheel accelerations. This method is often used for dynamics calculations -- determining the robot's acceleration on the field using data from the real-world acceleration of each wheel on the robot.- Specified by:
toChassisAccelerationsin interfaceKinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>- Parameters:
wheelAccelerations- The current mecanum drive wheel accelerations.- Returns:
- The resulting chassis accelerations.
-
toTwist2d
Description copied from interface:KinematicsPerforms forward kinematics to return the resulting Twist2d from the given change in wheel positions. This method is often used for odometry -- determining the robot's position on the field using changes in the distance driven by each wheel on the robot.- Specified by:
toTwist2din interfaceKinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>- Parameters:
start- The starting distances driven by the wheels.end- The ending distances driven by the wheels.- Returns:
- The resulting Twist2d in the robot's movement.
-
toTwist2d
Performs forward kinematics to return the resulting Twist2d from the given wheel deltas. This method is often used for odometry -- determining the robot's position on the field using changes in the distance driven by each wheel on the robot.- Parameters:
wheelDeltas- The distances driven by each wheel.- Returns:
- The resulting Twist2d.
-
getFrontLeft
Returns the front-left wheel translation.- Returns:
- The front-left wheel translation.
-
getFrontRight
Returns the front-right wheel translation.- Returns:
- The front-right wheel translation.
-
getRearLeft
Returns the rear-left wheel translation.- Returns:
- The rear-left wheel translation.
-
getRearRight
Returns the rear-right wheel translation.- Returns:
- The rear-right wheel translation.
-
copy
Description copied from interface:KinematicsReturns a copy of the wheel positions object.- Specified by:
copyin interfaceKinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>- Parameters:
positions- The wheel positions object to copy.- Returns:
- A copy.
-
copyInto
Description copied from interface:KinematicsCopies the value of the wheel positions object into the output.- Specified by:
copyIntoin interfaceKinematics<MecanumDriveWheelPositions, MecanumDriveWheelVelocities, MecanumDriveWheelAccelerations>- Parameters:
positions- The wheel positions object to copy. Will not be modified.output- The output variable of the copy operation. Will have the same value as the positions object after the call.
-
interpolate
public MecanumDriveWheelPositions interpolate(MecanumDriveWheelPositions startValue, MecanumDriveWheelPositions endValue, double t) Description copied from interface:InterpolatorPerform interpolation between two values.- Specified by:
interpolatein interfaceInterpolator<MecanumDriveWheelPositions>- Parameters:
startValue- The value to start at.endValue- The value to end at.t- How far between the two values to interpolate. This should be bounded to [0, 1].- Returns:
- The interpolated value.
-