CTRE_Phoenix 5.20.2
SupplyCurrentLimitConfiguration.h
1#pragma once
2#include <sstream>
3#include <vector>
4#include <algorithm>
5#include "ctre/phoenix/string_util/string_util.h"
6namespace ctre {
7 namespace phoenix {
8 namespace motorcontrol {
13 {
17 bool enable = false;
21 double currentLimit = 0;
22
32
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 }
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 }
100 bool Equals(const SupplyCurrentLimitConfiguration& rhs) const
101 {
102 bool retval = true;
103 retval &= (enable == rhs.enable);
104 retval &= (currentLimit == rhs.currentLimit);
105 retval &= (triggerThresholdCurrent == rhs.triggerThresholdCurrent);
106 retval &= (triggerThresholdTime == rhs.triggerThresholdTime);
107 return retval;
108 }
109 };
110
111 } // namespace motorcontrol
112 } // namespace phoenix
113} // namespace ctre
Definition: ErrorCode.h:5
Definition: SupplyCurrentLimitConfiguration.h:13
double triggerThresholdCurrent
Definition: SupplyCurrentLimitConfiguration.h:27
std::string ToString() const
Definition: SupplyCurrentLimitConfiguration.h:53
double triggerThresholdTime
Definition: SupplyCurrentLimitConfiguration.h:31
SupplyCurrentLimitConfiguration()
Definition: SupplyCurrentLimitConfiguration.h:36
bool enable
Definition: SupplyCurrentLimitConfiguration.h:17
double currentLimit
Definition: SupplyCurrentLimitConfiguration.h:21