WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
SwerveDriveKinematicsConstraint.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
9#include "wpi/units/math.hpp"
10#include "wpi/units/velocity.hpp"
11
12namespace wpi::math {
13
14/**
15 * A class that enforces constraints on the swerve drive kinematics.
16 * This can be used to ensure that the trajectory is constructed so that the
17 * commanded velocities of the wheels stay below a certain limit.
18 */
19template <size_t NumModules>
21 public:
24 wpi::units::meters_per_second_t maxVelocity)
25 : m_kinematics(kinematics), m_maxVelocity(maxVelocity) {}
26
27 wpi::units::meters_per_second_t MaxVelocity(
28 const Pose2d& pose, wpi::units::curvature_t curvature,
29 wpi::units::meters_per_second_t velocity) const override {
30 auto xVelocity = velocity * pose.Rotation().Cos();
31 auto yVelocity = velocity * pose.Rotation().Sin();
32 auto wheelVelocities = m_kinematics.ToSwerveModuleVelocities(
33 {xVelocity, yVelocity, velocity * curvature});
34 m_kinematics.DesaturateWheelVelocities(&wheelVelocities, m_maxVelocity);
35
36 auto normVelocities = m_kinematics.ToChassisVelocities(wheelVelocities);
37
38 return wpi::units::math::hypot(normVelocities.vx, normVelocities.vy);
39 }
40
42 const Pose2d& pose, wpi::units::curvature_t curvature,
43 wpi::units::meters_per_second_t velocity) const override {
44 return {};
45 }
46
47 private:
49 wpi::units::meters_per_second_t m_maxVelocity;
50};
51
52} // namespace wpi::math
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.hpp:27
constexpr const Rotation2d & Rotation() const
Returns the underlying rotation.
Definition Pose2d.hpp:128
constexpr double Cos() const
Returns the cosine of the rotation.
Definition Rotation2d.hpp:235
constexpr double Sin() const
Returns the sine of the rotation.
Definition Rotation2d.hpp:242
wpi::units::meters_per_second_t MaxVelocity(const Pose2d &pose, wpi::units::curvature_t curvature, wpi::units::meters_per_second_t velocity) const override
Returns the max velocity given the current pose and curvature.
Definition SwerveDriveKinematicsConstraint.hpp:27
SwerveDriveKinematicsConstraint(const wpi::math::SwerveDriveKinematics< NumModules > &kinematics, wpi::units::meters_per_second_t maxVelocity)
Definition SwerveDriveKinematicsConstraint.hpp:22
MinMax MinMaxAcceleration(const Pose2d &pose, wpi::units::curvature_t curvature, wpi::units::meters_per_second_t velocity) const override
Returns the minimum and maximum allowable acceleration for the trajectory given pose,...
Definition SwerveDriveKinematicsConstraint.hpp:41
Helper class that converts a chassis velocity (dx, dy, and dtheta components) into individual module ...
Definition SwerveDriveKinematics.hpp:59
constexpr TrajectoryConstraint()=default
Definition LinearSystem.hpp:20
Represents a minimum and maximum acceleration.
Definition TrajectoryConstraint.hpp:36