Valkyrie 2026
Loading...
Searching...
No Matches
NeoController.h
1#pragma once
2
3#include <memory>
4#include <string>
5
6#include <rev/SparkMax.h>
7#include <rev/config/SparkMaxConfig.h>
8#include <rev/sim/SparkMaxSim.h>
9#include <units/base.h>
10
11#include "valkyrie/controllers/BaseController.h"
12
13namespace valor {
14
15enum NeoControllerType { NEO, NEO_550 };
16
17class NeoController : public BaseController, rev::spark::SparkMax {
18 public:
19 NeoController(valor::NeoControllerType, int canID, valor::NeutralMode mode, bool inverted);
20
21 static constexpr frc::DCMotor getMotorSpec(NeoControllerType controllerType) {
22 switch (controllerType) {
23 case NEO_550:
24 return frc::DCMotor::NEO550();
25 default:
26 return frc::DCMotor::NEO();
27 }
28 }
29
30 void ApplyConfig() override;
31
32 units::turn_t GetPosition() const override;
33
34 units::ampere_t GetCurrent() const override;
35
36 units::turns_per_second_t GetSpeed() const override;
37
38 void SetEncoderPosition(units::turn_t position) override;
39
40 units::turn_t GetAbsoluteEncoderPosition() const override;
41
42 void SetContinuousWrap(bool wrap, bool saveImmediately = false);
43
44 void PositionSetter(units::turn_t positon, Output feedforward, int slot = 0) override;
45 void SpeedSetter(units::turns_per_second_t speed, Output feedforward, int slot = 0) override;
46
47 void SetupFollower(int canID, bool followerInverted = false) override;
48
49 void SetPIDF(valor::PIDF<> pidf, int slot = 0, bool saveImmediately = false) override;
50
51 void SetForwardLimit(units::turn_t forward, bool saveImmediately = false) override;
52
53 void SetReverseLimit(units::turn_t reverse, bool saveImmediately = false) override;
54
55 void SetGearRatios(double rotorToSensor, double sensorToMech, bool saveImmediately = false) override;
56
57 void SetCurrentLimits(units::ampere_t statorCurrentLimit, bool saveImmediately = false);
58
59 void SetNeutralMode(valor::NeutralMode mode, bool saveImmediately = false) override;
60
61 void SetOpenLoopRamp(units::second_t time, bool saveImmediately = false) override;
62
63 void PowerSetter(Output out) override;
64
65 void LoggablePeriodic() override;
66
67 units::volt_t CalculateAppliedVoltage() override;
68
69 using BaseController::SetSimState;
70 void SetSimState(units::turn_t pos, units::turns_per_second_t vel, units::turns_per_second_squared_t accel) override;
71 void SetSimState(frc::sim::DCMotorSim&) override;
72 void SetSimState(frc::sim::FlywheelSim&) override;
73
74 private:
75 static constexpr units::ampere_t STATOR_CURRENT_LIMIT = 40_A;
76
77 valor::PIDF<> pidf;
78
79 rev::spark::SparkMaxConfig config;
80 std::unique_ptr<rev::spark::SparkMax> followerMotor;
81 rev::spark::SparkMaxSim sim;
82};
83} // namespace valor
BaseController(frc::DCMotor _motorSpec)
Construct a new Valor Controller object.
Definition BaseController.h:65
void SpeedSetter(units::turns_per_second_t speed, Output feedforward, int slot=0) override
Send the motor to a specific speed.
units::turns_per_second_t GetSpeed() const override
Get the motors speed.
units::ampere_t GetCurrent() const override
Get the motors output current.
units::turn_t GetPosition() const override
Get the motors position.
void SetGearRatios(double rotorToSensor, double sensorToMech, bool saveImmediately=false) override
Set the gear ratios for the motor.
void PositionSetter(units::turn_t positon, Output feedforward, int slot=0) override
Send the motor to a specific position.
void SetForwardLimit(units::turn_t forward, bool saveImmediately=false) override
Set the forward soft limit for the motor.
void SetNeutralMode(valor::NeutralMode mode, bool saveImmediately=false) override
Set the neutral mode of the motor.
void SetReverseLimit(units::turn_t reverse, bool saveImmediately=false) override
Set the reverse soft limit for the motor.
void SetupFollower(int canID, bool followerInverted=false) override
If a motor is paired with another motor, setup that other motor as a follower.
void LoggablePeriodic() override
Periodic callback for logging updates.
void SetPIDF(valor::PIDF<> pidf, int slot=0, bool saveImmediately=false) override
Change the PIDF values for the motor.
Container to hold PID and feed forward values for the motor controller.
Definition PIDF.h:26