CTRE_Phoenix  5.19.4
TalonSRX.h
1 #pragma once
2 #if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
3 #pragma warning (push)
4 #pragma warning (disable : 4250)
5 #endif
6 
7 #include "ctre/phoenix/motorcontrol/can/BaseTalon.h"
8 #include "ctre/phoenix/motorcontrol/IMotorControllerEnhanced.h"
9 #include "ctre/phoenix/CustomParamConfiguration.h"
10 
11 /* forward proto's */
12 namespace ctre {
13  namespace phoenix {
14  namespace motorcontrol {
15  class SensorCollection;
16  class TalonSRXSimCollection;
17  }
18  }
19 }
20 
21 namespace ctre {
22  namespace phoenix {
23  namespace motorcontrol {
24  namespace can {
25 
34 
64  peakCurrentLimit(1),
65  peakCurrentDuration(1),
66  continuousCurrentLimit(1)
67  {
68  }
69 
73  std::string toString() {
74  return toString("");
75  }
76 
82  std::string toString(std::string prependString) {
83 
84  std::string retstr;
85  retstr += prependString + ".peakCurrentLimit = " + std::to_string(peakCurrentLimit) + ";\n";
86  retstr += prependString + ".peakCurrentDuration = " + std::to_string(peakCurrentDuration) + ";\n";
87  retstr += prependString + ".continuousCurrentLimit = " + std::to_string(continuousCurrentLimit) + ";\n";
88  retstr += BaseTalonConfiguration::toString(prependString);
89 
90  return retstr;
91  }
92  };// struct TalonSRXConfiguration
93 
98  private:
99  static struct TalonSRXConfiguration _default;
100  public:
107  static bool PeakCurrentLimitDifferent(const TalonSRXConfiguration& settings) { return (!(settings.peakCurrentLimit == _default.peakCurrentLimit)) || !settings.enableOptimizations; }
108  static bool PeakCurrentDurationDifferent(const TalonSRXConfiguration& settings) { return (!(settings.peakCurrentDuration == _default.peakCurrentDuration)) || !settings.enableOptimizations; }
109  static bool ContinuousCurrentLimitDifferent(const TalonSRXConfiguration& settings) { return (!(settings.continuousCurrentLimit == _default.continuousCurrentLimit)) || !settings.enableOptimizations; }
110 
112  };
113 
117  class TalonSRX : public virtual BaseTalon
118  {
119  private:
120 
121  public:
126  TalonSRX(int deviceNumber);
127  ~TalonSRX();
128  TalonSRX() = delete;
129  TalonSRX(TalonSRX const&) = delete;
130  TalonSRX& operator=(TalonSRX const&) = delete;
131  // ------ Set output routines. ----------//
150  void Set(TalonSRXControlMode mode, double value);
189  void Set(TalonSRXControlMode mode, double demand0, DemandType demand1Type, double demand1);
190  //------ sensor selection ----------//
204  ctre::phoenix::ErrorCode ConfigSelectedFeedbackSensor(TalonSRXFeedbackDevice feedbackDevice, int pidIdx = 0, int timeoutMs = 0);
218  ctre::phoenix::ErrorCode ConfigSelectedFeedbackSensor(FeedbackDevice feedbackDevice, int pidIdx, int timeoutMs = 0);
219 
234  ctre::phoenix::ErrorCode ConfigSelectedFeedbackSensor(RemoteFeedbackDevice feedbackDevice, int pidIdx, int timeoutMs);
235 
236  //------ Current Limit ----------//
246  virtual ctre::phoenix::ErrorCode ConfigSupplyCurrentLimit(const SupplyCurrentLimitConfiguration& currLimitConfigs, int timeoutMs = 50);
269  ctre::phoenix::ErrorCode ConfigPeakCurrentLimit(int amps, int timeoutMs = 0);
292  ctre::phoenix::ErrorCode ConfigPeakCurrentDuration(int milliseconds,
293  int timeoutMs = 0);
317  ctre::phoenix::ErrorCode ConfigContinuousCurrentLimit(int amps, int timeoutMs = 0);
318 
331  void EnableCurrentLimit(bool enable);
332  //------ RAW Sensor API ----------//
336  ctre::phoenix::motorcontrol::SensorCollection& GetSensorCollection();
337 
338  //------ Simulation API ----------//
343 
344  //------ All Configs ----------//
345 
356  ctre::phoenix::ErrorCode ConfigurePID(const TalonSRXPIDSetConfiguration& pid, int pidIdx = 0, int timeoutMs = 50);
367  void GetPIDConfigs(TalonSRXPIDSetConfiguration& pid, int pidIdx = 0, int timeoutMs = 50);
379  ctre::phoenix::ErrorCode ConfigAllSettings(const TalonSRXConfiguration& allConfigs, int timeoutMs = 50);
389  void GetAllConfigs(TalonSRXConfiguration& allConfigs, int timeoutMs = 50);
390 
391  /* ----- virtual re-directs ------- */
392  virtual void Set(ControlMode mode, double value);
393  virtual void Set(ControlMode mode, double demand0, DemandType demand1Type, double demand1);
394  };// class TalonSRX
395 
396  } // namespace can
397  } // namespace motorcontrol
398  } // namespace phoenix
399 } // namespace ctre
400 
401 #if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
402 #pragma warning (pop)
403 #endif
bool enableOptimizations
Definition: CustomParamConfiguration.h:22
static bool PeakCurrentLimitDifferent(const TalonSRXConfiguration &settings)
Definition: TalonSRX.h:107
Definition: ErrorCode.h:4
ErrorCode
Definition: ErrorCode.h:7
FeedbackDevice
Definition: FeedbackDevice.h:13
Definition: SensorCollection.h:30
DemandType
Definition: DemandType.h:9
Definition: SupplyCurrentLimitConfiguration.h:12
TalonSRXControlMode
Definition: ControlMode.h:101
TalonSRXFeedbackDevice
Definition: FeedbackDevice.h:75
std::string toString(std::string prependString)
Definition: TalonSRX.h:82
Definition: TalonSRXSimCollection.h:25
ControlMode
Definition: ControlMode.h:10
RemoteFeedbackDevice
Definition: FeedbackDevice.h:169
std::string toString()
Definition: TalonSRX.h:73