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 that affect the open-loop control of this motor controller. 020 * <p> 021 * Open-loop ramp rates for the various control types. 022 */ 023public class OpenLoopRampsConfigs implements ParentConfiguration, Cloneable { 024 /** 025 * If non-zero, this determines how much time to ramp from 0% output 026 * to 100% during the open-loop DutyCycleOut control mode. 027 * <p> 028 * This provides an easy way to limit the acceleration of the motor. 029 * However, the acceleration and current draw of the motor can be 030 * better restricted using current limits instead of a ramp rate. 031 * 032 * <ul> 033 * <li> <b>Minimum Value:</b> 0 034 * <li> <b>Maximum Value:</b> 1 035 * <li> <b>Default Value:</b> 0 036 * <li> <b>Units:</b> seconds 037 * </ul> 038 */ 039 public double DutyCycleOpenLoopRampPeriod = 0; 040 /** 041 * If non-zero, this determines how much time to ramp from 0V output 042 * to 12V during the open-loop VoltageOut control mode. 043 * <p> 044 * This provides an easy way to limit the acceleration of the motor. 045 * However, the acceleration and current draw of the motor can be 046 * better restricted using current limits instead of a ramp rate. 047 * 048 * <ul> 049 * <li> <b>Minimum Value:</b> 0 050 * <li> <b>Maximum Value:</b> 1 051 * <li> <b>Default Value:</b> 0 052 * <li> <b>Units:</b> seconds 053 * </ul> 054 */ 055 public double VoltageOpenLoopRampPeriod = 0; 056 /** 057 * If non-zero, this determines how much time to ramp from 0A output 058 * to 300A during the open-loop TorqueCurrent control mode. 059 * <p> 060 * Since TorqueCurrent is directly proportional to acceleration, this 061 * ramp limits jerk instead of acceleration. 062 * 063 * <ul> 064 * <li> <b>Minimum Value:</b> 0 065 * <li> <b>Maximum Value:</b> 10 066 * <li> <b>Default Value:</b> 0 067 * <li> <b>Units:</b> seconds 068 * </ul> 069 */ 070 public double TorqueOpenLoopRampPeriod = 0; 071 072 /** 073 * Modifies this configuration's DutyCycleOpenLoopRampPeriod parameter and returns itself for 074 * method-chaining and easier to use config API. 075 * <p> 076 * If non-zero, this determines how much time to ramp from 0% output 077 * to 100% during the open-loop DutyCycleOut control mode. 078 * <p> 079 * This provides an easy way to limit the acceleration of the motor. 080 * However, the acceleration and current draw of the motor can be 081 * better restricted using current limits instead of a ramp rate. 082 * 083 * <ul> 084 * <li> <b>Minimum Value:</b> 0 085 * <li> <b>Maximum Value:</b> 1 086 * <li> <b>Default Value:</b> 0 087 * <li> <b>Units:</b> seconds 088 * </ul> 089 * 090 * @param newDutyCycleOpenLoopRampPeriod Parameter to modify 091 * @return Itself 092 */ 093 public final OpenLoopRampsConfigs withDutyCycleOpenLoopRampPeriod(double newDutyCycleOpenLoopRampPeriod) 094 { 095 DutyCycleOpenLoopRampPeriod = newDutyCycleOpenLoopRampPeriod; 096 return this; 097 } 098 099 /** 100 * Modifies this configuration's DutyCycleOpenLoopRampPeriod parameter and returns itself for 101 * method-chaining and easier to use config API. 102 * <p> 103 * If non-zero, this determines how much time to ramp from 0% output 104 * to 100% during the open-loop DutyCycleOut control mode. 105 * <p> 106 * This provides an easy way to limit the acceleration of the motor. 107 * However, the acceleration and current draw of the motor can be 108 * better restricted using current limits instead of a ramp rate. 109 * 110 * <ul> 111 * <li> <b>Minimum Value:</b> 0 112 * <li> <b>Maximum Value:</b> 1 113 * <li> <b>Default Value:</b> 0 114 * <li> <b>Units:</b> seconds 115 * </ul> 116 * 117 * @param newDutyCycleOpenLoopRampPeriod Parameter to modify 118 * @return Itself 119 */ 120 public final OpenLoopRampsConfigs withDutyCycleOpenLoopRampPeriod(Time newDutyCycleOpenLoopRampPeriod) 121 { 122 DutyCycleOpenLoopRampPeriod = newDutyCycleOpenLoopRampPeriod.in(Seconds); 123 return this; 124 } 125 126 /** 127 * Helper method to get this configuration's DutyCycleOpenLoopRampPeriod parameter converted 128 * to a unit type. If not using the Java units library, {@link #DutyCycleOpenLoopRampPeriod} 129 * can be accessed directly instead. 130 * <p> 131 * If non-zero, this determines how much time to ramp from 0% output 132 * to 100% during the open-loop DutyCycleOut control mode. 133 * <p> 134 * This provides an easy way to limit the acceleration of the motor. 135 * However, the acceleration and current draw of the motor can be 136 * better restricted using current limits instead of a ramp rate. 137 * 138 * <ul> 139 * <li> <b>Minimum Value:</b> 0 140 * <li> <b>Maximum Value:</b> 1 141 * <li> <b>Default Value:</b> 0 142 * <li> <b>Units:</b> seconds 143 * </ul> 144 * 145 * @return DutyCycleOpenLoopRampPeriod 146 */ 147 public final Time getDutyCycleOpenLoopRampPeriodMeasure() 148 { 149 return Seconds.of(DutyCycleOpenLoopRampPeriod); 150 } 151 152 /** 153 * Modifies this configuration's VoltageOpenLoopRampPeriod parameter and returns itself for 154 * method-chaining and easier to use config API. 155 * <p> 156 * If non-zero, this determines how much time to ramp from 0V output 157 * to 12V during the open-loop VoltageOut control mode. 158 * <p> 159 * This provides an easy way to limit the acceleration of the motor. 160 * However, the acceleration and current draw of the motor can be 161 * better restricted using current limits instead of a ramp rate. 162 * 163 * <ul> 164 * <li> <b>Minimum Value:</b> 0 165 * <li> <b>Maximum Value:</b> 1 166 * <li> <b>Default Value:</b> 0 167 * <li> <b>Units:</b> seconds 168 * </ul> 169 * 170 * @param newVoltageOpenLoopRampPeriod Parameter to modify 171 * @return Itself 172 */ 173 public final OpenLoopRampsConfigs withVoltageOpenLoopRampPeriod(double newVoltageOpenLoopRampPeriod) 174 { 175 VoltageOpenLoopRampPeriod = newVoltageOpenLoopRampPeriod; 176 return this; 177 } 178 179 /** 180 * Modifies this configuration's VoltageOpenLoopRampPeriod parameter and returns itself for 181 * method-chaining and easier to use config API. 182 * <p> 183 * If non-zero, this determines how much time to ramp from 0V output 184 * to 12V during the open-loop VoltageOut control mode. 185 * <p> 186 * This provides an easy way to limit the acceleration of the motor. 187 * However, the acceleration and current draw of the motor can be 188 * better restricted using current limits instead of a ramp rate. 189 * 190 * <ul> 191 * <li> <b>Minimum Value:</b> 0 192 * <li> <b>Maximum Value:</b> 1 193 * <li> <b>Default Value:</b> 0 194 * <li> <b>Units:</b> seconds 195 * </ul> 196 * 197 * @param newVoltageOpenLoopRampPeriod Parameter to modify 198 * @return Itself 199 */ 200 public final OpenLoopRampsConfigs withVoltageOpenLoopRampPeriod(Time newVoltageOpenLoopRampPeriod) 201 { 202 VoltageOpenLoopRampPeriod = newVoltageOpenLoopRampPeriod.in(Seconds); 203 return this; 204 } 205 206 /** 207 * Helper method to get this configuration's VoltageOpenLoopRampPeriod parameter converted 208 * to a unit type. If not using the Java units library, {@link #VoltageOpenLoopRampPeriod} 209 * can be accessed directly instead. 210 * <p> 211 * If non-zero, this determines how much time to ramp from 0V output 212 * to 12V during the open-loop VoltageOut control mode. 213 * <p> 214 * This provides an easy way to limit the acceleration of the motor. 215 * However, the acceleration and current draw of the motor can be 216 * better restricted using current limits instead of a ramp rate. 217 * 218 * <ul> 219 * <li> <b>Minimum Value:</b> 0 220 * <li> <b>Maximum Value:</b> 1 221 * <li> <b>Default Value:</b> 0 222 * <li> <b>Units:</b> seconds 223 * </ul> 224 * 225 * @return VoltageOpenLoopRampPeriod 226 */ 227 public final Time getVoltageOpenLoopRampPeriodMeasure() 228 { 229 return Seconds.of(VoltageOpenLoopRampPeriod); 230 } 231 232 /** 233 * Modifies this configuration's TorqueOpenLoopRampPeriod parameter and returns itself for 234 * method-chaining and easier to use config API. 235 * <p> 236 * If non-zero, this determines how much time to ramp from 0A output 237 * to 300A during the open-loop TorqueCurrent control mode. 238 * <p> 239 * Since TorqueCurrent is directly proportional to acceleration, this 240 * ramp limits jerk instead of acceleration. 241 * 242 * <ul> 243 * <li> <b>Minimum Value:</b> 0 244 * <li> <b>Maximum Value:</b> 10 245 * <li> <b>Default Value:</b> 0 246 * <li> <b>Units:</b> seconds 247 * </ul> 248 * 249 * @param newTorqueOpenLoopRampPeriod Parameter to modify 250 * @return Itself 251 */ 252 public final OpenLoopRampsConfigs withTorqueOpenLoopRampPeriod(double newTorqueOpenLoopRampPeriod) 253 { 254 TorqueOpenLoopRampPeriod = newTorqueOpenLoopRampPeriod; 255 return this; 256 } 257 258 /** 259 * Modifies this configuration's TorqueOpenLoopRampPeriod parameter and returns itself for 260 * method-chaining and easier to use config API. 261 * <p> 262 * If non-zero, this determines how much time to ramp from 0A output 263 * to 300A during the open-loop TorqueCurrent control mode. 264 * <p> 265 * Since TorqueCurrent is directly proportional to acceleration, this 266 * ramp limits jerk instead of acceleration. 267 * 268 * <ul> 269 * <li> <b>Minimum Value:</b> 0 270 * <li> <b>Maximum Value:</b> 10 271 * <li> <b>Default Value:</b> 0 272 * <li> <b>Units:</b> seconds 273 * </ul> 274 * 275 * @param newTorqueOpenLoopRampPeriod Parameter to modify 276 * @return Itself 277 */ 278 public final OpenLoopRampsConfigs withTorqueOpenLoopRampPeriod(Time newTorqueOpenLoopRampPeriod) 279 { 280 TorqueOpenLoopRampPeriod = newTorqueOpenLoopRampPeriod.in(Seconds); 281 return this; 282 } 283 284 /** 285 * Helper method to get this configuration's TorqueOpenLoopRampPeriod parameter converted 286 * to a unit type. If not using the Java units library, {@link #TorqueOpenLoopRampPeriod} 287 * can be accessed directly instead. 288 * <p> 289 * If non-zero, this determines how much time to ramp from 0A output 290 * to 300A during the open-loop TorqueCurrent control mode. 291 * <p> 292 * Since TorqueCurrent is directly proportional to acceleration, this 293 * ramp limits jerk instead of acceleration. 294 * 295 * <ul> 296 * <li> <b>Minimum Value:</b> 0 297 * <li> <b>Maximum Value:</b> 10 298 * <li> <b>Default Value:</b> 0 299 * <li> <b>Units:</b> seconds 300 * </ul> 301 * 302 * @return TorqueOpenLoopRampPeriod 303 */ 304 public final Time getTorqueOpenLoopRampPeriodMeasure() 305 { 306 return Seconds.of(TorqueOpenLoopRampPeriod); 307 } 308 309 310 311 @Override 312 public String toString() { 313 String ss = "Config Group: OpenLoopRamps\n"; 314 ss += " DutyCycleOpenLoopRampPeriod: " + DutyCycleOpenLoopRampPeriod + " seconds" + "\n"; 315 ss += " VoltageOpenLoopRampPeriod: " + VoltageOpenLoopRampPeriod + " seconds" + "\n"; 316 ss += " TorqueOpenLoopRampPeriod: " + TorqueOpenLoopRampPeriod + " seconds" + "\n"; 317 return ss; 318 } 319 320 /** 321 * Get the serialized form of this configuration group. 322 * 323 * @return Serialized form of this config group 324 */ 325 @Override 326 public final String serialize() { 327 String ss = ""; 328 ss += ConfigJNI.Serializedouble(SpnValue.Config_DutyCycleOpenLoopRampPeriod.value, DutyCycleOpenLoopRampPeriod); 329 ss += ConfigJNI.Serializedouble(SpnValue.Config_VoltageOpenLoopRampPeriod.value, VoltageOpenLoopRampPeriod); 330 ss += ConfigJNI.Serializedouble(SpnValue.Config_TorqueOpenLoopRampPeriod.value, TorqueOpenLoopRampPeriod); 331 return ss; 332 } 333 334 /** 335 * Take a string and deserialize it to this configuration group. 336 * 337 * @return Return code of the deserialize method 338 */ 339 @Override 340 public final StatusCode deserialize(String to_deserialize) { 341 DutyCycleOpenLoopRampPeriod = ConfigJNI.Deserializedouble(SpnValue.Config_DutyCycleOpenLoopRampPeriod.value, to_deserialize); 342 VoltageOpenLoopRampPeriod = ConfigJNI.Deserializedouble(SpnValue.Config_VoltageOpenLoopRampPeriod.value, to_deserialize); 343 TorqueOpenLoopRampPeriod = ConfigJNI.Deserializedouble(SpnValue.Config_TorqueOpenLoopRampPeriod.value, to_deserialize); 344 return StatusCode.OK; 345 } 346 347 @Override 348 public OpenLoopRampsConfigs clone() { 349 try { 350 return (OpenLoopRampsConfigs)super.clone(); 351 } catch (CloneNotSupportedException ex) { 352 /* this should never happen */ 353 throw new RuntimeException(ex); 354 } 355 } 356} 357