WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
DifferentialDrivePoseEstimator3d.hpp
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
12#include "wpi/units/time.hpp"
14#include "wpi/util/array.hpp"
15
16namespace wpi::math {
17/**
18 * This class wraps Differential Drive Odometry to fuse latency-compensated
19 * vision measurements with differential drive encoder measurements. It will
20 * correct for noisy vision measurements and encoder drift. It is intended to be
21 * an easy drop-in for DifferentialDriveOdometry3d. In fact, if you never call
22 * AddVisionMeasurement(), and only call Update(), this will behave exactly the
23 * same as DifferentialDriveOdometry3d. It is also intended to be an easy
24 * replacement for PoseEstimator, only requiring the addition of a standard
25 * deviation for Z and appropriate conversions between 2D and 3D versions of
26 * geometry classes. (See Pose3d(Pose2d), Rotation3d(Rotation2d),
27 * Translation3d(Translation2d), and Pose3d.ToPose2d().)
28 *
29 * Update() should be called every robot loop (if your robot loops are faster or
30 * slower than the default of 20 ms, then you should change the nominal delta
31 * time via the constructor).
32 *
33 * AddVisionMeasurement() can be called as infrequently as you want; if you
34 * never call it, then this class will behave like regular encoder odometry.
35 */
37 : public PoseEstimator3d<DifferentialDriveWheelPositions,
38 DifferentialDriveWheelVelocities,
39 DifferentialDriveWheelAccelerations> {
40 public:
41 /**
42 * Constructs a DifferentialDrivePoseEstimator3d with default standard
43 * deviations for the model and vision measurements.
44 *
45 * The default standard deviations of the model states are
46 * 0.02 meters for x, 0.02 meters for y, 0.02 meters for z, and 0.01 radians
47 * for angle. The default standard deviations of the vision measurements are
48 * 0.1 meters for x, 0.1 meters for y, 0.1 meters for z, and 0.1 radians for
49 * angle.
50 *
51 * @param kinematics A correctly-configured kinematics object for your
52 * drivetrain.
53 * @param gyroAngle The gyro angle of the robot.
54 * @param leftDistance The distance traveled by the left encoder.
55 * @param rightDistance The distance traveled by the right encoder.
56 * @param initialPose The estimated initial pose.
57 */
59 const Rotation3d& gyroAngle,
60 wpi::units::meter_t leftDistance,
61 wpi::units::meter_t rightDistance,
62 const Pose3d& initialPose);
63
64 /**
65 * Constructs a DifferentialDrivePoseEstimator3d.
66 *
67 * @param kinematics A correctly-configured kinematics object for your
68 * drivetrain.
69 * @param gyroAngle The gyro angle of the robot.
70 * @param leftDistance The distance traveled by the left encoder.
71 * @param rightDistance The distance traveled by the right encoder.
72 * @param initialPose The estimated initial pose.
73 * @param stateStdDevs Standard deviations of the pose estimate (x position in
74 * meters, y position in meters, z position in meters, and angle in
75 * radians). Increase these numbers to trust your state estimate less.
76 * @param visionMeasurementStdDevs Standard deviations of the vision pose
77 * measurement (x position in meters, y position in meters, z position in
78 * meters, and angle in radians). Increase these numbers to trust the vision
79 * pose measurement less.
80 */
82 DifferentialDriveKinematics& kinematics, const Rotation3d& gyroAngle,
83 wpi::units::meter_t leftDistance, wpi::units::meter_t rightDistance,
84 const Pose3d& initialPose,
85 const wpi::util::array<double, 4>& stateStdDevs,
86 const wpi::util::array<double, 4>& visionMeasurementStdDevs);
87
88 /**
89 * Resets the robot's position on the field.
90 *
91 * @param gyroAngle The current gyro angle.
92 * @param leftDistance The distance traveled by the left encoder.
93 * @param rightDistance The distance traveled by the right encoder.
94 * @param pose The estimated pose of the robot on the field.
95 */
96 void ResetPosition(const Rotation3d& gyroAngle,
97 wpi::units::meter_t leftDistance,
98 wpi::units::meter_t rightDistance, const Pose3d& pose) {
99 PoseEstimator3d::ResetPosition(gyroAngle, {leftDistance, rightDistance},
100 pose);
101 }
102
103 /**
104 * Updates the pose estimator with wheel encoder and gyro information. This
105 * should be called every loop.
106 *
107 * @param gyroAngle The current gyro angle.
108 * @param leftDistance The distance traveled by the left encoder.
109 * @param rightDistance The distance traveled by the right encoder.
110 *
111 * @return The estimated pose of the robot.
112 */
113 Pose3d Update(const Rotation3d& gyroAngle, wpi::units::meter_t leftDistance,
114 wpi::units::meter_t rightDistance) {
115 return PoseEstimator3d::Update(gyroAngle, {leftDistance, rightDistance});
116 }
117
118 /**
119 * Updates the pose estimator with wheel encoder and gyro information. This
120 * should be called every loop.
121 *
122 * @param currentTime The time at which this method was called.
123 * @param gyroAngle The current gyro angle.
124 * @param leftDistance The distance traveled by the left encoder.
125 * @param rightDistance The distance traveled by the right encoder.
126 *
127 * @return The estimated pose of the robot.
128 */
129 Pose3d UpdateWithTime(wpi::units::second_t currentTime,
130 const Rotation3d& gyroAngle,
131 wpi::units::meter_t leftDistance,
132 wpi::units::meter_t rightDistance) {
133 return PoseEstimator3d::UpdateWithTime(currentTime, gyroAngle,
134 {leftDistance, rightDistance});
135 }
136
137 private:
138 DifferentialDriveOdometry3d m_odometryImpl;
139};
140
141} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Helper class that converts a chassis velocity (dx and dtheta components) to left and right wheel velo...
Definition DifferentialDriveKinematics.hpp:33
Class for differential drive odometry.
Definition DifferentialDriveOdometry3d.hpp:31
Pose3d UpdateWithTime(wpi::units::second_t currentTime, const Rotation3d &gyroAngle, wpi::units::meter_t leftDistance, wpi::units::meter_t rightDistance)
Updates the pose estimator with wheel encoder and gyro information.
Definition DifferentialDrivePoseEstimator3d.hpp:129
Pose3d Update(const Rotation3d &gyroAngle, wpi::units::meter_t leftDistance, wpi::units::meter_t rightDistance)
Updates the pose estimator with wheel encoder and gyro information.
Definition DifferentialDrivePoseEstimator3d.hpp:113
void ResetPosition(const Rotation3d &gyroAngle, wpi::units::meter_t leftDistance, wpi::units::meter_t rightDistance, const Pose3d &pose)
Resets the robot's position on the field.
Definition DifferentialDrivePoseEstimator3d.hpp:96
DifferentialDrivePoseEstimator3d(DifferentialDriveKinematics &kinematics, const Rotation3d &gyroAngle, wpi::units::meter_t leftDistance, wpi::units::meter_t rightDistance, const Pose3d &initialPose, const wpi::util::array< double, 4 > &stateStdDevs, const wpi::util::array< double, 4 > &visionMeasurementStdDevs)
Constructs a DifferentialDrivePoseEstimator3d.
DifferentialDrivePoseEstimator3d(DifferentialDriveKinematics &kinematics, const Rotation3d &gyroAngle, wpi::units::meter_t leftDistance, wpi::units::meter_t rightDistance, const Pose3d &initialPose)
Constructs a DifferentialDrivePoseEstimator3d with default standard deviations for the model and visi...
Represents a 3D pose containing translational and rotational elements.
Definition Pose3d.hpp:28
PoseEstimator3d(Kinematics< DifferentialDriveWheelPositions, DifferentialDriveWheelVelocities, DifferentialDriveWheelAccelerations > &kinematics, Odometry3d< DifferentialDriveWheelPositions, DifferentialDriveWheelVelocities, DifferentialDriveWheelAccelerations > &odometry, const wpi::util::array< double, 4 > &stateStdDevs, const wpi::util::array< double, 4 > &visionMeasurementStdDevs)
Definition PoseEstimator3d.hpp:71
void ResetPosition(const Rotation3d &gyroAngle, const WheelPositions &wheelPositions, const Pose3d &pose)
Resets the robot's position on the field.
Definition PoseEstimator3d.hpp:129
Pose3d Update(const Rotation3d &gyroAngle, const WheelPositions &wheelPositions)
Updates the pose estimator with wheel encoder and gyro information.
Definition PoseEstimator3d.hpp:407
Pose3d UpdateWithTime(wpi::units::second_t currentTime, const Rotation3d &gyroAngle, const WheelPositions &wheelPositions)
Updates the pose estimator with wheel encoder and gyro information.
Definition PoseEstimator3d.hpp:423
A rotation in a 3D coordinate frame, represented by a quaternion.
Definition Rotation3d.hpp:69
This class is a wrapper around std::array that does compile time size checking.
Definition array.hpp:26
Definition LinearSystem.hpp:20