Valor 6800 1.0
Loading...
Searching...
No Matches
BaseSubsystem.h
1
2#pragma once
3
4#include <memory>
5#include <string>
6
7#include <frc/DriverStation.h>
8#include <frc/TimedRobot.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#include <frc/Timer.h>
17
18#include "valkyrie/Gamepad.h"
19#include "valkyrie/Loggable.h"
20#include "valkyrie/util/Profiler.h"
21
22namespace valor {
23
52class BaseSubsystem : public frc2::Subsystem, public valor::Loggable {
53 public:
63 explicit BaseSubsystem(std::string name) : Loggable{name}, operatorGamepad(nullptr), driverGamepad(nullptr) {
64 frc2::CommandScheduler::GetInstance().RegisterSubsystem(this);
65 profiler.Start();
66 }
67
84 virtual void analyzeDashboard() {}
85
107 virtual void assessInputs() {}
108
135 virtual void assignOutputs() {}
136
148 virtual void reset() {}
149
150 void setGamepads(valor::Gamepad* _operatorGamepad, valor::Gamepad* _driverGamepad) {
151 operatorGamepad = _operatorGamepad;
152 driverGamepad = _driverGamepad;
153 }
154
155 protected:
156 valor::Gamepad* operatorGamepad;
157 valor::Gamepad* driverGamepad;
158
159 private:
160 void Periodic() {
161 profiler.Reset();
162 if (frc::DriverStation::IsTeleopEnabled())
163 assessInputs();
164 units::millisecond_t assessInputsTime = profiler.Get();
165
167 units::millisecond_t analyzeDashboardTime = profiler.Get() - assessInputsTime;
168
169 if (frc::DriverStation::IsEnabled())
171 units::millisecond_t assignOutputsTime = profiler.Get() - analyzeDashboardTime;
172 if (util::Profiler::IsEnabled()) {
173 WriteLog("Profiler/Cycle Time", units::millisecond_t{profiler.Get()});
174 WriteLog("Profiler/Assign Outputs Time", assignOutputsTime);
175 WriteLog("Profiler/Assess Inputs Time", assessInputsTime);
176 WriteLog("Profiler/Analyze Dashboard Time", analyzeDashboardTime);
177 }
178 }
179
180 frc::Timer profiler;
181};
182} // namespace valor
Abstract class that all Valor subsystem's should implement.
Definition BaseSubsystem.h:52
virtual void reset()
Reset all subsystem state.
Definition BaseSubsystem.h:148
BaseSubsystem(std::string name)
Construct a new Valor Subsystem object.
Definition BaseSubsystem.h:63
virtual void analyzeDashboard()
Synchronize dashboard data (both read and write)
Definition BaseSubsystem.h:84
virtual void assignOutputs()
Read subsystem state and send motor commands.
Definition BaseSubsystem.h:135
virtual void assessInputs()
Read controller logic and set subsystem state.
Definition BaseSubsystem.h:107
Wrapper class for XBox gamepads.
Definition Gamepad.h:20
Base helper for publishing and subscribing values to NetworkTables.
Definition Loggable.h:204
T WriteLog(std::string_view field, const T &data)
Publish a value to NetworkTables under the given field.
Definition Loggable.h:313