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 * What the gains for slot 0 are 015 * <p> 016 * If this slot is selected, these gains are used in closed loop 017 * control requests. 018 */ 019public class Slot0Configs implements ParentConfiguration 020{ 021 /** 022 * Proportional Gain 023 * <p> 024 * The units for this gain is dependent on the control mode. Since 025 * this gain is multiplied by error in the input, the units should be 026 * defined as units of output per unit of input error. For example, 027 * when controlling velocity using a duty cycle closed loop, the units 028 * for the proportional gain will be duty cycle per rps of error, or 029 * 1/rps. 030 * 031 * <ul> 032 * <li> <b>Minimum Value:</b> 0 033 * <li> <b>Maximum Value:</b> 3.4e+38 034 * <li> <b>Default Value:</b> 0 035 * <li> <b>Units:</b> 036 * </ul> 037 */ 038 public double kP = 0; 039 /** 040 * Integral Gain 041 * <p> 042 * The units for this gain is dependent on the control mode. Since 043 * this gain is multiplied by error in the input integrated over time 044 * (in units of seconds), the units should be defined as units of 045 * output per unit of integrated input error. For example, when 046 * controlling velocity using a duty cycle closed loop, integrating 047 * velocity over time results in rps * s = rotations. Therefore, the 048 * units for the integral gain will be duty cycle per rotation of 049 * accumulated error, or 1/rot. 050 * 051 * <ul> 052 * <li> <b>Minimum Value:</b> 0 053 * <li> <b>Maximum Value:</b> 3.4e+38 054 * <li> <b>Default Value:</b> 0 055 * <li> <b>Units:</b> 056 * </ul> 057 */ 058 public double kI = 0; 059 /** 060 * Derivative Gain 061 * <p> 062 * The units for this gain is dependent on the control mode. Since 063 * this gain is multiplied by the derivative of error in the input 064 * with respect to time (in units of seconds), the units should be 065 * defined as units of output per unit of the differentiated input 066 * error. For example, when controlling velocity using a duty cycle 067 * closed loop, the derivative of velocity with respect to time is 068 * rps/s, which is acceleration. Therefore, the units for the 069 * derivative gain will be duty cycle per unit of acceleration error, 070 * or 1/(rps/s). 071 * 072 * <ul> 073 * <li> <b>Minimum Value:</b> 0 074 * <li> <b>Maximum Value:</b> 3.4e+38 075 * <li> <b>Default Value:</b> 0 076 * <li> <b>Units:</b> 077 * </ul> 078 */ 079 public double kD = 0; 080 /** 081 * Velocity Feed Forward Gain 082 * <p> 083 * The units for this gain is dependent on the control mode. Since 084 * this gain is multiplied by the requested velocity, the units should 085 * be defined as units of output per unit of requested input velocity. 086 * For example, when controlling velocity using a duty cycle closed 087 * loop, the units for the velocity feed foward gain will be duty 088 * cycle per requested rps, or 1/rps. 089 * 090 * <ul> 091 * <li> <b>Minimum Value:</b> 0 092 * <li> <b>Maximum Value:</b> 3.4e+38 093 * <li> <b>Default Value:</b> 0 094 * <li> <b>Units:</b> 095 * </ul> 096 */ 097 public double kV = 0; 098 /** 099 * Static Constant 100 * <p> 101 * This is added to the closed loop output. The sign is determined by 102 * target velocity. The unit for this constant is dependent on the 103 * control mode, typically fractional duty cycle, voltage, or torque 104 * current. 105 * 106 * <ul> 107 * <li> <b>Minimum Value:</b> -512 108 * <li> <b>Maximum Value:</b> 511 109 * <li> <b>Default Value:</b> 0 110 * <li> <b>Units:</b> 111 * </ul> 112 */ 113 public double kS = 0; 114 115 @Override 116 public String toString() 117 { 118 String ss = "Config Group: Slot0\n"; 119 ss += "Name: \"kP\" Value: \"" + kP + "\"" + "\n"; 120 ss += "Name: \"kI\" Value: \"" + kI + "\"" + "\n"; 121 ss += "Name: \"kD\" Value: \"" + kD + "\"" + "\n"; 122 ss += "Name: \"kV\" Value: \"" + kV + "\"" + "\n"; 123 ss += "Name: \"kS\" Value: \"" + kS + "\"" + "\n"; 124 return ss; 125 } 126 127 /** 128 * 129 */ 130 public StatusCode deserialize(String string) 131 { 132 kP = ConfigJNI.Deserializedouble(SpnValue.Slot0_kP.value, string); 133 kI = ConfigJNI.Deserializedouble(SpnValue.Slot0_kI.value, string); 134 kD = ConfigJNI.Deserializedouble(SpnValue.Slot0_kD.value, string); 135 kV = ConfigJNI.Deserializedouble(SpnValue.Slot0_kV.value, string); 136 kS = ConfigJNI.Deserializedouble(SpnValue.Slot0_kS.value, string); 137 return StatusCode.OK; 138 } 139 140 /** 141 * 142 */ 143 public String serialize() 144 { 145 String ss = ""; 146 ss += ConfigJNI.Serializedouble(1407, kP); 147 ss += ConfigJNI.Serializedouble(1408, kI); 148 ss += ConfigJNI.Serializedouble(1409, kD); 149 ss += ConfigJNI.Serializedouble(1410, kV); 150 ss += ConfigJNI.Serializedouble(1411, kS); 151 return ss; 152 } 153} 154