CTRE Phoenix C++ 5.33.1
SupplyCurrentLimitConfiguration.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 */
13 {
14 /**
15 * True/False to enable/disable limit feature.
16 */
17 bool enable = false;
18 /**
19 * The "holding" current (amperes) to limit to when feature is activated.
20 */
21 double currentLimit = 0;
22
23 /**
24 * Current must exceed this threshold (amperes) before limiting occurs.
25 * If this value is less than currentLimit, then currentLimit is used as the threshold.
26 */
28 /**
29 * How long current must exceed threshold (seconds) before limiting occurs.
30 */
32
33 /**
34 * Default c'tor. Because currentLimit is zero, limiting is disabled.
35 */
36 SupplyCurrentLimitConfiguration() { /* already done - initializers above */ }
37
39 {
40 this->enable = enable;
41 this->currentLimit = currentLimit;
42 this->triggerThresholdCurrent = triggerThresholdCurrent;
43 this->triggerThresholdTime = triggerThresholdTime;
44 }
45
46 SupplyCurrentLimitConfiguration(const double* doubleArray, int doubleArraySz)
47 {
48 Deserialize(doubleArray, doubleArraySz);
49 }
50 /**
51 * @return string representation of current faults tripped
52 */
53 std::string ToString() const
54 {
55 std::stringstream work;
56
57 if (false == enable) {
58 work << "Limiting is disabled.";
59 }
60 else {
61 /* If current limit is greater than triggerThresholdCurrent,
62 * the device will use current-limit as the threshold.
63 */
64 double effectiveThresholdCurr = std::max<double>(currentLimit, triggerThresholdCurrent);
65
66 work << "Current Limiting will activate if SUPPLY current exceeds " << effectiveThresholdCurr << " amps for " << triggerThresholdTime << " seconds." << " Then current will hold at " << currentLimit << " amps";
67 }
68 return work.str();
69 }
70 std::vector<double> ToArray() const
71 {
72 std::vector<double> retval;
73 retval.push_back(enable ? 1 : 0);
74 retval.push_back(currentLimit);
75 retval.push_back(triggerThresholdCurrent);
76 retval.push_back(triggerThresholdTime);
77 return retval;
78 }
79 void Deserialize(const double * doubles, int doubleCnt)
80 {
81 if (doubleCnt <= 0) { return; }
82
83 if (doubleCnt > 0) {
84 enable = *doubles++;
85 --doubleCnt;
86 }
87 if (doubleCnt > 0) {
88 currentLimit = *doubles++;
89 --doubleCnt;
90 }
91 if (doubleCnt > 0) {
92 triggerThresholdCurrent = *doubles++;
93 --doubleCnt;
94 }
95 if (doubleCnt > 0) {
96 triggerThresholdTime = *doubles++;
97 --doubleCnt;
98 }
99 }
101 {
102 bool retval = true;
103 retval &= (enable == rhs.enable);
104 retval &= (currentLimit == rhs.currentLimit);
107 return retval;
108 }
109 };
110
111 } // namespace motorcontrol
112 } // namespace phoenix
113} // namespace ctre
namespace ctre
Definition: paramEnum.h:5
Describes the desired stator current limiting behavior.
Definition: SupplyCurrentLimitConfiguration.h:13
double triggerThresholdCurrent
Current must exceed this threshold (amperes) before limiting occurs.
Definition: SupplyCurrentLimitConfiguration.h:27
void Deserialize(const double *doubles, int doubleCnt)
Definition: SupplyCurrentLimitConfiguration.h:79
SupplyCurrentLimitConfiguration(bool enable, double currentLimit, double triggerThresholdCurrent, double triggerThresholdTime)
Definition: SupplyCurrentLimitConfiguration.h:38
std::string ToString() const
Definition: SupplyCurrentLimitConfiguration.h:53
double triggerThresholdTime
How long current must exceed threshold (seconds) before limiting occurs.
Definition: SupplyCurrentLimitConfiguration.h:31
bool Equals(const SupplyCurrentLimitConfiguration &rhs) const
Definition: SupplyCurrentLimitConfiguration.h:100
SupplyCurrentLimitConfiguration()
Default c'tor.
Definition: SupplyCurrentLimitConfiguration.h:36
std::vector< double > ToArray() const
Definition: SupplyCurrentLimitConfiguration.h:70
bool enable
True/False to enable/disable limit feature.
Definition: SupplyCurrentLimitConfiguration.h:17
double currentLimit
The "holding" current (amperes) to limit to when feature is activated.
Definition: SupplyCurrentLimitConfiguration.h:21
SupplyCurrentLimitConfiguration(const double *doubleArray, int doubleArraySz)
Definition: SupplyCurrentLimitConfiguration.h:46