WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
RectangularRegionConstraint.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 <concepts>
8#include <limits>
9
13
14namespace frc {
15
16/**
17 * Enforces a particular constraint only within a rectangular region.
18 */
19template <std::derived_from<TrajectoryConstraint> Constraint>
21 public:
22 /**
23 * Constructs a new RectangularRegionConstraint.
24 *
25 * @param bottomLeftPoint The bottom left point of the rectangular region in
26 * which to enforce the constraint.
27 * @param topRightPoint The top right point of the rectangular region in which
28 * to enforce the constraint.
29 * @param constraint The constraint to enforce when the robot is within the
30 * region.
31 * @deprecated Use constructor taking Rectangle2d instead.
32 */
33 [[deprecated("Use constructor taking Rectangle2d instead.")]]
34 constexpr RectangularRegionConstraint(const Translation2d& bottomLeftPoint,
35 const Translation2d& topRightPoint,
36 const Constraint& constraint)
37 : m_rectangle{bottomLeftPoint, topRightPoint}, m_constraint(constraint) {}
38
39 /**
40 * Constructs a new RectangularRegionConstraint.
41 *
42 * @param rectangle The rectangular region in which to enforce the constraint.
43 * @param constraint The constraint to enforce when the robot is within the
44 * region.
45 */
46 constexpr RectangularRegionConstraint(const Rectangle2d& rectangle,
47 const Constraint& constraint)
48 : m_rectangle{rectangle}, m_constraint{constraint} {}
49
50 constexpr units::meters_per_second_t MaxVelocity(
51 const Pose2d& pose, units::curvature_t curvature,
52 units::meters_per_second_t velocity) const override {
53 if (m_rectangle.Contains(pose.Translation())) {
54 return m_constraint.MaxVelocity(pose, curvature, velocity);
55 } else {
56 return units::meters_per_second_t{
57 std::numeric_limits<double>::infinity()};
58 }
59 }
60
62 const Pose2d& pose, units::curvature_t curvature,
63 units::meters_per_second_t speed) const override {
64 if (m_rectangle.Contains(pose.Translation())) {
65 return m_constraint.MinMaxAcceleration(pose, curvature, speed);
66 } else {
67 return {};
68 }
69 }
70
71 private:
72 Rectangle2d m_rectangle;
73 Constraint m_constraint;
74};
75
76} // namespace frc
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.h:28
constexpr const Translation2d & Translation() const
Returns the underlying translation.
Definition Pose2d.h:107
Represents a 2d rectangular space containing translational, rotational, and scaling components.
Definition Rectangle2d.h:25
constexpr bool Contains(const Translation2d &point) const
Checks if a point is contained within the rectangle.
Definition Rectangle2d.h:139
Enforces a particular constraint only within a rectangular region.
Definition RectangularRegionConstraint.h:20
constexpr RectangularRegionConstraint(const Rectangle2d &rectangle, const Constraint &constraint)
Constructs a new RectangularRegionConstraint.
Definition RectangularRegionConstraint.h:46
constexpr 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 RectangularRegionConstraint.h:61
constexpr 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 RectangularRegionConstraint.h:50
constexpr RectangularRegionConstraint(const Translation2d &bottomLeftPoint, const Translation2d &topRightPoint, const Constraint &constraint)
Constructs a new RectangularRegionConstraint.
Definition RectangularRegionConstraint.h:34
An interface for defining user-defined velocity and acceleration constraints while generating traject...
Definition TrajectoryConstraint.h:21
Represents a translation in 2D space.
Definition Translation2d.h:29
Definition CAN.h:11
Represents a minimum and maximum acceleration.
Definition TrajectoryConstraint.h:37