PathPlannerLib
Loading...
Searching...
No Matches
EventScheduler.h
1#pragma once
2
3#include <vector>
4#include <deque>
5#include <memory>
6#include <frc2/command/Command.h>
7#include <wpi/SmallSet.h>
8#include <frc/event/EventLoop.h>
9#include <functional>
10#include "pathplanner/lib/events/Event.h"
11#include "pathplanner/lib/trajectory/PathPlannerTrajectory.h"
12#include "pathplanner/lib/path/PathPlannerPath.h"
13
14namespace pathplanner {
16public:
19 }
20
27 inline void initialize(PathPlannerTrajectory trajectory) {
28 m_eventCommands.clear();
29 m_upcomingEvents.clear();
30 auto events = trajectory.getEvents();
31 m_upcomingEvents.insert(m_upcomingEvents.end(), events.begin(),
32 events.end());
33 }
34
41 void execute(units::second_t time);
42
47 void end();
48
55 static inline wpi::SmallSet<frc2::Subsystem*, 4> getSchedulerRequirements(
56 std::shared_ptr<PathPlannerPath> path) {
57 wpi::SmallSet<frc2::Subsystem*, 4> allReqs;
58 for (auto m : path->getEventMarkers()) {
59 auto markerReqs = m.getCommand()->GetRequirements();
60 allReqs.insert(markerReqs.begin(), markerReqs.end());
61 }
62 return allReqs;
63 }
64
71 void scheduleCommand(std::shared_ptr<frc2::Command> command);
72
78 void cancelCommand(std::shared_ptr<frc2::Command> command);
79
80 static inline frc::EventLoop* getEventLoop() {
81 static frc::EventLoop *eventLoop = new frc::EventLoop();
82 return eventLoop;
83 }
84
85private:
86 std::vector<std::pair<std::shared_ptr<frc2::Command>, bool>> m_eventCommands;
87 std::deque<std::shared_ptr<Event>> m_upcomingEvents;
88};
89}
Definition: EventScheduler.h:15
static wpi::SmallSet< frc2::Subsystem *, 4 > getSchedulerRequirements(std::shared_ptr< PathPlannerPath > path)
Definition: EventScheduler.h:55
void scheduleCommand(std::shared_ptr< frc2::Command > command)
Definition: EventScheduler.cpp:48
void cancelCommand(std::shared_ptr< frc2::Command > command)
Definition: EventScheduler.cpp:70
void initialize(PathPlannerTrajectory trajectory)
Definition: EventScheduler.h:27
void execute(units::second_t time)
Definition: EventScheduler.cpp:5
void end()
Definition: EventScheduler.cpp:29
EventScheduler()
Definition: EventScheduler.h:18
Definition: PathPlannerTrajectory.h:29
std::vector< std::shared_ptr< Event > > getEvents()
Definition: PathPlannerTrajectory.h:71