WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
frc::DifferentialDriveKinematics Class Reference

Helper class that converts a chassis velocity (dx and dtheta components) to left and right wheel velocities for a differential drive. More...

#include <frc/kinematics/DifferentialDriveKinematics.h>

Inheritance diagram for frc::DifferentialDriveKinematics:
frc::Kinematics< DifferentialDriveWheelSpeeds, DifferentialDriveWheelPositions >

Public Member Functions

constexpr DifferentialDriveKinematics (units::meter_t trackWidth)
 Constructs a differential drive kinematics object.
 
constexpr ChassisSpeeds ToChassisSpeeds (const DifferentialDriveWheelSpeeds &wheelSpeeds) const override
 Returns a chassis speed from left and right component velocities using forward kinematics.
 
constexpr DifferentialDriveWheelSpeeds ToWheelSpeeds (const ChassisSpeeds &chassisSpeeds) const override
 Returns left and right component velocities from a chassis speed using inverse kinematics.
 
constexpr Twist2d ToTwist2d (const units::meter_t leftDistance, const units::meter_t rightDistance) const
 Returns a twist from left and right distance deltas using forward kinematics.
 
constexpr Twist2d ToTwist2d (const DifferentialDriveWheelPositions &start, const DifferentialDriveWheelPositions &end) const override
 Performs forward kinematics to return the resulting Twist2d from the given change in wheel positions.
 
constexpr DifferentialDriveWheelPositions Interpolate (const DifferentialDriveWheelPositions &start, const DifferentialDriveWheelPositions &end, double t) const override
 Performs interpolation between two values.
 
- Public Member Functions inherited from frc::Kinematics< DifferentialDriveWheelSpeeds, DifferentialDriveWheelPositions >
virtual ~Kinematics () noexcept=default
 

Public Attributes

units::meter_t trackWidth
 Differential drive trackwidth.
 

Detailed Description

Helper class that converts a chassis velocity (dx and dtheta components) to left and right wheel velocities for a differential drive.

Inverse kinematics converts a desired chassis speed into left and right velocity components whereas forward kinematics converts left and right component velocities into a linear and angular chassis speed.

Constructor & Destructor Documentation

◆ DifferentialDriveKinematics()

frc::DifferentialDriveKinematics::DifferentialDriveKinematics ( units::meter_t trackWidth)
inlineexplicitconstexpr

Constructs a differential drive kinematics object.

Parameters
trackWidthThe track width of the drivetrain. Theoretically, this is the distance between the left wheels and right wheels. However, the empirical value may be larger than the physical measured value due to scrubbing effects.

Member Function Documentation

◆ Interpolate()

DifferentialDriveWheelPositions frc::DifferentialDriveKinematics::Interpolate ( const DifferentialDriveWheelPositions & start,
const DifferentialDriveWheelPositions & end,
double t ) const
inlineconstexproverridevirtual

Performs interpolation between two values.

Parameters
startThe value to start at.
endThe value to end at.
tHow far between the two values to interpolate. This should be bounded to [0, 1].
Returns
The interpolated value.

Implements frc::Kinematics< DifferentialDriveWheelSpeeds, DifferentialDriveWheelPositions >.

◆ ToChassisSpeeds()

ChassisSpeeds frc::DifferentialDriveKinematics::ToChassisSpeeds ( const DifferentialDriveWheelSpeeds & wheelSpeeds) const
inlineconstexproverridevirtual

Returns a chassis speed from left and right component velocities using forward kinematics.

Parameters
wheelSpeedsThe left and right velocities.
Returns
The chassis speed.

Implements frc::Kinematics< DifferentialDriveWheelSpeeds, DifferentialDriveWheelPositions >.

◆ ToTwist2d() [1/2]

Twist2d frc::DifferentialDriveKinematics::ToTwist2d ( const DifferentialDriveWheelPositions & start,
const DifferentialDriveWheelPositions & end ) const
inlineconstexproverridevirtual

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.

Parameters
startThe starting distances driven by the wheels.
endThe ending distances driven by the wheels.
Returns
The resulting Twist2d in the robot's movement.

Implements frc::Kinematics< DifferentialDriveWheelSpeeds, DifferentialDriveWheelPositions >.

◆ ToTwist2d() [2/2]

Twist2d frc::DifferentialDriveKinematics::ToTwist2d ( const units::meter_t leftDistance,
const units::meter_t rightDistance ) const
inlineconstexpr

Returns a twist from left and right distance deltas using forward kinematics.

Parameters
leftDistanceThe distance measured by the left encoder.
rightDistanceThe distance measured by the right encoder.
Returns
The resulting Twist2d.

◆ ToWheelSpeeds()

DifferentialDriveWheelSpeeds frc::DifferentialDriveKinematics::ToWheelSpeeds ( const ChassisSpeeds & chassisSpeeds) const
inlineconstexproverridevirtual

Returns left and right component velocities from a chassis speed using inverse kinematics.

Parameters
chassisSpeedsThe linear and angular (dx and dtheta) components that represent the chassis' speed.
Returns
The left and right velocities.

Implements frc::Kinematics< DifferentialDriveWheelSpeeds, DifferentialDriveWheelPositions >.

Member Data Documentation

◆ trackWidth

units::meter_t frc::DifferentialDriveKinematics::trackWidth

Differential drive trackwidth.


The documentation for this class was generated from the following file: