001/* 002 * Copyright (C) Cross The Road Electronics. All rights reserved. 003 * License information can be found in CTRE_LICENSE.txt 004 * For support and suggestions contact support@ctr-electronics.com or file 005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases 006 */ 007package com.ctre.phoenixpro.configs; 008 009import com.ctre.phoenixpro.StatusCode; 010import com.ctre.phoenixpro.configs.jni.ConfigJNI; 011import com.ctre.phoenixpro.spns.*; 012 013/** 014 * Configs that directly affect current limiting features. 015 * <p> 016 * Includes Motor Invert and various limit features. 017 */ 018public class CurrentLimitsConfigs implements ParentConfiguration 019{ 020 /** 021 * The amount of current allowed in the motor (motoring and regen 022 * current). This is only applicable for non-torque current control 023 * modes. Note this requires the corresponding enable to be true. 024 * 025 * <ul> 026 * <li> <b>Minimum Value:</b> 0.0 027 * <li> <b>Maximum Value:</b> 800.0 028 * <li> <b>Default Value:</b> 0 029 * <li> <b>Units:</b> A 030 * </ul> 031 */ 032 public double StatorCurrentLimit = 0; 033 /** 034 * Enable motor stator current limiting. 035 * 036 * <ul> 037 * <li> <b>Default Value:</b> False 038 * </ul> 039 */ 040 public boolean StatorCurrentLimitEnable = false; 041 /** 042 * The amount of supply current allowed. This is only applicable for 043 * non-torque current control modes. Note this requires the 044 * corresponding enable to be true. Use SupplyCurrentThreshold and 045 * SupplyTimeThreshold to allow brief periods of high-current before 046 * limiting occurs. 047 * 048 * <ul> 049 * <li> <b>Minimum Value:</b> 0.0 050 * <li> <b>Maximum Value:</b> 800.0 051 * <li> <b>Default Value:</b> 0 052 * <li> <b>Units:</b> A 053 * </ul> 054 */ 055 public double SupplyCurrentLimit = 0; 056 /** 057 * Enable motor supply current limiting. 058 * 059 * <ul> 060 * <li> <b>Default Value:</b> False 061 * </ul> 062 */ 063 public boolean SupplyCurrentLimitEnable = false; 064 /** 065 * Delay supply current limiting until current exceeds this threshold 066 * for longer than SupplyTimeThreshold. This allows current draws 067 * above SupplyCurrentLimit for a fixed period of time. This has no 068 * effect if SupplyCurrentLimit is greater than this value. 069 * 070 * <ul> 071 * <li> <b>Minimum Value:</b> 0.0 072 * <li> <b>Maximum Value:</b> 511 073 * <li> <b>Default Value:</b> 0 074 * <li> <b>Units:</b> A 075 * </ul> 076 */ 077 public double SupplyCurrentThreshold = 0; 078 /** 079 * Allows unlimited current for a period of time before current 080 * limiting occurs. Current threshold is the maximum of 081 * SupplyCurrentThreshold and SupplyCurrentLimit. 082 * 083 * <ul> 084 * <li> <b>Minimum Value:</b> 0.0 085 * <li> <b>Maximum Value:</b> 1.275 086 * <li> <b>Default Value:</b> 0 087 * <li> <b>Units:</b> sec 088 * </ul> 089 */ 090 public double SupplyTimeThreshold = 0; 091 092 @Override 093 public String toString() 094 { 095 String ss = "Config Group: CurrentLimits\n"; 096 ss += "Name: \"StatorCurrentLimit\" Value: \"" + StatorCurrentLimit + "A\"" + "\n"; 097 ss += "Name: \"StatorCurrentLimitEnable\" Value: \"" + StatorCurrentLimitEnable + "\"" + "\n"; 098 ss += "Name: \"SupplyCurrentLimit\" Value: \"" + SupplyCurrentLimit + "A\"" + "\n"; 099 ss += "Name: \"SupplyCurrentLimitEnable\" Value: \"" + SupplyCurrentLimitEnable + "\"" + "\n"; 100 ss += "Name: \"SupplyCurrentThreshold\" Value: \"" + SupplyCurrentThreshold + "A\"" + "\n"; 101 ss += "Name: \"SupplyTimeThreshold\" Value: \"" + SupplyTimeThreshold + "sec\"" + "\n"; 102 return ss; 103 } 104 105 /** 106 * 107 */ 108 public StatusCode deserialize(String string) 109 { 110 StatorCurrentLimit = ConfigJNI.Deserializedouble(SpnValue.Config_StatorCurrentLimit.value, string); 111 StatorCurrentLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_StatorCurrLimitEn.value, string); 112 SupplyCurrentLimit = ConfigJNI.Deserializedouble(SpnValue.Config_SupplyCurrentLimit.value, string); 113 SupplyCurrentLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_SupplyCurrLimitEn.value, string); 114 SupplyCurrentThreshold = ConfigJNI.Deserializedouble(SpnValue.Config_SupplyCurrThres.value, string); 115 SupplyTimeThreshold = ConfigJNI.Deserializedouble(SpnValue.Config_SupplyTimeThres.value, string); 116 return StatusCode.OK; 117 } 118 119 /** 120 * 121 */ 122 public String serialize() 123 { 124 String ss = ""; 125 ss += ConfigJNI.Serializedouble(1427, StatorCurrentLimit); 126 ss += ConfigJNI.Serializeboolean(1428, StatorCurrentLimitEnable); 127 ss += ConfigJNI.Serializedouble(1429, SupplyCurrentLimit); 128 ss += ConfigJNI.Serializeboolean(1430, SupplyCurrentLimitEnable); 129 ss += ConfigJNI.Serializedouble(1505, SupplyCurrentThreshold); 130 ss += ConfigJNI.Serializedouble(1506, SupplyTimeThreshold); 131 return ss; 132 } 133} 134