2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-09-28 18:40:56 -04:00
|
|
|
|
|
|
|
|
#include "frc/trajectory/constraint/CentripetalAccelerationConstraint.h"
|
|
|
|
|
|
2020-08-06 23:57:39 -07:00
|
|
|
#include "units/math.h"
|
2020-06-29 22:25:09 -07:00
|
|
|
|
2019-09-28 18:40:56 -04:00
|
|
|
using namespace frc;
|
|
|
|
|
|
|
|
|
|
CentripetalAccelerationConstraint::CentripetalAccelerationConstraint(
|
|
|
|
|
units::meters_per_second_squared_t maxCentripetalAcceleration)
|
|
|
|
|
: m_maxCentripetalAcceleration(maxCentripetalAcceleration) {}
|
|
|
|
|
|
|
|
|
|
units::meters_per_second_t CentripetalAccelerationConstraint::MaxVelocity(
|
2020-03-23 01:57:52 -04:00
|
|
|
const Pose2d& pose, units::curvature_t curvature,
|
2020-04-14 01:32:25 -04:00
|
|
|
units::meters_per_second_t velocity) const {
|
2019-09-28 18:40:56 -04:00
|
|
|
// ac = v^2 / r
|
|
|
|
|
// k (curvature) = 1 / r
|
|
|
|
|
|
|
|
|
|
// therefore, ac = v^2 * k
|
|
|
|
|
// ac / k = v^2
|
|
|
|
|
// v = std::sqrt(ac / k)
|
|
|
|
|
|
|
|
|
|
// We have to multiply by 1_rad here to get the units to cancel out nicely.
|
|
|
|
|
// The units library defines a unit for radians although it is technically
|
|
|
|
|
// unitless.
|
|
|
|
|
return units::math::sqrt(m_maxCentripetalAcceleration /
|
|
|
|
|
units::math::abs(curvature) * 1_rad);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TrajectoryConstraint::MinMax
|
|
|
|
|
CentripetalAccelerationConstraint::MinMaxAcceleration(
|
2020-03-23 01:57:52 -04:00
|
|
|
const Pose2d& pose, units::curvature_t curvature,
|
2020-04-14 01:32:25 -04:00
|
|
|
units::meters_per_second_t speed) const {
|
2019-09-28 18:40:56 -04:00
|
|
|
// The acceleration of the robot has no impact on the centripetal acceleration
|
|
|
|
|
// of the robot.
|
|
|
|
|
return {};
|
|
|
|
|
}
|