CTRE_Phoenix  5.19.4
TalonFX.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/motorcontrol/MotorCommutation.h"
10 #include "ctre/phoenix/motorcontrol/StatorCurrentLimitConfiguration.h"
11 #include "ctre/phoenix/CustomParamConfiguration.h"
12 #include "ctre/phoenix/sensors/AbsoluteSensorRange.h"
13 #include "ctre/phoenix/sensors/SensorInitializationStrategy.h"
14 
15 namespace ctre {
16  namespace phoenix {
17  namespace motorcontrol {
18  namespace can {
19 
24 
29 
38 
43 
49  ctre::phoenix::sensors::AbsoluteSensorRange absoluteSensorRange = ctre::phoenix::sensors::AbsoluteSensorRange::Unsigned_0_to_360;
56  double integratedSensorOffsetDegrees = 0;
66  ctre::phoenix::sensors::SensorInitializationStrategy initializationStrategy = ctre::phoenix::sensors::SensorInitializationStrategy::BootToZero;
67 
68 
70  {
71  }
72 
76  std::string toString() {
77  return toString("");
78  }
79 
85  std::string toString(std::string prependString) {
86 
87  std::string retstr;
88  retstr += prependString + ".supplyCurrLimit = " + supplyCurrLimit.ToString() + ";\n";
89  retstr += prependString + ".statorCurrLimit = " + statorCurrLimit.ToString() + ";\n";
90  retstr += prependString + ".motorCommutation = " + std::to_string((int)motorCommutation) + ";\n";
91  retstr += prependString + ".absoluteSensorRange = " + std::to_string(absoluteSensorRange) + ";\n";
92  retstr += prependString + ".integratedSensorOffsetDegrees = " + std::to_string(integratedSensorOffsetDegrees) + ";\n";
93  retstr += prependString + ".initializationStrategy = " + std::to_string(initializationStrategy) + ";\n";
94  retstr += BaseTalonConfiguration::toString(prependString);
95 
96  return retstr;
97  }
98  };// struct TalonFXConfiguration
99 
104  private:
105  static struct TalonFXConfiguration _default;
106  public:
113  static bool SupplyCurrentLimitDifferent(const TalonFXConfiguration& settings) { return (!settings.supplyCurrLimit.Equals(_default.supplyCurrLimit)) || !settings.enableOptimizations; }
114  static bool StatorCurrentDurationDifferent(const TalonFXConfiguration& settings) { return (!settings.statorCurrLimit.Equals(_default.statorCurrLimit)) || !settings.enableOptimizations; }
115  static bool MotorCommutationDifferent(const TalonFXConfiguration& settings) { return (settings.motorCommutation != _default.motorCommutation) || !settings.enableOptimizations; }
116  static bool AbsoluteSensorRangeDifferent(const TalonFXConfiguration& settings) { return (settings.absoluteSensorRange != _default.absoluteSensorRange) || !settings.enableOptimizations; }
117  static bool IntegratedSensorOffsetDegreesDifferent(const TalonFXConfiguration& settings) { return (settings.integratedSensorOffsetDegrees != _default.integratedSensorOffsetDegrees) || !settings.enableOptimizations; }
118  static bool InitializationStrategyDifferent(const TalonFXConfiguration& settings) { return (settings.initializationStrategy != _default.initializationStrategy) || !settings.enableOptimizations; }
120  };
121 
125  class TalonFX : public virtual BaseTalon
126  {
127  private:
128 
129  public:
134  TalonFX(int deviceNumber);
135  ~TalonFX();
136  TalonFX() = delete;
137  TalonFX(TalonFX const&) = delete;
138  TalonFX& operator=(TalonFX const&) = delete;
139  // ------ Set output routines. ----------//
158  void Set(TalonFXControlMode mode, double value);
197  void Set(TalonFXControlMode mode, double demand0, DemandType demand1Type, double demand1);
198  //------ Invert behavior ----------//
213  void SetInverted(TalonFXInvertType invertType);
214  //------ sensor selection ----------//
228  ctre::phoenix::ErrorCode ConfigSelectedFeedbackSensor(TalonFXFeedbackDevice feedbackDevice, int pidIdx = 0, int timeoutMs = 0);
229  //------ Current Limit ----------//
239  ctre::phoenix::ErrorCode ConfigSupplyCurrentLimit(const ctre::phoenix::motorcontrol::SupplyCurrentLimitConfiguration& currLimitConfigs, int timeoutMs = 50);
249  ctre::phoenix::ErrorCode ConfigStatorCurrentLimit(const ctre::phoenix::motorcontrol::StatorCurrentLimitConfiguration& currLimitConfigs, int timeoutMs = 50);
258  ctre::phoenix::ErrorCode ConfigGetSupplyCurrentLimit(ctre::phoenix::motorcontrol::SupplyCurrentLimitConfiguration& currLimitConfigsToFill, int timeoutMs = 50);
267  ctre::phoenix::ErrorCode ConfigGetStatorCurrentLimit(ctre::phoenix::motorcontrol::StatorCurrentLimitConfiguration& currLimitConfigsToFill, int timeoutMs = 50);
268 
269  //------ RAW Sensor API ----------//
274  //------ All Configs ----------//
275 
286  ctre::phoenix::ErrorCode ConfigurePID(const TalonFXPIDSetConfiguration& pid, int pidIdx = 0, int timeoutMs = 50);
297  void GetPIDConfigs(TalonFXPIDSetConfiguration& pid, int pidIdx = 0, int timeoutMs = 50);
298 
310  ctre::phoenix::ErrorCode ConfigAllSettings(const TalonFXConfiguration& allConfigs, int timeoutMs = 50);
320  void GetAllConfigs(TalonFXConfiguration& allConfigs, int timeoutMs = 50);
331  ctre::phoenix::ErrorCode ConfigMotorCommutation(ctre::phoenix::motorcontrol::MotorCommutation motorCommutation, int timeoutMs = 0);
338  ctre::phoenix::ErrorCode ConfigGetMotorCommutation(ctre::phoenix::motorcontrol::MotorCommutation & motorCommutation, int timeoutMs = 0);
339 
352  ErrorCode ConfigIntegratedSensorAbsoluteRange(ctre::phoenix::sensors::AbsoluteSensorRange absoluteSensorRange, int timeoutMs = 0);
366  ErrorCode ConfigIntegratedSensorOffset(double offsetDegrees, int timeoutMs = 0);
382  ErrorCode ConfigIntegratedSensorInitializationStrategy(ctre::phoenix::sensors::SensorInitializationStrategy initializationStrategy, int timeoutMs = 0);
383 
384  /* ----- virtual re-directs ------- */
385  virtual void Set(ControlMode mode, double value);
386  virtual void Set(ControlMode mode, double demand0, DemandType demand1Type, double demand1);
387  virtual void SetInverted(InvertType invertType);
388  virtual void SetInverted(bool bInvert);
389  virtual ctre::phoenix::ErrorCode ConfigSelectedFeedbackSensor(FeedbackDevice feedbackDevice, int pidIdx = 0, int timeoutMs = 0);
390  virtual ctre::phoenix::ErrorCode ConfigSelectedFeedbackSensor(RemoteFeedbackDevice feedbackDevice, int pidIdx = 0, int timeoutMs = 0);
391 
392  };// class TalonFX
393 
394  } // namespace can
395  } // namespace motorcontrol
396  } // namespace phoenix
397 } // namespace ctre
398 
399 #if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
400 #pragma warning (pop)
401 #endif
TalonFXControlMode
Definition: ControlMode.h:55
TalonFXFeedbackDevice
Definition: FeedbackDevice.h:134
bool enableOptimizations
Definition: CustomParamConfiguration.h:22
StatorCurrentLimitConfiguration statorCurrLimit
Definition: TalonFX.h:37
static bool SupplyCurrentLimitDifferent(const TalonFXConfiguration &settings)
Definition: TalonFX.h:113
MotorCommutation
Definition: MotorCommutation.h:10
Definition: ErrorCode.h:4
ErrorCode
Definition: ErrorCode.h:7
Definition: StatorCurrentLimitConfiguration.h:12
std::string ToString() const
Definition: SupplyCurrentLimitConfiguration.h:53
std::string toString()
Definition: BaseTalon.h:195
SupplyCurrentLimitConfiguration supplyCurrLimit
Definition: TalonFX.h:33
std::string ToString() const
Definition: StatorCurrentLimitConfiguration.h:53
FeedbackDevice
Definition: FeedbackDevice.h:13
std::string toString()
Definition: TalonFX.h:76
double integratedSensorOffsetDegrees
Definition: TalonFX.h:56
ctre::phoenix::sensors::AbsoluteSensorRange absoluteSensorRange
Definition: TalonFX.h:49
TalonFXInvertType
Definition: InvertType.h:24
DemandType
Definition: DemandType.h:9
AbsoluteSensorRange
Definition: AbsoluteSensorRange.h:12
Definition: SupplyCurrentLimitConfiguration.h:12
std::string toString()
Definition: BaseTalon.h:52
std::string toString(std::string prependString)
Definition: TalonFX.h:85
ctre::phoenix::motorcontrol::MotorCommutation motorCommutation
Definition: TalonFX.h:42
Definition: TalonFXSensorCollection.h:30
ControlMode
Definition: ControlMode.h:10
ctre::phoenix::sensors::SensorInitializationStrategy initializationStrategy
Definition: TalonFX.h:66
RemoteFeedbackDevice
Definition: FeedbackDevice.h:169
SensorInitializationStrategy
Definition: SensorInitializationStrategy.h:12
InvertType
Definition: InvertType.h:13