PathPlannerLib
Loading...
Searching...
No Matches
AutoBuilder.h
1#pragma once
2
3#include <functional>
4#include <frc2/command/CommandPtr.h>
5#include <frc2/command/Commands.h>
6#include <frc/geometry/Pose2d.h>
7#include <frc/kinematics/ChassisSpeeds.h>
8#include <frc/controller/RamseteController.h>
9#include <vector>
10#include <map>
11#include <frc2/command/Command.h>
12#include <frc/smartdashboard/SendableChooser.h>
13#include <memory>
14#include <wpi/json.h>
15#include <wpi/array.h>
16#include <string>
17#include "pathplanner/lib/path/PathPlannerPath.h"
18#include "pathplanner/lib/config/RobotConfig.h"
19#include "pathplanner/lib/controllers/PathFollowingController.h"
20#include "pathplanner/lib/util/DriveFeedforwards.h"
21#include "pathplanner/lib/util/FlippingUtil.h"
22
23namespace pathplanner {
24
25class PathPlannerAuto;
26
28public:
46 static void configure(std::function<frc::Pose2d()> poseSupplier,
47 std::function<void(const frc::Pose2d&)> resetPose,
48 std::function<frc::ChassisSpeeds()> robotRelativeSpeedsSupplier,
49 std::function<
50 void(const frc::ChassisSpeeds&, const DriveFeedforwards&)> output,
51 std::shared_ptr<PathFollowingController> controller,
52 RobotConfig robotConfig, std::function<bool()> shouldFlipPath,
53 frc2::Subsystem *driveSubsystem);
54
68 static inline void configure(std::function<frc::Pose2d()> poseSupplier,
69 std::function<void(const frc::Pose2d&)> resetPose,
70 std::function<frc::ChassisSpeeds()> robotRelativeSpeedsSupplier,
71 std::function<void(const frc::ChassisSpeeds&)> output,
72 std::shared_ptr<PathFollowingController> controller,
73 RobotConfig robotConfig, std::function<bool()> shouldFlipPath,
74 frc2::Subsystem *driveSubsystem) {
75 configure(poseSupplier, resetPose, robotRelativeSpeedsSupplier,
76 [output](auto &&speeds, auto &&feedforwards) {
77 output(speeds);
78 }, std::move(controller), std::move(robotConfig),
79 shouldFlipPath, driveSubsystem);
80 }
81
96 static void configureCustom(std::function<frc::Pose2d()> poseSupplier,
97 std::function<frc2::CommandPtr(std::shared_ptr<PathPlannerPath>)> pathFollowingCommandBuilder,
98 std::function<void(const frc::Pose2d&)> resetPose, bool isHolonomic,
99 std::function<bool()> shouldFlipPose = []() {
100 return false;
101 });
102
108 static inline bool isConfigured() {
109 return m_configured;
110 }
111
117 static inline bool isHolonomic() {
118 return m_isHolonomic;
119 }
120
126 static inline frc::Pose2d getCurrentPose() {
127 return m_poseSupplier();
128 }
129
135 static inline bool shouldFlip() {
136 return m_shouldFlipPath();
137 }
138
145 static frc2::CommandPtr followPath(std::shared_ptr<PathPlannerPath> path);
146
153 static inline frc2::CommandPtr buildAuto(std::string autoName);
154
161 static frc2::CommandPtr resetOdom(frc::Pose2d bluePose);
162
172 static frc2::CommandPtr pathfindToPose(frc::Pose2d pose,
173 PathConstraints constraints, units::meters_per_second_t goalEndVel =
174 0_mps);
175
187 static frc2::CommandPtr pathfindToPoseFlipped(frc::Pose2d pose,
188 PathConstraints constraints, units::meters_per_second_t goalEndVel =
189 0_mps) {
190 return frc2::cmd::Either(
192 goalEndVel),
193 pathfindToPose(pose, constraints, goalEndVel), m_shouldFlipPath);
194 }
195
204 static frc2::CommandPtr pathfindThenFollowPath(
205 std::shared_ptr<PathPlannerPath> goalPath,
206 PathConstraints pathfindingConstraints);
207
215 static void regenerateSendableReferences();
216
226 static frc::SendableChooser<frc2::Command*> buildAutoChooser(
227 std::string defaultAutoName = "");
228
242 static frc::SendableChooser<frc2::Command*> buildAutoChooserFilter(
243 std::function<bool(const PathPlannerAuto&)> filter,
244 std::string defaultAutoName = "");
245
260 static frc::SendableChooser<frc2::Command*> buildAutoChooserFilterPath(
261 std::function<bool(const PathPlannerAuto&, std::filesystem::path)> filter,
262 std::string defaultAutoName = "");
263
269 static std::vector<std::string> getAllAutoNames();
270
276 static std::vector<std::filesystem::path> getAllAutoPaths();
277
278private:
279 static bool m_configured;
280 static std::function<frc2::CommandPtr(std::shared_ptr<PathPlannerPath>)> m_pathFollowingCommandBuilder;
281 static std::function<frc::Pose2d()> m_poseSupplier;
282 static std::function<void(const frc::Pose2d&)> m_resetPose;
283 static std::function<bool()> m_shouldFlipPath;
284 static bool m_isHolonomic;
285
286 static bool m_commandRefsGeneratedForSendable;
287 static frc2::CommandPtr m_noneCommand;
288 static std::map<std::filesystem::path, frc2::CommandPtr> m_autoCommands;
289
290 static bool m_pathfindingConfigured;
291 static std::function<
292 frc2::CommandPtr(frc::Pose2d, PathConstraints,
293 units::meters_per_second_t)> m_pathfindToPoseCommandBuilder;
294 static std::function<
295 frc2::CommandPtr(std::shared_ptr<PathPlannerPath>, PathConstraints)> m_pathfindThenFollowPathCommandBuilder;
296};
297}
Definition: AutoBuilder.h:27
static frc::SendableChooser< frc2::Command * > buildAutoChooserFilterPath(std::function< bool(const PathPlannerAuto &, std::filesystem::path)> filter, std::string defaultAutoName="")
Definition: AutoBuilder.cpp:179
static frc::SendableChooser< frc2::Command * > buildAutoChooserFilter(std::function< bool(const PathPlannerAuto &)> filter, std::string defaultAutoName="")
Definition: AutoBuilder.cpp:169
static frc::SendableChooser< frc2::Command * > buildAutoChooser(std::string defaultAutoName="")
Definition: AutoBuilder.cpp:160
static frc2::CommandPtr followPath(std::shared_ptr< PathPlannerPath > path)
Definition: AutoBuilder.cpp:99
static frc2::CommandPtr pathfindThenFollowPath(std::shared_ptr< PathPlannerPath > goalPath, PathConstraints pathfindingConstraints)
Definition: AutoBuilder.cpp:138
static frc2::CommandPtr pathfindToPoseFlipped(frc::Pose2d pose, PathConstraints constraints, units::meters_per_second_t goalEndVel=0_mps)
Definition: AutoBuilder.h:187
static std::vector< std::string > getAllAutoNames()
Definition: AutoBuilder.cpp:220
static void regenerateSendableReferences()
Definition: AutoBuilder.cpp:150
static bool isHolonomic()
Definition: AutoBuilder.h:117
static std::vector< std::filesystem::path > getAllAutoPaths()
Definition: AutoBuilder.cpp:230
static frc2::CommandPtr pathfindToPose(frc::Pose2d pose, PathConstraints constraints, units::meters_per_second_t goalEndVel=0_mps)
Definition: AutoBuilder.cpp:128
static frc2::CommandPtr buildAuto(std::string autoName)
Definition: AutoBuilder.cpp:109
static bool isConfigured()
Definition: AutoBuilder.h:108
static bool shouldFlip()
Definition: AutoBuilder.h:135
static void configure(std::function< frc::Pose2d()> poseSupplier, std::function< void(const frc::Pose2d &)> resetPose, std::function< frc::ChassisSpeeds()> robotRelativeSpeedsSupplier, std::function< void(const frc::ChassisSpeeds &)> output, std::shared_ptr< PathFollowingController > controller, RobotConfig robotConfig, std::function< bool()> shouldFlipPath, frc2::Subsystem *driveSubsystem)
Definition: AutoBuilder.h:68
static frc::Pose2d getCurrentPose()
Definition: AutoBuilder.h:126
static frc2::CommandPtr resetOdom(frc::Pose2d bluePose)
Definition: AutoBuilder.cpp:113
static void configure(std::function< frc::Pose2d()> poseSupplier, std::function< void(const frc::Pose2d &)> resetPose, std::function< frc::ChassisSpeeds()> robotRelativeSpeedsSupplier, std::function< void(const frc::ChassisSpeeds &, const DriveFeedforwards &)> output, std::shared_ptr< PathFollowingController > controller, RobotConfig robotConfig, std::function< bool()> shouldFlipPath, frc2::Subsystem *driveSubsystem)
Definition: AutoBuilder.cpp:34
static void configureCustom(std::function< frc::Pose2d()> poseSupplier, std::function< frc2::CommandPtr(std::shared_ptr< PathPlannerPath >)> pathFollowingCommandBuilder, std::function< void(const frc::Pose2d &)> resetPose, bool isHolonomic, std::function< bool()> shouldFlipPose=[]() { return false;})
Definition: AutoBuilder.cpp:80
static frc::Pose2d flipFieldPose(const frc::Pose2d &pose)
Definition: FlippingUtil.h:61
Definition: PathConstraints.h:12
Definition: PathPlannerAuto.h:22
Definition: RobotConfig.h:17
Definition: DriveFeedforwards.h:12