001package com.ctre.phoenix.motorcontrol; 002 003 004/** 005 * Supply-side current limiting. This is typically used to prevent breakers from tripping. 006 */ 007public class SupplyCurrentLimitConfiguration{ 008 /** 009 * True/False to enable/disable limit feature. 010 */ 011 public boolean enable = false; 012 /** 013 * The "holding" current (amperes) to limit to when feature is activated. 014 */ 015 public double currentLimit = 0; 016 017 /** 018 * Current must exceed this threshold (amperes) before limiting occurs. 019 * If this value is less than currentLimit, then currentLimit is used as the threshold. 020 */ 021 public double triggerThresholdCurrent = 0; 022 /** 023 * How long current must exceed threshold (seconds) before limiting occurs. 024 */ 025 public double triggerThresholdTime = 0; 026 027 public SupplyCurrentLimitConfiguration(){} 028 029 public SupplyCurrentLimitConfiguration(boolean enable, double currentLimit, double triggerThresholdCurrent, double triggerThresholdTime){ 030 this.enable = enable; 031 this.currentLimit = currentLimit; 032 this.triggerThresholdCurrent = triggerThresholdCurrent; 033 this.triggerThresholdTime = triggerThresholdTime; 034 } 035 036 public SupplyCurrentLimitConfiguration(double[] doubleArray){ 037 deserialize(doubleArray); 038 } 039 040 /** 041 * @return string representation of current faults tripped 042 */ 043 public String toString(){ 044 String retstr = ""; 045 046 if(enable == false){ 047 retstr = "Limiting is disabled."; 048 } 049 else{ 050 /* If current limit is greater than triggerThresholdCurrent, 051 * the device will use current-limit as the threshold. 052 */ 053 double effectiveThresholdCurr = Math.max(currentLimit, triggerThresholdCurrent); 054 retstr = "Current Limiting will activate if SUPPLY current exceeds " + effectiveThresholdCurr + " amps for " + triggerThresholdTime + " seconds." + " Then current will hold at " + currentLimit + " amps"; 055 } 056 return retstr; 057 } 058 059 public double[] toArray(){ 060 double[] retval = new double[4]; 061 retval[0] = ((double)(enable ? 1 : 0)); 062 retval[1] = (currentLimit); 063 retval[2] = (triggerThresholdCurrent); 064 retval[3] = (triggerThresholdTime); 065 return retval; 066 } 067 068 public void deserialize(double[] doubles){ 069 int doubleCnt = doubles.length; 070 071 if (doubleCnt <= 0) { return; } 072 int i = 0; 073 074 if (i < doubleCnt) { 075 enable = (doubles[i++] > 0); 076 } 077 if (i < doubleCnt) { 078 currentLimit = doubles[i++]; 079 } 080 if (i < doubleCnt) { 081 triggerThresholdCurrent = doubles[i++]; 082 } 083 if (i < doubleCnt) { 084 triggerThresholdTime = doubles[i++]; 085 } 086 } 087 public boolean equals(SupplyCurrentLimitConfiguration rhs){ 088 boolean retval = true; 089 retval &= (enable == rhs.enable); 090 retval &= (currentLimit == rhs.currentLimit); 091 retval &= (triggerThresholdCurrent == rhs.triggerThresholdCurrent); 092 retval &= (triggerThresholdTime == rhs.triggerThresholdTime); 093 return retval; 094 } 095}