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