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