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