PathPlannerLib
Loading...
Searching...
No Matches
PathPlannerTrajectory.h
1#pragma once
2
3#include <units/time.h>
4#include <units/length.h>
5#include <units/velocity.h>
6#include <units/acceleration.h>
7#include <units/angular_velocity.h>
8#include <units/curvature.h>
9#include <frc/geometry/Translation2d.h>
10#include <frc/geometry/Rotation2d.h>
11#include <frc/geometry/Pose2d.h>
12#include <frc/kinematics/ChassisSpeeds.h>
13#include <frc/kinematics/SwerveModuleState.h>
14#include <frc/MathUtil.h>
15#include <frc2/command/Command.h>
16#include <vector>
17#include <utility>
18#include <memory>
19#include "pathplanner/lib/trajectory/PathPlannerTrajectoryState.h"
20#include "pathplanner/lib/path/PathConstraints.h"
21#include "pathplanner/lib/util/GeometryUtil.h"
22#include "pathplanner/lib/config/RobotConfig.h"
23#include "pathplanner/lib/events/Event.h"
24
25namespace pathplanner {
26
27class PathPlannerPath;
28
30public:
32 }
33
40 PathPlannerTrajectory(std::vector<PathPlannerTrajectoryState> states,
41 std::vector<std::shared_ptr<Event>> events) : m_states(states), m_events(
42 events) {
43 }
44
50 PathPlannerTrajectory(std::vector<PathPlannerTrajectoryState> states) : m_states(
51 states) {
52 }
53
62 PathPlannerTrajectory(std::shared_ptr<PathPlannerPath> path,
63 const frc::ChassisSpeeds &startingSpeeds,
64 const frc::Rotation2d &startingRotation, const RobotConfig &config);
65
71 inline std::vector<std::shared_ptr<Event>> getEvents() {
72 return m_events;
73 }
74
80 constexpr std::vector<PathPlannerTrajectoryState>& getStates() {
81 return m_states;
82 }
83
90 inline PathPlannerTrajectoryState getState(size_t index) {
91 return m_states[index];
92 }
93
100 return m_states[0];
101 }
102
109 return m_states[m_states.size() - 1];
110 }
111
117 inline units::second_t getTotalTime() {
118 return getEndState().time;
119 }
120
126 inline frc::Pose2d getInitialPose() {
127 return getInitialState().pose;
128 }
129
136 PathPlannerTrajectoryState sample(const units::second_t time);
137
144 std::vector < PathPlannerTrajectoryState > mirroredStates;
145 for (auto state : m_states) {
146 mirroredStates.emplace_back(state.flip());
147 }
148 return PathPlannerTrajectory(mirroredStates, getEvents());
149 }
150private:
151 std::vector<PathPlannerTrajectoryState> m_states;
152 std::vector<std::shared_ptr<Event>> m_events;
153
154 static void generateStates(std::vector<PathPlannerTrajectoryState> &states,
155 std::shared_ptr<PathPlannerPath> path,
156 const frc::Rotation2d &startingRotation, const RobotConfig &config);
157
158 static void forwardAccelPass(
159 std::vector<PathPlannerTrajectoryState> &states,
160 const RobotConfig &config);
161
162 static void reverseAccelPass(
163 std::vector<PathPlannerTrajectoryState> &states,
164 const RobotConfig &config);
165
166 static void desaturateWheelSpeeds(
167 std::vector<SwerveModuleTrajectoryState> &moduleStates,
168 const frc::ChassisSpeeds &desiredSpeeds,
169 units::meters_per_second_t maxModuleSpeed,
170 units::meters_per_second_t maxTranslationSpeed,
171 units::radians_per_second_t maxRotationSpeed);
172
173 static size_t getNextRotationTargetIdx(
174 std::shared_ptr<PathPlannerPath> path, const size_t startingIndex);
175
176 static inline frc::Rotation2d cosineInterpolate(const frc::Rotation2d start,
177 const frc::Rotation2d end, const double t) {
178 double t2 = (1.0 - std::cos(t * M_PI)) / 2.0;
179 return GeometryUtil::rotationLerp(start, end, t2);
180 }
181};
182}
Definition: PathPlannerTrajectoryState.h:17
Definition: PathPlannerTrajectory.h:29
frc::Pose2d getInitialPose()
Definition: PathPlannerTrajectory.h:126
units::second_t getTotalTime()
Definition: PathPlannerTrajectory.h:117
PathPlannerTrajectory flip()
Definition: PathPlannerTrajectory.h:143
PathPlannerTrajectoryState sample(const units::second_t time)
Definition: PathPlannerTrajectory.cpp:210
PathPlannerTrajectory(std::vector< PathPlannerTrajectoryState > states)
Definition: PathPlannerTrajectory.h:50
constexpr std::vector< PathPlannerTrajectoryState > & getStates()
Definition: PathPlannerTrajectory.h:80
std::vector< std::shared_ptr< Event > > getEvents()
Definition: PathPlannerTrajectory.h:71
PathPlannerTrajectoryState getState(size_t index)
Definition: PathPlannerTrajectory.h:90
PathPlannerTrajectoryState getInitialState()
Definition: PathPlannerTrajectory.h:99
PathPlannerTrajectoryState getEndState()
Definition: PathPlannerTrajectory.h:108
PathPlannerTrajectory(std::vector< PathPlannerTrajectoryState > states, std::vector< std::shared_ptr< Event > > events)
Definition: PathPlannerTrajectory.h:40
Definition: RobotConfig.h:17