ThunderLib
Loading...
Searching...
No Matches
ThunderAutoSendableChooser.hpp
1#pragma once
2
3#include <ThunderLib/Auto/ThunderAutoProject.hpp>
4#include <ThunderLib/Trajectory/TrajectoryRunnerProperties.hpp>
5#include <frc/smartdashboard/SendableChooser.h>
6#include <frc2/command/CommandPtr.h>
7#include <frc2/command/Command.h>
8#include <string_view>
9#include <string>
10#include <unordered_map>
11#include <memory>
12#include <optional>
13
14namespace thunder {
15
16namespace driver {
17
18class ThunderAutoSendableChooser;
19struct ThunderAutoSendableChooserSelection;
20
21} // namespace driver
22
23 enum class ThunderAutoSendableChooserSelectionType {
24 NONE,
25 AUTO_MODE,
26 TRAJECTORY,
27 CUSTOM_COMMAND,
28 };
29
31 ThunderAutoSendableChooserSelectionType type = ThunderAutoSendableChooserSelectionType::NONE;
32 std::string projectName;
33 std::string itemName;
34 };
35
36
43 public:
48
54 explicit ThunderAutoSendableChooser(std::string_view smartDashboardKey) noexcept;
55
62 explicit ThunderAutoSendableChooser(const TrajectoryRunnerProperties& runnerProps) noexcept;
63
71 ThunderAutoSendableChooser(std::string_view smartDashboardKey,
72 const TrajectoryRunnerProperties& runnerProps) noexcept;
73
75
81 void setTrajectoryRunnerProperties(const TrajectoryRunnerProperties& runnerProps) noexcept;
82
89 void publish(std::string_view smartDashboardKey) noexcept;
90
99 void includeProjectSource(std::shared_ptr<ThunderAutoProject> project,
100 bool addAllAutoModes = false,
101 bool addAllTrajectories = false) noexcept;
102
109 void addAllTrajectoriesFromProject(const std::string& projectName) noexcept;
110
117 void addAllAutoModesFromProject(const std::string& projectName) noexcept;
118
129 bool addTrajectoryFromProject(const std::string& projectName, const std::string& trajectoryName) noexcept;
130
141 bool addAutoModeFromProject(const std::string& projectName, const std::string& autoModeName) noexcept;
142
152 bool addCustomCommand(const std::string& name, frc2::CommandPtr command) noexcept;
153
163 bool addCustomCommand(const std::string& name, std::shared_ptr<frc2::Command> command) noexcept;
164
170 frc2::CommandPtr getSelectedCommand() const noexcept;
171
176
177 driver::ThunderAutoSendableChooser* getHandle() noexcept;
178 const driver::ThunderAutoSendableChooser* getHandle() const noexcept;
179
180 private:
181 // Callbacks
182 void addChooserSelection(const driver::ThunderAutoSendableChooserSelection& selection) noexcept;
183 void publishChooser(const std::string& key) noexcept;
184
185 static ThunderAutoSendableChooserSelection convertChooserSelection(const driver::ThunderAutoSendableChooserSelection& driverSelection) noexcept;
186
187 private:
188 driver::ThunderAutoSendableChooser* m_handle = nullptr;
189 frc::SendableChooser<ThunderAutoSendableChooserSelection> m_chooser;
190
191 std::optional<TrajectoryRunnerProperties> m_runnerProps;
192 std::unordered_map<std::string, std::shared_ptr<ThunderAutoProject>> m_includedProjects;
193
194 std::unordered_map<std::string, std::shared_ptr<frc2::Command>> m_customCommands;
195};
196
197} // namespace thunder
Definition ThunderAutoSendableChooser.hpp:42
void setTrajectoryRunnerProperties(const TrajectoryRunnerProperties &runnerProps) noexcept
Definition ThunderAutoSendableChooser.cpp:40
void publish(std::string_view smartDashboardKey) noexcept
Definition ThunderAutoSendableChooser.cpp:45
void includeProjectSource(std::shared_ptr< ThunderAutoProject > project, bool addAllAutoModes=false, bool addAllTrajectories=false) noexcept
Definition ThunderAutoSendableChooser.cpp:49
void addAllTrajectoriesFromProject(const std::string &projectName) noexcept
Definition ThunderAutoSendableChooser.cpp:56
bool addCustomCommand(const std::string &name, frc2::CommandPtr command) noexcept
Definition ThunderAutoSendableChooser.cpp:69
ThunderAutoSendableChooser() noexcept
Definition ThunderAutoSendableChooser.cpp:11
bool addAutoModeFromProject(const std::string &projectName, const std::string &autoModeName) noexcept
Definition ThunderAutoSendableChooser.cpp:83
ThunderAutoSendableChooserSelection getSelected() const noexcept
Definition ThunderAutoSendableChooser.cpp:124
frc2::CommandPtr getSelectedCommand() const noexcept
Definition ThunderAutoSendableChooser.cpp:88
void addAllAutoModesFromProject(const std::string &projectName) noexcept
Definition ThunderAutoSendableChooser.cpp:60
bool addTrajectoryFromProject(const std::string &projectName, const std::string &trajectoryName) noexcept
Definition ThunderAutoSendableChooser.cpp:64
Definition ThunderAutoSendableChooser.hpp:30
Definition TrajectoryRunnerProperties.hpp:14