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.phoenix6.configs; 008 009import com.ctre.phoenix6.StatusCode; 010import com.ctre.phoenix6.configs.jni.ConfigJNI; 011import com.ctre.phoenix6.spns.*; 012 013import edu.wpi.first.units.*; 014 015import edu.wpi.first.units.measure.*; 016import static edu.wpi.first.units.Units.*; 017 018/** 019 * Configs related to constants used for differential control of a 020 * mechanism. 021 * <p> 022 * Includes the differential peak outputs. 023 */ 024public class DifferentialConstantsConfigs implements ParentConfiguration 025{ 026 /** 027 * Maximum differential output during duty cycle based differential 028 * control modes. 029 * 030 * <ul> 031 * <li> <b>Minimum Value:</b> 0.0 032 * <li> <b>Maximum Value:</b> 2.0 033 * <li> <b>Default Value:</b> 2 034 * <li> <b>Units:</b> fractional 035 * </ul> 036 */ 037 public double PeakDifferentialDutyCycle = 2; 038 /** 039 * Maximum differential output during voltage based differential 040 * control modes. 041 * 042 * <ul> 043 * <li> <b>Minimum Value:</b> 0.0 044 * <li> <b>Maximum Value:</b> 32 045 * <li> <b>Default Value:</b> 32 046 * <li> <b>Units:</b> V 047 * </ul> 048 */ 049 public double PeakDifferentialVoltage = 32; 050 /** 051 * Maximum differential output during torque current based 052 * differential control modes. 053 * 054 * <ul> 055 * <li> <b>Minimum Value:</b> 0.0 056 * <li> <b>Maximum Value:</b> 1600 057 * <li> <b>Default Value:</b> 1600 058 * <li> <b>Units:</b> A 059 * </ul> 060 */ 061 public double PeakDifferentialTorqueCurrent = 1600; 062 063 /** 064 * Modifies this configuration's PeakDifferentialDutyCycle parameter and returns itself for 065 * method-chaining and easier to use config API. 066 * <p> 067 * Maximum differential output during duty cycle based differential 068 * control modes. 069 * 070 * <ul> 071 * <li> <b>Minimum Value:</b> 0.0 072 * <li> <b>Maximum Value:</b> 2.0 073 * <li> <b>Default Value:</b> 2 074 * <li> <b>Units:</b> fractional 075 * </ul> 076 * 077 * @param newPeakDifferentialDutyCycle Parameter to modify 078 * @return Itself 079 */ 080 public DifferentialConstantsConfigs withPeakDifferentialDutyCycle(double newPeakDifferentialDutyCycle) 081 { 082 PeakDifferentialDutyCycle = newPeakDifferentialDutyCycle; 083 return this; 084 } 085 086 /** 087 * Modifies this configuration's PeakDifferentialVoltage parameter and returns itself for 088 * method-chaining and easier to use config API. 089 * <p> 090 * Maximum differential output during voltage based differential 091 * control modes. 092 * 093 * <ul> 094 * <li> <b>Minimum Value:</b> 0.0 095 * <li> <b>Maximum Value:</b> 32 096 * <li> <b>Default Value:</b> 32 097 * <li> <b>Units:</b> V 098 * </ul> 099 * 100 * @param newPeakDifferentialVoltage Parameter to modify 101 * @return Itself 102 */ 103 public DifferentialConstantsConfigs withPeakDifferentialVoltage(double newPeakDifferentialVoltage) 104 { 105 PeakDifferentialVoltage = newPeakDifferentialVoltage; 106 return this; 107 } 108 109 /** 110 * Modifies this configuration's PeakDifferentialVoltage parameter and returns itself for 111 * method-chaining and easier to use config API. 112 * <p> 113 * Maximum differential output during voltage based differential 114 * control modes. 115 * 116 * <ul> 117 * <li> <b>Minimum Value:</b> 0.0 118 * <li> <b>Maximum Value:</b> 32 119 * <li> <b>Default Value:</b> 32 120 * <li> <b>Units:</b> V 121 * </ul> 122 * 123 * @param newPeakDifferentialVoltage Parameter to modify 124 * @return Itself 125 */ 126 public DifferentialConstantsConfigs withPeakDifferentialVoltage(Voltage newPeakDifferentialVoltage) 127 { 128 PeakDifferentialVoltage = newPeakDifferentialVoltage.in(Volts); 129 return this; 130 } 131 132 /** 133 * Helper method to get this configuration's PeakDifferentialVoltage parameter converted 134 * to a unit type. If not using the Java units library, {@link #PeakDifferentialVoltage} 135 * can be accessed directly instead. 136 * <p> 137 * Maximum differential output during voltage based differential 138 * control modes. 139 * 140 * <ul> 141 * <li> <b>Minimum Value:</b> 0.0 142 * <li> <b>Maximum Value:</b> 32 143 * <li> <b>Default Value:</b> 32 144 * <li> <b>Units:</b> V 145 * </ul> 146 * 147 * @return PeakDifferentialVoltage 148 */ 149 public Voltage getPeakDifferentialVoltageMeasure() 150 { 151 return Volts.of(PeakDifferentialVoltage); 152 } 153 154 /** 155 * Modifies this configuration's PeakDifferentialTorqueCurrent parameter and returns itself for 156 * method-chaining and easier to use config API. 157 * <p> 158 * Maximum differential output during torque current based 159 * differential control modes. 160 * 161 * <ul> 162 * <li> <b>Minimum Value:</b> 0.0 163 * <li> <b>Maximum Value:</b> 1600 164 * <li> <b>Default Value:</b> 1600 165 * <li> <b>Units:</b> A 166 * </ul> 167 * 168 * @param newPeakDifferentialTorqueCurrent Parameter to modify 169 * @return Itself 170 */ 171 public DifferentialConstantsConfigs withPeakDifferentialTorqueCurrent(double newPeakDifferentialTorqueCurrent) 172 { 173 PeakDifferentialTorqueCurrent = newPeakDifferentialTorqueCurrent; 174 return this; 175 } 176 177 /** 178 * Modifies this configuration's PeakDifferentialTorqueCurrent parameter and returns itself for 179 * method-chaining and easier to use config API. 180 * <p> 181 * Maximum differential output during torque current based 182 * differential control modes. 183 * 184 * <ul> 185 * <li> <b>Minimum Value:</b> 0.0 186 * <li> <b>Maximum Value:</b> 1600 187 * <li> <b>Default Value:</b> 1600 188 * <li> <b>Units:</b> A 189 * </ul> 190 * 191 * @param newPeakDifferentialTorqueCurrent Parameter to modify 192 * @return Itself 193 */ 194 public DifferentialConstantsConfigs withPeakDifferentialTorqueCurrent(Current newPeakDifferentialTorqueCurrent) 195 { 196 PeakDifferentialTorqueCurrent = newPeakDifferentialTorqueCurrent.in(Amps); 197 return this; 198 } 199 200 /** 201 * Helper method to get this configuration's PeakDifferentialTorqueCurrent parameter converted 202 * to a unit type. If not using the Java units library, {@link #PeakDifferentialTorqueCurrent} 203 * can be accessed directly instead. 204 * <p> 205 * Maximum differential output during torque current based 206 * differential control modes. 207 * 208 * <ul> 209 * <li> <b>Minimum Value:</b> 0.0 210 * <li> <b>Maximum Value:</b> 1600 211 * <li> <b>Default Value:</b> 1600 212 * <li> <b>Units:</b> A 213 * </ul> 214 * 215 * @return PeakDifferentialTorqueCurrent 216 */ 217 public Current getPeakDifferentialTorqueCurrentMeasure() 218 { 219 return Amps.of(PeakDifferentialTorqueCurrent); 220 } 221 222 223 224 @Override 225 public String toString() 226 { 227 String ss = "Config Group: DifferentialConstants\n"; 228 ss += " PeakDifferentialDutyCycle: " + PeakDifferentialDutyCycle + " fractional" + "\n"; 229 ss += " PeakDifferentialVoltage: " + PeakDifferentialVoltage + " V" + "\n"; 230 ss += " PeakDifferentialTorqueCurrent: " + PeakDifferentialTorqueCurrent + " A" + "\n"; 231 return ss; 232 } 233 234 /** 235 * 236 */ 237 public StatusCode deserialize(String to_deserialize) 238 { 239 PeakDifferentialDutyCycle = ConfigJNI.Deserializedouble(SpnValue.Config_PeakDiffDC.value, to_deserialize); 240 PeakDifferentialVoltage = ConfigJNI.Deserializedouble(SpnValue.Config_PeakDiffV.value, to_deserialize); 241 PeakDifferentialTorqueCurrent = ConfigJNI.Deserializedouble(SpnValue.Config_PeakDiffTorqCurr.value, to_deserialize); 242 return StatusCode.OK; 243 } 244 245 /** 246 * 247 */ 248 public String serialize() 249 { 250 String ss = ""; 251 ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakDiffDC.value, PeakDifferentialDutyCycle); 252 ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakDiffV.value, PeakDifferentialVoltage); 253 ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakDiffTorqCurr.value, PeakDifferentialTorqueCurrent); 254 return ss; 255 } 256} 257