PathPlannerLib
Loading...
Searching...
No Matches
PPLibTelemetry.h
1#pragma once
2
3#include <networktables/NetworkTableInstance.h>
4#include <networktables/DoubleArrayTopic.h>
5#include <networktables/DoubleTopic.h>
6#include <networktables/StructTopic.h>
7#include <networktables/StructArrayTopic.h>
8#include <networktables/NetworkTableListener.h>
9#include <string>
10#include <unordered_map>
11#include <vector>
12#include <memory>
13#include <optional>
14#include <units/velocity.h>
15#include <units/angular_velocity.h>
16#include <units/length.h>
17#include <span>
18#include <frc/geometry/Pose2d.h>
19#include "pathplanner/lib/path/PathPlannerPath.h"
20#include "pathplanner/lib/commands/PathPlannerAuto.h"
21
22namespace pathplanner {
24public:
25 static inline void enableCompetitionMode() {
26 m_compMode = true;
27 }
28
29 static inline void setVelocities(units::meters_per_second_t actualVel,
30 units::meters_per_second_t commandedVel,
31 units::degrees_per_second_t actualAngVel,
32 units::degrees_per_second_t commandedAngVel) {
33 if (!m_compMode) {
34 m_velPub.Set(std::span<const double>( { actualVel(), commandedVel(),
35 actualAngVel(), commandedAngVel() }));
36 }
37 }
38
39 static inline void setCurrentPose(frc::Pose2d pose) {
40 if (!m_compMode) {
41 m_posePub.Set(pose);
42 }
43 }
44
45 static inline void setCurrentPath(std::shared_ptr<PathPlannerPath> path) {
46 if (!m_compMode) {
47 auto poses = path->getPathPoses();
48 m_pathPub.Set(std::span { poses.data(), poses.size() });
49 }
50 }
51
52 static inline void setTargetPose(frc::Pose2d targetPose) {
53 if (!m_compMode) {
54 m_targetPosePub.Set(targetPose);
55 }
56 }
57
58 static void registerHotReloadPath(std::string pathName,
59 std::shared_ptr<PathPlannerPath> path);
60
61private:
62 static void ensureHotReloadListenersInitialized();
63
64 static void handlePathHotReloadEvent(const nt::Event &event);
65
66 static bool m_compMode;
67
68 static nt::DoubleArrayPublisher m_velPub;
69 static nt::StructPublisher<frc::Pose2d> m_posePub;
70 static nt::StructArrayPublisher<frc::Pose2d> m_pathPub;
71 static nt::StructPublisher<frc::Pose2d> m_targetPosePub;
72
73 static std::unordered_map<std::string,
74 std::vector<std::shared_ptr<PathPlannerPath>>> m_hotReloadPaths;
75
76 static std::optional<NT_Listener> m_hotReloadPathListener;
77};
78}
Definition: PPLibTelemetry.h:23