Valkyrie 2026
Loading...
Searching...
No Matches
BaseSubsystem.h
1#pragma once
2
3#include <memory>
4#include <string>
5
6#include <frc/DriverStation.h>
7#include <frc/TimedRobot.h>
8#include <frc/Timer.h>
9#include <frc2/command/SubsystemBase.h>
10#include <networktables/NetworkTable.h>
11#include <networktables/NetworkTableEntry.h>
12#include <networktables/NetworkTableInstance.h>
13#include <wpi/sendable/Sendable.h>
14#include <wpi/sendable/SendableBuilder.h>
15#include <wpi/sendable/SendableHelper.h>
16
17#include "valkyrie/Gamepad.h"
18#include "valkyrie/Loggable.h"
19#include "valkyrie/util/Profiler.h"
20
21namespace valor {
22
51class BaseSubsystem : public frc2::Subsystem, public valor::Loggable {
52 public:
62 explicit BaseSubsystem(std::string name) : Loggable{name}, operatorGamepad(nullptr), driverGamepad(nullptr) {
63 frc2::CommandScheduler::GetInstance().RegisterSubsystem(this);
64 profiler.Start();
65 }
66
83 virtual void AnalyzeDashboard() {}
84
106 virtual void AssessInputs() {}
107
134 virtual void AssignOutputs() {}
135
147 virtual void Reset() {}
148
149 void SetGamepads(valor::Gamepad* _operatorGamepad, valor::Gamepad* _driverGamepad) {
150 operatorGamepad = _operatorGamepad;
151 driverGamepad = _driverGamepad;
152 }
153
154 protected:
155 valor::Gamepad* operatorGamepad;
156 valor::Gamepad* driverGamepad;
157
158 private:
159 void Periodic() {
160 profiler.Reset();
161 if (frc::DriverStation::IsTeleopEnabled())
162 AssessInputs();
163 units::millisecond_t assessInputsTime = profiler.Get();
164
166 units::millisecond_t analyzeDashboardTime = profiler.Get() - assessInputsTime;
167
168 if (frc::DriverStation::IsEnabled())
170 units::millisecond_t assignOutputsTime = profiler.Get() - analyzeDashboardTime;
171 if (util::Profiler::IsEnabled()) {
172 WriteLog("Profiler/Cycle Time", units::millisecond_t{profiler.Get()});
173 WriteLog("Profiler/Assign Outputs Time", assignOutputsTime);
174 WriteLog("Profiler/Assess Inputs Time", assessInputsTime);
175 WriteLog("Profiler/Analyze Dashboard Time", analyzeDashboardTime);
176 }
177 }
178
179 frc::Timer profiler;
180};
181} // namespace valor
BaseSubsystem(std::string name)
Construct a new Valor Subsystem object.
Definition BaseSubsystem.h:62
virtual void AnalyzeDashboard()
Synchronize dashboard data (both read and write).
Definition BaseSubsystem.h:83
virtual void AssessInputs()
Read controller logic and set subsystem state.
Definition BaseSubsystem.h:106
virtual void AssignOutputs()
Read subsystem state and send motor commands.
Definition BaseSubsystem.h:134
virtual void Reset()
Reset all subsystem state.
Definition BaseSubsystem.h:147
Enhanced wrapper around frc::XboxController.
Definition Gamepad.h:24
Base helper for publishing and subscribing values to NetworkTables.
Definition Loggable.h:218
T WriteLog(std::string_view field, const T &data, LogLevel level=LogLevel::Normal)
Publish a value to NetworkTables under the given field.
Definition Loggable.h:326
Loggable(std::string_view name)
Construct a Loggable that registers a top-level table name.