WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
CentripetalAccelerationConstraint.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
8#include "wpi/units/acceleration.hpp"
9#include "wpi/units/curvature.hpp"
10#include "wpi/units/math.hpp"
11#include "wpi/units/velocity.hpp"
13
14namespace wpi::math {
15
16/**
17 * A constraint on the maximum absolute centripetal acceleration allowed when
18 * traversing a trajectory. The centripetal acceleration of a robot is defined
19 * as the velocity squared divided by the radius of curvature.
20 *
21 * Effectively, limiting the maximum centripetal acceleration will cause the
22 * robot to slow down around tight turns, making it easier to track trajectories
23 * with sharp turns.
24 */
26 : public TrajectoryConstraint {
27 public:
29 wpi::units::meters_per_second_squared_t maxCentripetalAcceleration)
30 : m_maxCentripetalAcceleration(maxCentripetalAcceleration) {}
31
32 constexpr wpi::units::meters_per_second_t MaxVelocity(
33 const Pose2d& pose, wpi::units::curvature_t curvature,
34 wpi::units::meters_per_second_t velocity) const override {
35 // ac = v²/r
36 // k (curvature) = 1/r
37
38 // therefore, ac = v²k
39 // ac/k = v²
40 // v = √(ac/k)
41
42 // We have to multiply by 1_rad here to get the units to cancel out nicely.
43 // The units library defines a unit for radians although it is technically
44 // unitless.
45 return wpi::units::math::sqrt(m_maxCentripetalAcceleration /
46 wpi::units::math::abs(curvature) * 1_rad);
47 }
48
50 const Pose2d& pose, wpi::units::curvature_t curvature,
51 wpi::units::meters_per_second_t velocity) const override {
52 // The acceleration of the robot has no impact on the centripetal
53 // acceleration of the robot.
54 return {};
55 }
56
57 private:
58 wpi::units::meters_per_second_squared_t m_maxCentripetalAcceleration;
59};
60} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
constexpr 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 CentripetalAccelerationConstraint.hpp:32
constexpr 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 CentripetalAccelerationConstraint.hpp:49
constexpr CentripetalAccelerationConstraint(wpi::units::meters_per_second_squared_t maxCentripetalAcceleration)
Definition CentripetalAccelerationConstraint.hpp:28
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.hpp:27
constexpr TrajectoryConstraint()=default
Definition LinearSystem.hpp:20
Represents a minimum and maximum acceleration.
Definition TrajectoryConstraint.hpp:36