WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
SwerveDrivePoseEstimator3d.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 <cmath>
8
9#include <wpi/SymbolExports.h>
10#include <wpi/array.h>
11
13#include "frc/geometry/Pose2d.h"
17#include "units/time.h"
18
19namespace frc {
20
21/**
22 * This class wraps Swerve Drive Odometry to fuse latency-compensated
23 * vision measurements with swerve drive encoder distance measurements. It is
24 * intended to be a drop-in for SwerveDriveOdometry3d. It is also intended to be
25 * an easy replacement for PoseEstimator, only requiring the addition of a
26 * standard deviation for Z and appropriate conversions between 2D and 3D
27 * versions of geometry classes. (See Pose3d(Pose2d), Rotation3d(Rotation2d),
28 * Translation3d(Translation2d), and Pose3d.ToPose2d().)
29 *
30 * Update() should be called every robot loop.
31 *
32 * AddVisionMeasurement() can be called as infrequently as you want; if you
33 * never call it, then this class will behave as regular encoder
34 * odometry.
35 */
36template <size_t NumModules>
38 : public PoseEstimator3d<wpi::array<SwerveModuleState, NumModules>,
39 wpi::array<SwerveModulePosition, NumModules>> {
40 public:
41 /**
42 * Constructs a SwerveDrivePoseEstimator3d with default standard deviations
43 * for the model and vision measurements.
44 *
45 * The default standard deviations of the model states are
46 * 0.1 meters for x, 0.1 meters for y, 0.1 meters for z, and 0.1 radians for
47 * angle. The default standard deviations of the vision measurements are 0.9
48 * meters for x, 0.9 meters for y, 0.9 meters for z, and 0.9 radians for
49 * angle.
50 *
51 * @param kinematics A correctly-configured kinematics object for your
52 * drivetrain.
53 * @param gyroAngle The current gyro angle.
54 * @param modulePositions The current distance and rotation measurements of
55 * the swerve modules.
56 * @param initialPose The starting pose estimate.
57 */
60 const Rotation3d& gyroAngle,
62 const Pose3d& initialPose)
63 : SwerveDrivePoseEstimator3d{kinematics, gyroAngle,
64 modulePositions, initialPose,
65 {0.1, 0.1, 0.1, 0.1}, {0.9, 0.9, 0.9, 0.9}} {
66 }
67
68 /**
69 * Constructs a SwerveDrivePoseEstimator3d.
70 *
71 * @param kinematics A correctly-configured kinematics object for your
72 * drivetrain.
73 * @param gyroAngle The current gyro angle.
74 * @param modulePositions The current distance and rotation measurements of
75 * the swerve modules.
76 * @param initialPose The starting pose estimate.
77 * @param stateStdDevs Standard deviations of the pose estimate (x position in
78 * meters, y position in meters, and heading in radians). Increase these
79 * numbers to trust your state estimate less.
80 * @param visionMeasurementStdDevs Standard deviations of the vision pose
81 * measurement (x position in meters, y position in meters, and heading in
82 * radians). Increase these numbers to trust the vision pose measurement
83 * less.
84 */
87 const Rotation3d& gyroAngle,
89 const Pose3d& initialPose, const wpi::array<double, 4>& stateStdDevs,
90 const wpi::array<double, 4>& visionMeasurementStdDevs)
92 kinematics, m_odometryImpl, stateStdDevs, visionMeasurementStdDevs),
93 m_odometryImpl{kinematics, gyroAngle, modulePositions, initialPose} {
94 this->ResetPose(initialPose);
95 }
96
97 private:
99};
100
101extern template class EXPORT_TEMPLATE_DECLARE(WPILIB_DLLEXPORT)
102 SwerveDrivePoseEstimator3d<4>;
103
104} // namespace frc
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
#define EXPORT_TEMPLATE_DECLARE(export)
Definition SymbolExports.hpp:92
Represents a 3D pose containing translational and rotational elements.
Definition Pose3d.h:28
This class wraps odometry to fuse latency-compensated vision measurements with encoder measurements.
Definition PoseEstimator3d.h:49
A rotation in a 3D coordinate frame represented by a quaternion.
Definition Rotation3d.h:29
Helper class that converts a chassis velocity (dx, dy, and dtheta components) into individual module ...
Definition SwerveDriveKinematics.h:54
Class for swerve drive odometry.
Definition SwerveDriveOdometry3d.h:35
This class wraps Swerve Drive Odometry to fuse latency-compensated vision measurements with swerve dr...
Definition SwerveDrivePoseEstimator3d.h:39
SwerveDrivePoseEstimator3d(SwerveDriveKinematics< NumModules > &kinematics, const Rotation3d &gyroAngle, const wpi::array< SwerveModulePosition, NumModules > &modulePositions, const Pose3d &initialPose)
Constructs a SwerveDrivePoseEstimator3d with default standard deviations for the model and vision mea...
Definition SwerveDrivePoseEstimator3d.h:58
SwerveDrivePoseEstimator3d(SwerveDriveKinematics< NumModules > &kinematics, const Rotation3d &gyroAngle, const wpi::array< SwerveModulePosition, NumModules > &modulePositions, const Pose3d &initialPose, const wpi::array< double, 4 > &stateStdDevs, const wpi::array< double, 4 > &visionMeasurementStdDevs)
Constructs a SwerveDrivePoseEstimator3d.
Definition SwerveDrivePoseEstimator3d.h:85
This class is a wrapper around std::array that does compile time size checking.
Definition array.h:26
Definition CAN.h:11