WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
MecanumDriveKinematicsConstraint.h
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 <cmath>
8
9#include <wpi/SymbolExports.h>
10
13#include "units/math.h"
14#include "units/velocity.h"
15
16namespace frc {
17/**
18 * A class that enforces constraints on the mecanum drive kinematics.
19 * This can be used to ensure that the trajectory is constructed so that the
20 * commanded velocities for wheels of the drivetrain stay below a certain
21 * limit.
22 */
24 : public TrajectoryConstraint {
25 public:
27 units::meters_per_second_t maxSpeed)
28 : m_kinematics(kinematics), m_maxSpeed(maxSpeed) {}
29
30 units::meters_per_second_t MaxVelocity(
31 const Pose2d& pose, units::curvature_t curvature,
32 units::meters_per_second_t velocity) const override {
33 auto xVelocity = velocity * pose.Rotation().Cos();
34 auto yVelocity = velocity * pose.Rotation().Sin();
35 auto wheelSpeeds = m_kinematics.ToWheelSpeeds(
36 {xVelocity, yVelocity, velocity * curvature});
37 wheelSpeeds.Desaturate(m_maxSpeed);
38
39 auto normSpeeds = m_kinematics.ToChassisSpeeds(wheelSpeeds);
40
41 return units::math::hypot(normSpeeds.vx, normSpeeds.vy);
42 }
43
45 units::meters_per_second_t speed) const override {
46 return {};
47 }
48
49 private:
50 MecanumDriveKinematics m_kinematics;
51 units::meters_per_second_t m_maxSpeed;
52};
53} // namespace frc
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
A class that enforces constraints on the mecanum drive kinematics.
Definition MecanumDriveKinematicsConstraint.h:24
MinMax MinMaxAcceleration(const Pose2d &pose, units::curvature_t curvature, units::meters_per_second_t speed) const override
Returns the minimum and maximum allowable acceleration for the trajectory given pose,...
Definition MecanumDriveKinematicsConstraint.h:44
units::meters_per_second_t MaxVelocity(const Pose2d &pose, units::curvature_t curvature, units::meters_per_second_t velocity) const override
Returns the max velocity given the current pose and curvature.
Definition MecanumDriveKinematicsConstraint.h:30
MecanumDriveKinematicsConstraint(const MecanumDriveKinematics &kinematics, units::meters_per_second_t maxSpeed)
Definition MecanumDriveKinematicsConstraint.h:26
Helper class that converts a chassis velocity (dx, dy, and dtheta components) into individual wheel s...
Definition MecanumDriveKinematics.h:44
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.h:28
constexpr const Rotation2d & Rotation() const
Returns the underlying rotation.
Definition Pose2d.h:128
constexpr double Cos() const
Returns the cosine of the rotation.
Definition Rotation2d.h:231
constexpr double Sin() const
Returns the sine of the rotation.
Definition Rotation2d.h:238
An interface for defining user-defined velocity and acceleration constraints while generating traject...
Definition TrajectoryConstraint.h:21
constexpr UnitTypeLhs hypot(const UnitTypeLhs &x, const UnitTypeRhs &y)
Computes the square root of the sum-of-squares of x and y.
Definition math.h:508
Definition CAN.h:11
Represents a minimum and maximum acceleration.
Definition TrajectoryConstraint.h:37