[wpimath] Make SwerveDriveKinematics::ToChassisSpeeds() take const-ref argument (#5363)

This commit is contained in:
Tyler Veness
2023-05-30 23:34:39 -07:00
committed by GitHub
parent 51066a5a8a
commit 125f6ea101
2 changed files with 12 additions and 5 deletions

View File

@@ -5,6 +5,7 @@
#pragma once
#include <cstddef>
#include <type_traits>
#include <wpi/SymbolExports.h>
#include <wpi/array.h>
@@ -146,7 +147,10 @@ class SwerveDriveKinematics {
* @return The resulting chassis speed.
*/
template <typename... ModuleStates>
ChassisSpeeds ToChassisSpeeds(ModuleStates&&... wheelStates) const;
requires(std::is_same_v<std::remove_reference_t<ModuleStates>,
SwerveModuleState>&&...) ChassisSpeeds
ToChassisSpeeds(ModuleStates&&... wheelStates)
const;
/**
* Performs forward kinematics to return the resulting chassis state from the
@@ -162,7 +166,7 @@ class SwerveDriveKinematics {
* @return The resulting chassis speed.
*/
ChassisSpeeds ToChassisSpeeds(
wpi::array<SwerveModuleState, NumModules> moduleStates) const;
const wpi::array<SwerveModuleState, NumModules>& moduleStates) const;
/**
* Performs forward kinematics to return the resulting Twist2d from the

View File

@@ -66,8 +66,11 @@ SwerveDriveKinematics<NumModules>::ToSwerveModuleStates(
template <size_t NumModules>
template <typename... ModuleStates>
ChassisSpeeds SwerveDriveKinematics<NumModules>::ToChassisSpeeds(
ModuleStates&&... wheelStates) const {
requires(std::is_same_v<std::remove_reference_t<ModuleStates>,
SwerveModuleState>&&...)
ChassisSpeeds SwerveDriveKinematics<NumModules>::ToChassisSpeeds(
ModuleStates&&... wheelStates)
const {
static_assert(sizeof...(wheelStates) == NumModules,
"Number of modules is not consistent with number of wheel "
"locations provided in constructor.");
@@ -79,7 +82,7 @@ ChassisSpeeds SwerveDriveKinematics<NumModules>::ToChassisSpeeds(
template <size_t NumModules>
ChassisSpeeds SwerveDriveKinematics<NumModules>::ToChassisSpeeds(
wpi::array<SwerveModuleState, NumModules> moduleStates) const {
const wpi::array<SwerveModuleState, NumModules>& moduleStates) const {
Matrixd<NumModules * 2, 1> moduleStateMatrix;
for (size_t i = 0; i < NumModules; ++i) {