CTRE Phoenix C++ 5.33.1
StatorCurrentLimitConfiguration.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3#include <sstream>
4#include <vector>
5#include <algorithm>
6namespace ctre {
7 namespace phoenix {
8 namespace motorcontrol {
9 /**
10 * Describes the desired stator current limiting behavior.
11 *
12 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
13 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
14 * Phoenix 6 API. A migration guide is available at
15 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
16 *
17 * If the Phoenix 5 API must be used for this device, the device must have 22.X
18 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
19 * the firmware year dropdown.
20 */
22 {
23 /**
24 * True/False to enable/disable limit feature.
25 */
26 bool enable = false;
27 /**
28 * The "holding" current (amperes) to limit to when feature is activated.
29 */
30 double currentLimit = 0;
31
32 /**
33 * Current must exceed this threshold (amperes) before limiting occurs.
34 * If this value is less than currentLimit, then currentLimit is used as the threshold.
35 */
37 /**
38 * How long current must exceed threshold (seconds) before limiting occurs.
39 */
41
42 /**
43 * Default c'tor. Because currentLimit is zero, limiting id disabled.
44 */
45 StatorCurrentLimitConfiguration() { /* already done - initializers above */ }
46
47 StatorCurrentLimitConfiguration(const double* doubleArray, int doubleArraySz)
48 {
49 Deserialize(doubleArray, doubleArraySz);
50 }
51
53 {
54 this->enable = enable;
55 this->currentLimit = currentLimit;
56 this->triggerThresholdCurrent = triggerThresholdCurrent;
57 this->triggerThresholdTime = triggerThresholdTime;
58 }
59 /**
60 * @return string representation of current faults tripped
61 */
62 std::string ToString() const
63 {
64 std::stringstream work;
65
66 if (false == enable) {
67 work << "Limiting is disabled.";
68 }
69 else {
70 /* If current limit is greater than thresholdCurrent,
71 * the device will use current-limit as the threshold.
72 */
73 double effectiveThresholdCurr = std::max<double>(currentLimit, triggerThresholdCurrent);
74
75 work << "Current Limiting will activate if STATOR current exceeds " << effectiveThresholdCurr << " amps for " << triggerThresholdTime << " seconds." << " Then current will hold at " << currentLimit << " amps";
76 }
77 return work.str();
78 }
79 std::vector<double> ToArray() const
80 {
81 std::vector<double> retval;
82 retval.push_back(enable ? 1 : 0);
83 retval.push_back(currentLimit);
84 retval.push_back(triggerThresholdCurrent);
85 retval.push_back(triggerThresholdTime);
86 return retval;
87 }
88 void Deserialize(const double* doubles, int doubleCnt)
89 {
90 if (doubleCnt <= 0) { return; }
91
92 if (doubleCnt > 0) {
93 enable = *doubles++;
94 --doubleCnt;
95 }
96 if (doubleCnt > 0) {
97 currentLimit = *doubles++;
98 --doubleCnt;
99 }
100 if (doubleCnt > 0) {
101 triggerThresholdCurrent = *doubles++;
102 --doubleCnt;
103 }
104 if (doubleCnt > 0) {
105 triggerThresholdTime = *doubles++;
106 --doubleCnt;
107 }
108 }
110 {
111 bool retval = true;
112 retval &= (enable == rhs.enable);
113 retval &= (currentLimit == rhs.currentLimit);
116 return retval;
117 }
118 };
119
120 } // namespace motorcontrol
121 } // namespace phoenix
122} // namespace ctre
namespace ctre
Definition: paramEnum.h:5
Describes the desired stator current limiting behavior.
Definition: StatorCurrentLimitConfiguration.h:22
bool Equals(const StatorCurrentLimitConfiguration &rhs) const
Definition: StatorCurrentLimitConfiguration.h:109
std::vector< double > ToArray() const
Definition: StatorCurrentLimitConfiguration.h:79
double triggerThresholdCurrent
Current must exceed this threshold (amperes) before limiting occurs.
Definition: StatorCurrentLimitConfiguration.h:36
bool enable
True/False to enable/disable limit feature.
Definition: StatorCurrentLimitConfiguration.h:26
double currentLimit
The "holding" current (amperes) to limit to when feature is activated.
Definition: StatorCurrentLimitConfiguration.h:30
StatorCurrentLimitConfiguration(bool enable, double currentLimit, double triggerThresholdCurrent, double triggerThresholdTime)
Definition: StatorCurrentLimitConfiguration.h:52
std::string ToString() const
Definition: StatorCurrentLimitConfiguration.h:62
void Deserialize(const double *doubles, int doubleCnt)
Definition: StatorCurrentLimitConfiguration.h:88
double triggerThresholdTime
How long current must exceed threshold (seconds) before limiting occurs.
Definition: StatorCurrentLimitConfiguration.h:40
StatorCurrentLimitConfiguration(const double *doubleArray, int doubleArraySz)
Definition: StatorCurrentLimitConfiguration.h:47
StatorCurrentLimitConfiguration()
Default c'tor.
Definition: StatorCurrentLimitConfiguration.h:45