PathPlannerLib
Loading...
Searching...
No Matches
PointTowardsZoneTrigger.h
1#pragma once
2
3#include <frc2/command/button/Trigger.h>
4#include <string>
5#include <unordered_map>
6#include "pathplanner/lib/events/EventScheduler.h"
7
8namespace pathplanner {
9class PointTowardsZoneTrigger: public frc2::Trigger {
10public:
16 PointTowardsZoneTrigger(std::string name) : frc2::Trigger(
17 EventScheduler::getEventLoop(), pollCondition(name)) {
18 }
19
27 PointTowardsZoneTrigger(frc::EventLoop *eventLoop, std::string name) : frc2::Trigger(
28 eventLoop, pollCondition(name)) {
29 }
30
31 static inline void setWithinZone(std::string name, bool withinZone) {
32 getZoneConditions()[name] = withinZone;
33 }
34
35private:
36
37 static inline std::unordered_map<std::string, bool>& getZoneConditions() {
38 static std::unordered_map<std::string, bool> *zoneConditions =
39 new std::unordered_map<std::string, bool>();
40 return *zoneConditions;
41 }
42
49 static inline std::function<bool()> pollCondition(std::string name) {
50 // Ensure there is a condition in the map for this name
51 if (!getZoneConditions().contains(name)) {
52 getZoneConditions().emplace(name, false);
53 }
54
55 return [name]() {
56 return getZoneConditions()[name];
57 };
58 }
59};
60}
Definition: EventScheduler.h:15
Definition: PointTowardsZoneTrigger.h:9
PointTowardsZoneTrigger(frc::EventLoop *eventLoop, std::string name)
Definition: PointTowardsZoneTrigger.h:27
PointTowardsZoneTrigger(std::string name)
Definition: PointTowardsZoneTrigger.h:16