3#include "pathplanner/lib/path/RotationTarget.h"
4#include "pathplanner/lib/path/PointTowardsZone.h"
5#include "pathplanner/lib/path/ConstraintsZone.h"
6#include "pathplanner/lib/path/EventMarker.h"
7#include "pathplanner/lib/path/PathConstraints.h"
8#include "pathplanner/lib/path/IdealStartingState.h"
9#include "pathplanner/lib/path/GoalEndState.h"
10#include "pathplanner/lib/path/PathPoint.h"
11#include "pathplanner/lib/path/Waypoint.h"
12#include "pathplanner/lib/trajectory/PathPlannerTrajectory.h"
13#include "pathplanner/lib/config/RobotConfig.h"
16#include <frc/geometry/Translation2d.h>
17#include <frc/kinematics/ChassisSpeeds.h>
20#include <unordered_map>
21#include <units/length.h>
23#include <initializer_list>
25namespace pathplanner {
29 bool preventFlipping =
false;
46 std::vector<RotationTarget> rotationTargets,
47 std::vector<PointTowardsZone> pointTowardsZones,
48 std::vector<ConstraintsZone> constraintZones,
49 std::vector<EventMarker> eventMarkers,
51 std::optional<IdealStartingState> idealStartingState,
67 std::optional<IdealStartingState> idealStartingState,
71 std::vector<
EventMarker>(), constraints, idealStartingState,
72 goalEndState, reversed) {
80 void hotReload(
const wpi::json &json);
89 std::vector<frc::Pose2d> poses);
97 [[deprecated(
"Renamed to waypointsFromPoses")]]
99 std::vector<frc::Pose2d> poses) {
109 static std::shared_ptr<PathPlannerPath>
fromPathFile(std::string pathName);
119 std::string trajectoryName);
130 std::string trajectoryName,
size_t splitIndex) {
131 std::string cacheName = trajectoryName +
"."
132 + std::to_string(splitIndex);
133 if (getChoreoPathCache().contains(cacheName)) {
134 return getChoreoPathCache()[cacheName];
138 loadChoreoTrajectoryIntoCache(trajectoryName);
139 return getChoreoPathCache()[cacheName];
162 std::vector<PathPoint> pathPoints,
180 return m_allPoints.size();
190 return m_allPoints[index];
227 return m_rotationTargets;
236 return m_pointTowardsZones;
244 return m_constraintZones;
253 return m_globalConstraints;
262 return m_goalEndState;
271 return m_idealStartingState;
280 return m_eventMarkers;
298 return m_isChoreoPath;
302 frc::ChassisSpeeds startingSpeeds, frc::Rotation2d startingRotation,
304 if (m_isChoreoPath) {
305 return m_idealTrajectory.value();
307 return PathPlannerTrajectory(shared_from_this(), startingSpeeds,
308 startingRotation, config);
317 std::shared_ptr<PathPlannerPath>
flipPath();
326 std::shared_ptr<PathPlannerPath>
mirrorPath();
335 std::vector < frc::Pose2d > poses;
336 for (
const PathPoint &point : m_allPoints) {
337 poses.emplace_back(point.position, frc::Rotation2d());
344 PathPlannerPath::getPathCache().clear();
345 PathPlannerPath::getChoreoPathCache().clear();
349 std::vector<PathPoint> createPath();
351 static std::shared_ptr<PathPlannerPath> fromJson(
const wpi::json &json);
353 static inline std::vector<Waypoint> waypointsFromJson(
354 const wpi::json &waypointsJson) {
355 std::vector < Waypoint > waypoints;
356 for (wpi::json::const_reference waypoint : waypointsJson) {
362 static void loadChoreoTrajectoryIntoCache(std::string trajectoryName);
364 void precalcValues();
366 static units::meter_t getCurveRadiusAtPoint(
size_t index,
367 std::vector<PathPoint> &points);
369 inline PathConstraints constraintsForWaypointPos(
double pos)
const {
370 for (
auto z : m_constraintZones) {
371 if (pos >= z.getMinWaypointRelativePos()
372 && pos <= z.getMaxWaypointRelativePos()) {
373 return z.getConstraints();
378 if (m_globalConstraints.isUnlimited()) {
383 return m_globalConstraints;
386 inline std::optional<PointTowardsZone> pointZoneForWaypointPos(
388 for (
auto z : m_pointTowardsZones) {
389 if (pos >= z.getMinWaypointRelativePos()
390 && pos <= z.getMaxWaypointRelativePos()) {
397 static frc::Translation2d mirrorTranslation(frc::Translation2d translation);
399 frc::Translation2d samplePath(
double waypointRelativePos)
const;
401 static std::unordered_map<std::string, std::shared_ptr<PathPlannerPath>>& getPathCache();
403 static std::unordered_map<std::string, std::shared_ptr<PathPlannerPath>>& getChoreoPathCache();
405 std::vector<Waypoint> m_waypoints;
406 std::vector<RotationTarget> m_rotationTargets;
407 std::vector<PointTowardsZone> m_pointTowardsZones;
408 std::vector<ConstraintsZone> m_constraintZones;
409 std::vector<EventMarker> m_eventMarkers;
410 PathConstraints m_globalConstraints;
411 std::optional<IdealStartingState> m_idealStartingState;
412 GoalEndState m_goalEndState;
413 std::vector<PathPoint> m_allPoints;
417 std::optional<PathPlannerTrajectory> m_idealTrajectory = std::nullopt;
419 static int m_instances;
421 static constexpr double targetIncrement = 0.05;
422 static constexpr units::meter_t targetSpacing = 0.2_m;
Definition: ConstraintsZone.h:7
Definition: EventMarker.h:11
Definition: GoalEndState.h:9
Definition: PathConstraints.h:12
static constexpr PathConstraints unlimitedConstraints(units::volt_t nominalVoltage)
Definition: PathConstraints.h:48
constexpr units::volt_t getNominalVoltage() const
Definition: PathConstraints.h:99
Definition: PathPlannerPath.h:26
static std::shared_ptr< PathPlannerPath > fromPathFile(std::string pathName)
Definition: PathPlannerPath.cpp:107
constexpr std::vector< ConstraintsZone > & getConstraintZones()
Definition: PathPlannerPath.h:243
frc::Pose2d getStartingDifferentialPose()
Definition: PathPlannerPath.cpp:627
std::optional< frc::Pose2d > getStartingHolonomicPose()
Definition: PathPlannerPath.cpp:640
const PathPoint & getPoint(size_t index) const
Definition: PathPlannerPath.h:189
frc::Rotation2d getInitialHeading() const
Definition: PathPlannerPath.h:210
constexpr std::vector< Waypoint > & getWaypoints()
Definition: PathPlannerPath.h:218
static std::shared_ptr< PathPlannerPath > fromChoreoTrajectory(std::string trajectoryName, size_t splitIndex)
Definition: PathPlannerPath.h:129
static std::shared_ptr< PathPlannerPath > fromPathPoints(std::vector< PathPoint > pathPoints, PathConstraints globalConstraints, GoalEndState goalEndState)
Definition: PathPlannerPath.cpp:381
static std::vector< Waypoint > bezierFromPoses(std::vector< frc::Pose2d > poses)
Definition: PathPlannerPath.h:98
constexpr const GoalEndState & getGoalEndState() const
Definition: PathPlannerPath.h:261
static std::vector< Waypoint > waypointsFromPoses(std::vector< frc::Pose2d > poses)
Definition: PathPlannerPath.cpp:76
std::vector< frc::Pose2d > getPathPoses() const
Definition: PathPlannerPath.h:334
constexpr const std::vector< PathPoint > & getAllPathPoints() const
Definition: PathPlannerPath.h:170
constexpr const PathConstraints & getGlobalConstraints() const
Definition: PathPlannerPath.h:252
constexpr bool isReversed() const
Definition: PathPlannerPath.h:288
constexpr std::vector< EventMarker > & getEventMarkers()
Definition: PathPlannerPath.h:279
size_t numPoints() const
Definition: PathPlannerPath.h:179
std::shared_ptr< PathPlannerPath > flipPath()
Definition: PathPlannerPath.cpp:722
static std::shared_ptr< PathPlannerPath > fromChoreoTrajectory(std::string trajectoryName)
Definition: PathPlannerPath.cpp:946
constexpr std::vector< RotationTarget > & getRotationTargets()
Definition: PathPlannerPath.h:226
PathPlannerPath(std::vector< Waypoint > waypoints, PathConstraints constraints, std::optional< IdealStartingState > idealStartingState, GoalEndState goalEndState, bool reversed=false)
Definition: PathPlannerPath.h:65
constexpr const std::optional< IdealStartingState > & getIdealStartingState() const
Definition: PathPlannerPath.h:270
std::shared_ptr< PathPlannerPath > mirrorPath()
Definition: PathPlannerPath.cpp:784
std::optional< PathPlannerTrajectory > getIdealTrajectory(RobotConfig robotConfig)
Definition: PathPlannerPath.cpp:651
static void clearPathCache()
Definition: PathPlannerPath.h:343
constexpr std::vector< PointTowardsZone > & getPointTowardsZones()
Definition: PathPlannerPath.h:235
constexpr bool isChoreoPath() const
Definition: PathPlannerPath.h:297
Definition: PathPlannerTrajectory.h:29
Definition: PathPoint.h:13
Definition: PointTowardsZone.h:11
Definition: RobotConfig.h:17
Definition: RotationTarget.h:7
static Waypoint fromJson(const wpi::json &waypointJson)
Definition: Waypoint.cpp:26