WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
SwerveDriveOdometry3d.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
7#include <cstddef>
8
15
16namespace wpi::math {
17
18/**
19 * Class for swerve drive odometry. Odometry allows you to track the robot's
20 * position on the field over a course of a match using readings from your
21 * swerve drive encoders and swerve azimuth encoders.
22 *
23 * Teams can use odometry during the autonomous period for complex tasks like
24 * path following. Furthermore, odometry can be used for latency compensation
25 * when using computer-vision systems.
26 */
27template <size_t NumModules>
29 : public Odometry3d<
30 wpi::util::array<SwerveModulePosition, NumModules>,
31 wpi::util::array<SwerveModuleVelocity, NumModules>,
32 wpi::util::array<SwerveModuleAcceleration, NumModules>> {
33 public:
34 /**
35 * Constructs a SwerveDriveOdometry3d object.
36 *
37 * @param kinematics The swerve drive kinematics for your drivetrain.
38 * @param gyroAngle The angle reported by the gyroscope.
39 * @param modulePositions The wheel positions reported by each module.
40 * @param initialPose The starting position of the robot on the field.
41 */
42#if defined(__GNUC__) && !defined(__clang__)
43#pragma GCC diagnostic push
44#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
45#endif // defined(__GNUC__) && !defined(__clang__)
47 SwerveDriveKinematics<NumModules> kinematics, const Rotation3d& gyroAngle,
49 const Pose3d& initialPose = Pose3d{})
50 : SwerveDriveOdometry3d::Odometry3d(m_kinematicsImpl, gyroAngle,
51 modulePositions, initialPose),
52 m_kinematicsImpl(kinematics) {
53 wpi::math::MathSharedStore::ReportUsage("SwerveDriveOdometry3d", "");
54 }
55#if defined(__GNUC__) && !defined(__clang__)
56#pragma GCC diagnostic pop
57#endif // defined(__GNUC__) && !defined(__clang__)
58
59 private:
60 SwerveDriveKinematics<NumModules> m_kinematicsImpl;
61};
62
63extern template class EXPORT_TEMPLATE_DECLARE(WPILIB_DLLEXPORT)
64 SwerveDriveOdometry3d<4>;
65
66} // namespace wpi::math
#define EXPORT_TEMPLATE_DECLARE(export)
Definition SymbolExports.hpp:94
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
static void ReportUsage(std::string_view resource, std::string_view data)
Definition MathShared.hpp:61
Class for odometry.
Definition Odometry3d.hpp:31
Odometry3d(const Kinematics< wpi::util::array< SwerveModulePosition, NumModules >, wpi::util::array< SwerveModuleVelocity, NumModules >, wpi::util::array< SwerveModuleAcceleration, NumModules > > &kinematics, const Rotation3d &gyroAngle, const wpi::util::array< SwerveModulePosition, NumModules > &wheelPositions, const Pose3d &initialPose=Pose3d{})
Definition Odometry3d.hpp:41
Represents a 3D pose containing translational and rotational elements.
Definition Pose3d.hpp:28
A rotation in a 3D coordinate frame, represented by a quaternion.
Definition Rotation3d.hpp:69
Helper class that converts a chassis velocity (dx, dy, and dtheta components) into individual module ...
Definition SwerveDriveKinematics.hpp:59
Class for swerve drive odometry.
Definition SwerveDriveOdometry3d.hpp:32
SwerveDriveOdometry3d(SwerveDriveKinematics< NumModules > kinematics, const Rotation3d &gyroAngle, const wpi::util::array< SwerveModulePosition, NumModules > &modulePositions, const Pose3d &initialPose=Pose3d{})
Constructs a SwerveDriveOdometry3d object.
Definition SwerveDriveOdometry3d.hpp:46
This class is a wrapper around std::array that does compile time size checking.
Definition array.hpp:26
Definition LinearSystem.hpp:20
SwerveDriveKinematics(ModuleTranslation, ModuleTranslations...) -> SwerveDriveKinematics< 1+sizeof...(ModuleTranslations)>