WPILibC++ 2023.4.3-108-ge5452e3
frc::SwerveDriveOdometry< NumModules > Class Template Reference

Class for swerve drive odometry. More...

#include <frc/kinematics/SwerveDriveOdometry.h>

Inheritance diagram for frc::SwerveDriveOdometry< NumModules >:
frc::Odometry< SwerveDriveWheelSpeeds< NumModules >, SwerveDriveWheelPositions< NumModules > >

Public Member Functions

 SwerveDriveOdometry (SwerveDriveKinematics< NumModules > kinematics, const Rotation2d &gyroAngle, const wpi::array< SwerveModulePosition, NumModules > &modulePositions, const Pose2d &initialPose=Pose2d{})
 Constructs a SwerveDriveOdometry object. More...
 
void ResetPosition (const Rotation2d &gyroAngle, const wpi::array< SwerveModulePosition, NumModules > &modulePositions, const Pose2d &pose)
 Resets the robot's position on the field. More...
 
const Pose2dUpdate (const Rotation2d &gyroAngle, const wpi::array< SwerveModulePosition, NumModules > &modulePositions)
 Updates the robot's position on the field using forward kinematics and integration of the pose over time. More...
 
- Public Member Functions inherited from frc::Odometry< SwerveDriveWheelSpeeds< NumModules >, SwerveDriveWheelPositions< NumModules > >
 Odometry (const Kinematics< SwerveDriveWheelSpeeds< NumModules >, WheelPositions > &kinematics, const Rotation2d &gyroAngle, const WheelPositions &wheelPositions, const Pose2d &initialPose=Pose2d{})
 Constructs an Odometry object. More...
 
void ResetPosition (const Rotation2d &gyroAngle, const WheelPositions &wheelPositions, const Pose2d &pose)
 Resets the robot's position on the field. More...
 
const Pose2dGetPose () const
 Returns the position of the robot on the field. More...
 
const Pose2dUpdate (const Rotation2d &gyroAngle, const WheelPositions &wheelPositions)
 Updates the robot's position on the field using forward kinematics and integration of the pose over time. More...
 

Detailed Description

template<size_t NumModules>
class frc::SwerveDriveOdometry< NumModules >

Class for swerve drive odometry.

Odometry allows you to track the robot's position on the field over a course of a match using readings from your swerve drive encoders and swerve azimuth encoders.

Teams can use odometry during the autonomous period for complex tasks like path following. Furthermore, odometry can be used for latency compensation when using computer-vision systems.

Constructor & Destructor Documentation

◆ SwerveDriveOdometry()

template<size_t NumModules>
frc::SwerveDriveOdometry< NumModules >::SwerveDriveOdometry ( SwerveDriveKinematics< NumModules >  kinematics,
const Rotation2d gyroAngle,
const wpi::array< SwerveModulePosition, NumModules > &  modulePositions,
const Pose2d initialPose = Pose2d{} 
)

Constructs a SwerveDriveOdometry object.

Parameters
kinematicsThe swerve drive kinematics for your drivetrain.
gyroAngleThe angle reported by the gyroscope.
modulePositionsThe wheel positions reported by each module.
initialPoseThe starting position of the robot on the field.

Member Function Documentation

◆ ResetPosition()

template<size_t NumModules>
void frc::SwerveDriveOdometry< NumModules >::ResetPosition ( const Rotation2d gyroAngle,
const wpi::array< SwerveModulePosition, NumModules > &  modulePositions,
const Pose2d pose 
)
inline

Resets the robot's position on the field.

The gyroscope angle does not need to be reset here on the user's robot code. The library automatically takes care of offsetting the gyro angle.

Parameters
gyroAngleThe angle reported by the gyroscope.
modulePositionsThe wheel positions reported by each module.
poseThe position on the field that your robot is at.

◆ Update()

template<size_t NumModules>
const Pose2d & frc::SwerveDriveOdometry< NumModules >::Update ( const Rotation2d gyroAngle,
const wpi::array< SwerveModulePosition, NumModules > &  modulePositions 
)
inline

Updates the robot's position on the field using forward kinematics and integration of the pose over time.

This also takes in an angle parameter which is used instead of the angular rate that is calculated from forward kinematics.

Parameters
gyroAngleThe angle reported by the gyroscope.
modulePositionsThe current position of all swerve modules. Please provide the positions in the same order in which you instantiated your SwerveDriveKinematics.
Returns
The new pose of the robot.

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