mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpimath] Make SwerveDriveKinematics::ToChassisSpeeds() take const-ref argument (#5363)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user