WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
DifferentialDriveOdometry3d.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <wpi/SymbolExports.h>
8
14#include "units/length.h"
15
16namespace frc {
17/**
18 * Class for differential drive odometry. Odometry allows you to track the
19 * robot's position on the field over the course of a match using readings from
20 * 2 encoders and a gyroscope.
21 *
22 * Teams can use odometry during the autonomous period for complex tasks like
23 * path following. Furthermore, odometry can be used for latency compensation
24 * when using computer-vision systems.
25 *
26 * It is important that you reset your encoders to zero before using this class.
27 * Any subsequent pose resets also require the encoders to be reset to zero.
28 */
30 : public Odometry3d<DifferentialDriveWheelSpeeds,
31 DifferentialDriveWheelPositions> {
32 public:
33 /**
34 * Constructs a DifferentialDriveOdometry3d object.
35 *
36 * IF leftDistance and rightDistance are unspecified,
37 * You NEED to reset your encoders (to zero).
38 *
39 * @param gyroAngle The angle reported by the gyroscope.
40 * @param leftDistance The distance traveled by the left encoder.
41 * @param rightDistance The distance traveled by the right encoder.
42 * @param initialPose The starting position of the robot on the field.
43 */
44 explicit DifferentialDriveOdometry3d(const Rotation3d& gyroAngle,
45 units::meter_t leftDistance,
46 units::meter_t rightDistance,
47 const Pose3d& initialPose = Pose3d{});
48
49 /**
50 * Resets the robot's position on the field.
51 *
52 * IF leftDistance and rightDistance are unspecified,
53 * You NEED to reset your encoders (to zero).
54 *
55 * The gyroscope angle does not need to be reset here on the user's robot
56 * code. The library automatically takes care of offsetting the gyro angle.
57 *
58 * @param pose The position on the field that your robot is at.
59 * @param gyroAngle The angle reported by the gyroscope.
60 * @param leftDistance The distance traveled by the left encoder.
61 * @param rightDistance The distance traveled by the right encoder.
62 */
63 void ResetPosition(const Rotation3d& gyroAngle, units::meter_t leftDistance,
64 units::meter_t rightDistance, const Pose3d& pose) {
65 Odometry3d::ResetPosition(gyroAngle, {leftDistance, rightDistance}, pose);
66 }
67
68 /**
69 * Updates the robot position on the field using distance measurements from
70 * encoders. This method is more numerically accurate than using velocities to
71 * integrate the pose and is also advantageous for teams that are using lower
72 * CPR encoders.
73 *
74 * @param gyroAngle The angle reported by the gyroscope.
75 * @param leftDistance The distance traveled by the left encoder.
76 * @param rightDistance The distance traveled by the right encoder.
77 * @return The new pose of the robot.
78 */
79 const Pose3d& Update(const Rotation3d& gyroAngle, units::meter_t leftDistance,
80 units::meter_t rightDistance) {
81 return Odometry3d::Update(gyroAngle, {leftDistance, rightDistance});
82 }
83
84 private:
85 DifferentialDriveKinematics m_kinematicsImpl{units::meter_t{1}};
86};
87} // namespace frc
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Helper class that converts a chassis velocity (dx and dtheta components) to left and right wheel velo...
Definition DifferentialDriveKinematics.h:31
Class for differential drive odometry.
Definition DifferentialDriveOdometry3d.h:31
DifferentialDriveOdometry3d(const Rotation3d &gyroAngle, units::meter_t leftDistance, units::meter_t rightDistance, const Pose3d &initialPose=Pose3d{})
Constructs a DifferentialDriveOdometry3d object.
const Pose3d & Update(const Rotation3d &gyroAngle, units::meter_t leftDistance, units::meter_t rightDistance)
Updates the robot position on the field using distance measurements from encoders.
Definition DifferentialDriveOdometry3d.h:79
void ResetPosition(const Rotation3d &gyroAngle, units::meter_t leftDistance, units::meter_t rightDistance, const Pose3d &pose)
Resets the robot's position on the field.
Definition DifferentialDriveOdometry3d.h:63
Class for odometry.
Definition Odometry3d.h:33
Represents a 3D pose containing translational and rotational elements.
Definition Pose3d.h:28
A rotation in a 3D coordinate frame represented by a quaternion.
Definition Rotation3d.h:29
Definition CAN.h:11