Class MecanumDriveKinematics
- All Implemented Interfaces:
Interpolator<MecanumDriveWheelPositions>
,Kinematics<MecanumDriveWheelSpeeds,
,MecanumDriveWheelPositions> ProtobufSerializable
,StructSerializable
,WPISerializable
The inverse kinematics (converting from a desired chassis velocity to individual wheel speeds) 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 speeds 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: [wheelSpeeds] = [wheelLocations] * [chassisSpeeds] We take the Moore-Penrose pseudoinverse of [wheelLocations] and then multiply by [wheelSpeeds] to get our chassis speeds.
Forward kinematics is also used for odometry -- determining the position of the robot on the field using encoders and a gyro.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final MecanumDriveKinematicsProto
MecanumDriveKinematics protobuf for serialization.static final MecanumDriveKinematicsStruct
MecanumDriveKinematics struct for serialization. -
Constructor Summary
ConstructorDescriptionMecanumDriveKinematics
(Translation2d frontLeftWheelMeters, Translation2d frontRightWheelMeters, Translation2d rearLeftWheelMeters, Translation2d rearRightWheelMeters) Constructs a mecanum drive kinematics object. -
Method Summary
Modifier and TypeMethodDescriptioncopy
(MecanumDriveWheelPositions positions) Returns a copy of the wheel positions object.void
copyInto
(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.toChassisSpeeds
(MecanumDriveWheelSpeeds wheelSpeeds) Performs forward kinematics to return the resulting chassis state from the given wheel speeds.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.toWheelSpeeds
(ChassisSpeeds chassisSpeeds) Performs inverse kinematics.toWheelSpeeds
(ChassisSpeeds chassisSpeeds, Translation2d centerOfRotationMeters) Performs inverse kinematics to return the wheel speeds from a desired chassis velocity.
-
Field Details
-
proto
MecanumDriveKinematics protobuf for serialization. -
struct
MecanumDriveKinematics struct for serialization.
-
-
Constructor Details
-
MecanumDriveKinematics
public MecanumDriveKinematics(Translation2d frontLeftWheelMeters, Translation2d frontRightWheelMeters, Translation2d rearLeftWheelMeters, Translation2d rearRightWheelMeters) Constructs a mecanum drive kinematics object.- Parameters:
frontLeftWheelMeters
- The location of the front-left wheel relative to the physical center of the robot.frontRightWheelMeters
- The location of the front-right wheel relative to the physical center of the robot.rearLeftWheelMeters
- The location of the rear-left wheel relative to the physical center of the robot.rearRightWheelMeters
- The location of the rear-right wheel relative to the physical center of the robot.
-
-
Method Details
-
toWheelSpeeds
public MecanumDriveWheelSpeeds toWheelSpeeds(ChassisSpeeds chassisSpeeds, Translation2d centerOfRotationMeters) Performs inverse kinematics to return the wheel speeds from a desired chassis velocity. This method is often used to convert joystick values into wheel speeds.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:
chassisSpeeds
- The desired chassis speed.centerOfRotationMeters
- The center of rotation. For example, if you set the center of rotation at one corner of the robot and provide a chassis speed that only has a dtheta component, the robot will rotate around that corner.- Returns:
- The wheel speeds. Use caution because they are not normalized. Sometimes, a user input
may cause one of the wheel speeds to go above the attainable max velocity. Use the
MecanumDriveWheelSpeeds.desaturate(double)
function to rectify this issue.
-
toWheelSpeeds
Performs inverse kinematics. SeetoWheelSpeeds(ChassisSpeeds, Translation2d)
for more information.- Specified by:
toWheelSpeeds
in interfaceKinematics<MecanumDriveWheelSpeeds,
MecanumDriveWheelPositions> - Parameters:
chassisSpeeds
- The desired chassis speed.- Returns:
- The wheel speeds.
-
toChassisSpeeds
Performs forward kinematics to return the resulting chassis state from the given wheel speeds. This method is often used for odometry -- determining the robot's position on the field using data from the real-world speed of each wheel on the robot.- Specified by:
toChassisSpeeds
in interfaceKinematics<MecanumDriveWheelSpeeds,
MecanumDriveWheelPositions> - Parameters:
wheelSpeeds
- The current mecanum drive wheel speeds.- Returns:
- The resulting chassis speed.
-
toTwist2d
Description copied from interface:Kinematics
Performs 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:
toTwist2d
in interfaceKinematics<MecanumDriveWheelSpeeds,
MecanumDriveWheelPositions> - 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:Kinematics
Returns a copy of the wheel positions object.- Specified by:
copy
in interfaceKinematics<MecanumDriveWheelSpeeds,
MecanumDriveWheelPositions> - Parameters:
positions
- The wheel positions object to copy.- Returns:
- A copy.
-
copyInto
Description copied from interface:Kinematics
Copies the value of the wheel positions object into the output.- Specified by:
copyInto
in interfaceKinematics<MecanumDriveWheelSpeeds,
MecanumDriveWheelPositions> - 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:Interpolator
Perform interpolation between two values.- Specified by:
interpolate
in 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.
-