WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
MecanumDriveKinematicsConstraint.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"
12
13namespace wpi::math {
14/**
15 * A class that enforces constraints on the mecanum drive kinematics.
16 * This can be used to ensure that the trajectory is constructed so that the
17 * commanded velocities for wheels of the drivetrain stay below a certain
18 * limit.
19 */
21 : public TrajectoryConstraint {
22 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 =
33 m_kinematics
34 .ToWheelVelocities({xVelocity, yVelocity, velocity * curvature})
35 .Desaturate(m_maxVelocity);
36
37 auto normVelocities = m_kinematics.ToChassisVelocities(wheelVelocities);
38
39 return wpi::units::math::hypot(normVelocities.vx, normVelocities.vy);
40 }
41
43 const Pose2d& pose, wpi::units::curvature_t curvature,
44 wpi::units::meters_per_second_t velocity) const override {
45 return {};
46 }
47
48 private:
49 MecanumDriveKinematics m_kinematics;
50 wpi::units::meters_per_second_t m_maxVelocity;
51};
52} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
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 MecanumDriveKinematicsConstraint.hpp:27
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 MecanumDriveKinematicsConstraint.hpp:42
MecanumDriveKinematicsConstraint(const MecanumDriveKinematics &kinematics, wpi::units::meters_per_second_t maxVelocity)
Definition MecanumDriveKinematicsConstraint.hpp:23
Helper class that converts a chassis velocity (dx, dy, and dtheta components) into individual wheel v...
Definition MecanumDriveKinematics.hpp:48
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
constexpr TrajectoryConstraint()=default
Definition LinearSystem.hpp:20
Represents a minimum and maximum acceleration.
Definition TrajectoryConstraint.hpp:36