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.*; 012import com.ctre.phoenix6.signals.*; 013 014import edu.wpi.first.units.*; 015 016import edu.wpi.first.units.measure.*; 017import static edu.wpi.first.units.Units.*; 018import com.ctre.phoenix6.hardware.traits.CommonTalon; 019import com.ctre.phoenix6.hardware.core.CoreCANcoder; 020import com.ctre.phoenix6.hardware.core.CoreCANrange; 021import com.ctre.phoenix6.hardware.core.CoreCANdi; 022 023/** 024 * Configs that change how the motor controller behaves under 025 * different limit switch states. 026 * <p> 027 * Includes configs such as enabling limit switches, configuring the 028 * remote sensor ID, the source, and the position to set on limit. 029 */ 030public class HardwareLimitSwitchConfigs implements ParentConfiguration, Cloneable { 031 /** 032 * Determines if the forward limit switch is normally-open (default) 033 * or normally-closed. 034 * 035 */ 036 public ForwardLimitTypeValue ForwardLimitType = ForwardLimitTypeValue.NormallyOpen; 037 /** 038 * If enabled, the position is automatically set to a specific value, 039 * specified by ForwardLimitAutosetPositionValue, when the forward 040 * limit switch is asserted. 041 * 042 * <ul> 043 * <li> <b>Default Value:</b> False 044 * </ul> 045 */ 046 public boolean ForwardLimitAutosetPositionEnable = false; 047 /** 048 * The value to automatically set the position to when the forward 049 * limit switch is asserted. This has no effect if 050 * ForwardLimitAutosetPositionEnable is false. 051 * 052 * <ul> 053 * <li> <b>Minimum Value:</b> -3.4e+38 054 * <li> <b>Maximum Value:</b> 3.4e+38 055 * <li> <b>Default Value:</b> 0 056 * <li> <b>Units:</b> rotations 057 * </ul> 058 */ 059 public double ForwardLimitAutosetPositionValue = 0; 060 /** 061 * If enabled, motor output is set to neutral when the forward limit 062 * switch is asserted and positive output is requested. 063 * 064 * <ul> 065 * <li> <b>Default Value:</b> True 066 * </ul> 067 */ 068 public boolean ForwardLimitEnable = true; 069 /** 070 * Determines where to poll the forward limit switch. This defaults 071 * to the forward limit switch pin on the limit switch connector. 072 * <p> 073 * Choose RemoteTalonFX to use the forward limit switch attached to 074 * another Talon FX on the same CAN bus (this also requires setting 075 * ForwardLimitRemoteSensorID). 076 * <p> 077 * Choose RemoteCANifier to use the forward limit switch attached to 078 * another CANifier on the same CAN bus (this also requires setting 079 * ForwardLimitRemoteSensorID). 080 * <p> 081 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus 082 * (this also requires setting ForwardLimitRemoteSensorID). The 083 * forward limit will assert when the CANcoder magnet strength changes 084 * from BAD (red) to ADEQUATE (orange) or GOOD (green). 085 * 086 */ 087 public ForwardLimitSourceValue ForwardLimitSource = ForwardLimitSourceValue.LimitSwitchPin; 088 /** 089 * Device ID of the remote device if using remote limit switch 090 * features for the forward limit switch. 091 * 092 * <ul> 093 * <li> <b>Minimum Value:</b> 0 094 * <li> <b>Maximum Value:</b> 62 095 * <li> <b>Default Value:</b> 0 096 * <li> <b>Units:</b> 097 * </ul> 098 */ 099 public int ForwardLimitRemoteSensorID = 0; 100 /** 101 * Determines if the reverse limit switch is normally-open (default) 102 * or normally-closed. 103 * 104 */ 105 public ReverseLimitTypeValue ReverseLimitType = ReverseLimitTypeValue.NormallyOpen; 106 /** 107 * If enabled, the position is automatically set to a specific value, 108 * specified by ReverseLimitAutosetPositionValue, when the reverse 109 * limit switch is asserted. 110 * 111 * <ul> 112 * <li> <b>Default Value:</b> False 113 * </ul> 114 */ 115 public boolean ReverseLimitAutosetPositionEnable = false; 116 /** 117 * The value to automatically set the position to when the reverse 118 * limit switch is asserted. This has no effect if 119 * ReverseLimitAutosetPositionEnable is false. 120 * 121 * <ul> 122 * <li> <b>Minimum Value:</b> -3.4e+38 123 * <li> <b>Maximum Value:</b> 3.4e+38 124 * <li> <b>Default Value:</b> 0 125 * <li> <b>Units:</b> rotations 126 * </ul> 127 */ 128 public double ReverseLimitAutosetPositionValue = 0; 129 /** 130 * If enabled, motor output is set to neutral when reverse limit 131 * switch is asseted and negative output is requested. 132 * 133 * <ul> 134 * <li> <b>Default Value:</b> True 135 * </ul> 136 */ 137 public boolean ReverseLimitEnable = true; 138 /** 139 * Determines where to poll the reverse limit switch. This defaults 140 * to the reverse limit switch pin on the limit switch connector. 141 * <p> 142 * Choose RemoteTalonFX to use the reverse limit switch attached to 143 * another Talon FX on the same CAN bus (this also requires setting 144 * ReverseLimitRemoteSensorID). 145 * <p> 146 * Choose RemoteCANifier to use the reverse limit switch attached to 147 * another CANifier on the same CAN bus (this also requires setting 148 * ReverseLimitRemoteSensorID). 149 * <p> 150 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus 151 * (this also requires setting ReverseLimitRemoteSensorID). The 152 * reverse limit will assert when the CANcoder magnet strength changes 153 * from BAD (red) to ADEQUATE (orange) or GOOD (green). 154 * 155 */ 156 public ReverseLimitSourceValue ReverseLimitSource = ReverseLimitSourceValue.LimitSwitchPin; 157 /** 158 * Device ID of the remote device if using remote limit switch 159 * features for the reverse limit switch. 160 * 161 * <ul> 162 * <li> <b>Minimum Value:</b> 0 163 * <li> <b>Maximum Value:</b> 62 164 * <li> <b>Default Value:</b> 0 165 * <li> <b>Units:</b> 166 * </ul> 167 */ 168 public int ReverseLimitRemoteSensorID = 0; 169 170 /** 171 * Modifies this configuration's ForwardLimitType parameter and returns itself for 172 * method-chaining and easier to use config API. 173 * <p> 174 * Determines if the forward limit switch is normally-open (default) 175 * or normally-closed. 176 * 177 * 178 * @param newForwardLimitType Parameter to modify 179 * @return Itself 180 */ 181 public final HardwareLimitSwitchConfigs withForwardLimitType(ForwardLimitTypeValue newForwardLimitType) 182 { 183 ForwardLimitType = newForwardLimitType; 184 return this; 185 } 186 187 /** 188 * Modifies this configuration's ForwardLimitAutosetPositionEnable parameter and returns itself for 189 * method-chaining and easier to use config API. 190 * <p> 191 * If enabled, the position is automatically set to a specific value, 192 * specified by ForwardLimitAutosetPositionValue, when the forward 193 * limit switch is asserted. 194 * 195 * <ul> 196 * <li> <b>Default Value:</b> False 197 * </ul> 198 * 199 * @param newForwardLimitAutosetPositionEnable Parameter to modify 200 * @return Itself 201 */ 202 public final HardwareLimitSwitchConfigs withForwardLimitAutosetPositionEnable(boolean newForwardLimitAutosetPositionEnable) 203 { 204 ForwardLimitAutosetPositionEnable = newForwardLimitAutosetPositionEnable; 205 return this; 206 } 207 208 /** 209 * Modifies this configuration's ForwardLimitAutosetPositionValue parameter and returns itself for 210 * method-chaining and easier to use config API. 211 * <p> 212 * The value to automatically set the position to when the forward 213 * limit switch is asserted. This has no effect if 214 * ForwardLimitAutosetPositionEnable is false. 215 * 216 * <ul> 217 * <li> <b>Minimum Value:</b> -3.4e+38 218 * <li> <b>Maximum Value:</b> 3.4e+38 219 * <li> <b>Default Value:</b> 0 220 * <li> <b>Units:</b> rotations 221 * </ul> 222 * 223 * @param newForwardLimitAutosetPositionValue Parameter to modify 224 * @return Itself 225 */ 226 public final HardwareLimitSwitchConfigs withForwardLimitAutosetPositionValue(double newForwardLimitAutosetPositionValue) 227 { 228 ForwardLimitAutosetPositionValue = newForwardLimitAutosetPositionValue; 229 return this; 230 } 231 232 /** 233 * Modifies this configuration's ForwardLimitAutosetPositionValue parameter and returns itself for 234 * method-chaining and easier to use config API. 235 * <p> 236 * The value to automatically set the position to when the forward 237 * limit switch is asserted. This has no effect if 238 * ForwardLimitAutosetPositionEnable is false. 239 * 240 * <ul> 241 * <li> <b>Minimum Value:</b> -3.4e+38 242 * <li> <b>Maximum Value:</b> 3.4e+38 243 * <li> <b>Default Value:</b> 0 244 * <li> <b>Units:</b> rotations 245 * </ul> 246 * 247 * @param newForwardLimitAutosetPositionValue Parameter to modify 248 * @return Itself 249 */ 250 public final HardwareLimitSwitchConfigs withForwardLimitAutosetPositionValue(Angle newForwardLimitAutosetPositionValue) 251 { 252 ForwardLimitAutosetPositionValue = newForwardLimitAutosetPositionValue.in(Rotations); 253 return this; 254 } 255 256 /** 257 * Helper method to get this configuration's ForwardLimitAutosetPositionValue parameter converted 258 * to a unit type. If not using the Java units library, {@link #ForwardLimitAutosetPositionValue} 259 * can be accessed directly instead. 260 * <p> 261 * The value to automatically set the position to when the forward 262 * limit switch is asserted. This has no effect if 263 * ForwardLimitAutosetPositionEnable is false. 264 * 265 * <ul> 266 * <li> <b>Minimum Value:</b> -3.4e+38 267 * <li> <b>Maximum Value:</b> 3.4e+38 268 * <li> <b>Default Value:</b> 0 269 * <li> <b>Units:</b> rotations 270 * </ul> 271 * 272 * @return ForwardLimitAutosetPositionValue 273 */ 274 public final Angle getForwardLimitAutosetPositionValueMeasure() 275 { 276 return Rotations.of(ForwardLimitAutosetPositionValue); 277 } 278 279 /** 280 * Modifies this configuration's ForwardLimitEnable parameter and returns itself for 281 * method-chaining and easier to use config API. 282 * <p> 283 * If enabled, motor output is set to neutral when the forward limit 284 * switch is asserted and positive output is requested. 285 * 286 * <ul> 287 * <li> <b>Default Value:</b> True 288 * </ul> 289 * 290 * @param newForwardLimitEnable Parameter to modify 291 * @return Itself 292 */ 293 public final HardwareLimitSwitchConfigs withForwardLimitEnable(boolean newForwardLimitEnable) 294 { 295 ForwardLimitEnable = newForwardLimitEnable; 296 return this; 297 } 298 299 /** 300 * Modifies this configuration's ForwardLimitSource parameter and returns itself for 301 * method-chaining and easier to use config API. 302 * <p> 303 * Determines where to poll the forward limit switch. This defaults 304 * to the forward limit switch pin on the limit switch connector. 305 * <p> 306 * Choose RemoteTalonFX to use the forward limit switch attached to 307 * another Talon FX on the same CAN bus (this also requires setting 308 * ForwardLimitRemoteSensorID). 309 * <p> 310 * Choose RemoteCANifier to use the forward limit switch attached to 311 * another CANifier on the same CAN bus (this also requires setting 312 * ForwardLimitRemoteSensorID). 313 * <p> 314 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus 315 * (this also requires setting ForwardLimitRemoteSensorID). The 316 * forward limit will assert when the CANcoder magnet strength changes 317 * from BAD (red) to ADEQUATE (orange) or GOOD (green). 318 * 319 * 320 * @param newForwardLimitSource Parameter to modify 321 * @return Itself 322 */ 323 public final HardwareLimitSwitchConfigs withForwardLimitSource(ForwardLimitSourceValue newForwardLimitSource) 324 { 325 ForwardLimitSource = newForwardLimitSource; 326 return this; 327 } 328 329 /** 330 * Modifies this configuration's ForwardLimitRemoteSensorID parameter and returns itself for 331 * method-chaining and easier to use config API. 332 * <p> 333 * Device ID of the remote device if using remote limit switch 334 * features for the forward limit switch. 335 * 336 * <ul> 337 * <li> <b>Minimum Value:</b> 0 338 * <li> <b>Maximum Value:</b> 62 339 * <li> <b>Default Value:</b> 0 340 * <li> <b>Units:</b> 341 * </ul> 342 * 343 * @param newForwardLimitRemoteSensorID Parameter to modify 344 * @return Itself 345 */ 346 public final HardwareLimitSwitchConfigs withForwardLimitRemoteSensorID(int newForwardLimitRemoteSensorID) 347 { 348 ForwardLimitRemoteSensorID = newForwardLimitRemoteSensorID; 349 return this; 350 } 351 352 /** 353 * Modifies this configuration's ReverseLimitType parameter and returns itself for 354 * method-chaining and easier to use config API. 355 * <p> 356 * Determines if the reverse limit switch is normally-open (default) 357 * or normally-closed. 358 * 359 * 360 * @param newReverseLimitType Parameter to modify 361 * @return Itself 362 */ 363 public final HardwareLimitSwitchConfigs withReverseLimitType(ReverseLimitTypeValue newReverseLimitType) 364 { 365 ReverseLimitType = newReverseLimitType; 366 return this; 367 } 368 369 /** 370 * Modifies this configuration's ReverseLimitAutosetPositionEnable parameter and returns itself for 371 * method-chaining and easier to use config API. 372 * <p> 373 * If enabled, the position is automatically set to a specific value, 374 * specified by ReverseLimitAutosetPositionValue, when the reverse 375 * limit switch is asserted. 376 * 377 * <ul> 378 * <li> <b>Default Value:</b> False 379 * </ul> 380 * 381 * @param newReverseLimitAutosetPositionEnable Parameter to modify 382 * @return Itself 383 */ 384 public final HardwareLimitSwitchConfigs withReverseLimitAutosetPositionEnable(boolean newReverseLimitAutosetPositionEnable) 385 { 386 ReverseLimitAutosetPositionEnable = newReverseLimitAutosetPositionEnable; 387 return this; 388 } 389 390 /** 391 * Modifies this configuration's ReverseLimitAutosetPositionValue parameter and returns itself for 392 * method-chaining and easier to use config API. 393 * <p> 394 * The value to automatically set the position to when the reverse 395 * limit switch is asserted. This has no effect if 396 * ReverseLimitAutosetPositionEnable is false. 397 * 398 * <ul> 399 * <li> <b>Minimum Value:</b> -3.4e+38 400 * <li> <b>Maximum Value:</b> 3.4e+38 401 * <li> <b>Default Value:</b> 0 402 * <li> <b>Units:</b> rotations 403 * </ul> 404 * 405 * @param newReverseLimitAutosetPositionValue Parameter to modify 406 * @return Itself 407 */ 408 public final HardwareLimitSwitchConfigs withReverseLimitAutosetPositionValue(double newReverseLimitAutosetPositionValue) 409 { 410 ReverseLimitAutosetPositionValue = newReverseLimitAutosetPositionValue; 411 return this; 412 } 413 414 /** 415 * Modifies this configuration's ReverseLimitAutosetPositionValue parameter and returns itself for 416 * method-chaining and easier to use config API. 417 * <p> 418 * The value to automatically set the position to when the reverse 419 * limit switch is asserted. This has no effect if 420 * ReverseLimitAutosetPositionEnable is false. 421 * 422 * <ul> 423 * <li> <b>Minimum Value:</b> -3.4e+38 424 * <li> <b>Maximum Value:</b> 3.4e+38 425 * <li> <b>Default Value:</b> 0 426 * <li> <b>Units:</b> rotations 427 * </ul> 428 * 429 * @param newReverseLimitAutosetPositionValue Parameter to modify 430 * @return Itself 431 */ 432 public final HardwareLimitSwitchConfigs withReverseLimitAutosetPositionValue(Angle newReverseLimitAutosetPositionValue) 433 { 434 ReverseLimitAutosetPositionValue = newReverseLimitAutosetPositionValue.in(Rotations); 435 return this; 436 } 437 438 /** 439 * Helper method to get this configuration's ReverseLimitAutosetPositionValue parameter converted 440 * to a unit type. If not using the Java units library, {@link #ReverseLimitAutosetPositionValue} 441 * can be accessed directly instead. 442 * <p> 443 * The value to automatically set the position to when the reverse 444 * limit switch is asserted. This has no effect if 445 * ReverseLimitAutosetPositionEnable is false. 446 * 447 * <ul> 448 * <li> <b>Minimum Value:</b> -3.4e+38 449 * <li> <b>Maximum Value:</b> 3.4e+38 450 * <li> <b>Default Value:</b> 0 451 * <li> <b>Units:</b> rotations 452 * </ul> 453 * 454 * @return ReverseLimitAutosetPositionValue 455 */ 456 public final Angle getReverseLimitAutosetPositionValueMeasure() 457 { 458 return Rotations.of(ReverseLimitAutosetPositionValue); 459 } 460 461 /** 462 * Modifies this configuration's ReverseLimitEnable parameter and returns itself for 463 * method-chaining and easier to use config API. 464 * <p> 465 * If enabled, motor output is set to neutral when reverse limit 466 * switch is asseted and negative output is requested. 467 * 468 * <ul> 469 * <li> <b>Default Value:</b> True 470 * </ul> 471 * 472 * @param newReverseLimitEnable Parameter to modify 473 * @return Itself 474 */ 475 public final HardwareLimitSwitchConfigs withReverseLimitEnable(boolean newReverseLimitEnable) 476 { 477 ReverseLimitEnable = newReverseLimitEnable; 478 return this; 479 } 480 481 /** 482 * Modifies this configuration's ReverseLimitSource parameter and returns itself for 483 * method-chaining and easier to use config API. 484 * <p> 485 * Determines where to poll the reverse limit switch. This defaults 486 * to the reverse limit switch pin on the limit switch connector. 487 * <p> 488 * Choose RemoteTalonFX to use the reverse limit switch attached to 489 * another Talon FX on the same CAN bus (this also requires setting 490 * ReverseLimitRemoteSensorID). 491 * <p> 492 * Choose RemoteCANifier to use the reverse limit switch attached to 493 * another CANifier on the same CAN bus (this also requires setting 494 * ReverseLimitRemoteSensorID). 495 * <p> 496 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus 497 * (this also requires setting ReverseLimitRemoteSensorID). The 498 * reverse limit will assert when the CANcoder magnet strength changes 499 * from BAD (red) to ADEQUATE (orange) or GOOD (green). 500 * 501 * 502 * @param newReverseLimitSource Parameter to modify 503 * @return Itself 504 */ 505 public final HardwareLimitSwitchConfigs withReverseLimitSource(ReverseLimitSourceValue newReverseLimitSource) 506 { 507 ReverseLimitSource = newReverseLimitSource; 508 return this; 509 } 510 511 /** 512 * Modifies this configuration's ReverseLimitRemoteSensorID parameter and returns itself for 513 * method-chaining and easier to use config API. 514 * <p> 515 * Device ID of the remote device if using remote limit switch 516 * features for the reverse limit switch. 517 * 518 * <ul> 519 * <li> <b>Minimum Value:</b> 0 520 * <li> <b>Maximum Value:</b> 62 521 * <li> <b>Default Value:</b> 0 522 * <li> <b>Units:</b> 523 * </ul> 524 * 525 * @param newReverseLimitRemoteSensorID Parameter to modify 526 * @return Itself 527 */ 528 public final HardwareLimitSwitchConfigs withReverseLimitRemoteSensorID(int newReverseLimitRemoteSensorID) 529 { 530 ReverseLimitRemoteSensorID = newReverseLimitRemoteSensorID; 531 return this; 532 } 533 534 /** 535 * Helper method to configure this feedback group to use RemoteTalonFX 536 * forward limit switch by passing in the CommonTalon object. When 537 * using RemoteTalonFX, the Talon FX will use the forward limit switch 538 * attached to another Talon FX on the same CAN bus. 539 * 540 * @param device CommonTalon reference to use for RemoteTalonFX forward limit 541 * switch 542 * @return Itself 543 */ 544 public final HardwareLimitSwitchConfigs withForwardLimitRemoteTalonFX(CommonTalon device) 545 { 546 ForwardLimitSource = ForwardLimitSourceValue.RemoteTalonFX; 547 ForwardLimitRemoteSensorID = device.getDeviceID(); 548 return this; 549 } 550 551 /** 552 * Helper method to configure this feedback group to use 553 * RemoteCANcoder forward limit switch by passing in the CANcoder 554 * object. When using RemoteCANcoder, the Talon FX will use another 555 * CANcoder on the same CAN bus. The forward limit will assert when 556 * the CANcoder magnet strength changes from BAD (red) to ADEQUATE 557 * (orange) or GOOD (green). 558 * 559 * @param device CANcoder reference to use for RemoteCANcoder forward limit 560 * switch 561 * @return Itself 562 */ 563 public final HardwareLimitSwitchConfigs withForwardLimitRemoteCANcoder(CoreCANcoder device) 564 { 565 ForwardLimitSource = ForwardLimitSourceValue.RemoteCANcoder; 566 ForwardLimitRemoteSensorID = device.getDeviceID(); 567 return this; 568 } 569 570 /** 571 * Helper method to configure this feedback group to use the 572 * RemoteCANrange by passing in the CANrange object. The forward limit 573 * will assert when the CANrange proximity detect is tripped. 574 * 575 * @param device CANrange reference to use for RemoteCANrange forward limit 576 * switch 577 * @return Itself 578 */ 579 public final HardwareLimitSwitchConfigs withForwardLimitRemoteCANrange(CoreCANrange device) 580 { 581 ForwardLimitSource = ForwardLimitSourceValue.RemoteCANrange; 582 ForwardLimitRemoteSensorID = device.getDeviceID(); 583 return this; 584 } 585 586 /** 587 * Helper method to configure this feedback group to use RemoteCANdi 588 * forward limit switch on Signal 1 Input (S1IN) by passing in the 589 * CANdi object. The forward limit will assert when the CANdi™ branded 590 * device's Signal 1 Input (S1IN) pin matches the configured closed 591 * state. 592 * 593 * @param device CANdi reference to use for RemoteCANdi forward limit switch 594 * @return Itself 595 */ 596 public final HardwareLimitSwitchConfigs withForwardLimitRemoteCANdiS1(CoreCANdi device) 597 { 598 ForwardLimitSource = ForwardLimitSourceValue.RemoteCANdiS1; 599 ForwardLimitRemoteSensorID = device.getDeviceID(); 600 return this; 601 } 602 603 /** 604 * Helper method to configure this feedback group to use RemoteCANdi 605 * forward limit switch on Signal 2 Input (S2IN) by passing in the 606 * CANdi object. The forward limit will assert when the CANdi™ branded 607 * device's Signal 2 Input (S2IN) pin matches the configured closed 608 * state. 609 * 610 * @param device CANdi reference to use for RemoteCANdi forward limit switch 611 * @return Itself 612 */ 613 public final HardwareLimitSwitchConfigs withForwardLimitRemoteCANdiS2(CoreCANdi device) 614 { 615 ForwardLimitSource = ForwardLimitSourceValue.RemoteCANdiS2; 616 ForwardLimitRemoteSensorID = device.getDeviceID(); 617 return this; 618 } 619 620 /** 621 * Helper method to configure this feedback group to use RemoteTalonFX 622 * reverse limit switch by passing in the CommonTalon object. When 623 * using RemoteTalonFX, the Talon FX will use the reverse limit switch 624 * attached to another Talon FX on the same CAN bus. 625 * 626 * @param device CommonTalon reference to use for RemoteTalonFX reverse limit 627 * switch 628 * @return Itself 629 */ 630 public final HardwareLimitSwitchConfigs withReverseLimitRemoteTalonFX(CommonTalon device) 631 { 632 ReverseLimitSource = ReverseLimitSourceValue.RemoteTalonFX; 633 ReverseLimitRemoteSensorID = device.getDeviceID(); 634 return this; 635 } 636 637 /** 638 * Helper method to configure this feedback group to use 639 * RemoteCANcoder reverse limit switch by passing in the CANcoder 640 * object. When using RemoteCANcoder, the Talon FX will use another 641 * CANcoder on the same CAN bus. The reverse limit will assert when 642 * the CANcoder magnet strength changes from BAD (red) to ADEQUATE 643 * (orange) or GOOD (green). 644 * 645 * @param device CANcoder reference to use for RemoteCANcoder reverse limit 646 * switch 647 * @return Itself 648 */ 649 public final HardwareLimitSwitchConfigs withReverseLimitRemoteCANcoder(CoreCANcoder device) 650 { 651 ReverseLimitSource = ReverseLimitSourceValue.RemoteCANcoder; 652 ReverseLimitRemoteSensorID = device.getDeviceID(); 653 return this; 654 } 655 656 /** 657 * Helper method to configure this feedback group to use the 658 * RemoteCANrange by passing in the CANrange object. The reverse limit 659 * will assert when the CANrange proximity detect is tripped. 660 * 661 * @param device CANrange reference to use for RemoteCANrange reverse limit 662 * switch 663 * @return Itself 664 */ 665 public final HardwareLimitSwitchConfigs withReverseLimitRemoteCANrange(CoreCANrange device) 666 { 667 ReverseLimitSource = ReverseLimitSourceValue.RemoteCANrange; 668 ReverseLimitRemoteSensorID = device.getDeviceID(); 669 return this; 670 } 671 672 /** 673 * Helper method to configure this feedback group to use RemoteCANdi 674 * reverse limit switch on Signal 1 Input (S1IN) by passing in the 675 * CANdi object. The reverse limit will assert when the CANdi™ branded 676 * device's Signal 1 Input (S1IN) pin matches the configured closed 677 * state. 678 * 679 * @param device CANdi reference to use for RemoteCANdi reverse limit switch 680 * @return Itself 681 */ 682 public final HardwareLimitSwitchConfigs withReverseLimitRemoteCANdiS1(CoreCANdi device) 683 { 684 ReverseLimitSource = ReverseLimitSourceValue.RemoteCANdiS1; 685 ReverseLimitRemoteSensorID = device.getDeviceID(); 686 return this; 687 } 688 689 /** 690 * Helper method to configure this feedback group to use RemoteCANdi 691 * reverse limit switch on Signal 2 Input (S2IN) by passing in the 692 * CANdi object. The reverse limit will assert when the CANdi™ branded 693 * device's Signal 2 Input (S2IN) pin matches the configured closed 694 * state. 695 * 696 * @param device CANdi reference to use for RemoteCANdi reverse limit switch 697 * @return Itself 698 */ 699 public final HardwareLimitSwitchConfigs withReverseLimitRemoteCANdiS2(CoreCANdi device) 700 { 701 ReverseLimitSource = ReverseLimitSourceValue.RemoteCANdiS2; 702 ReverseLimitRemoteSensorID = device.getDeviceID(); 703 return this; 704 } 705 706 707 708 @Override 709 public String toString() { 710 String ss = "Config Group: HardwareLimitSwitch\n"; 711 ss += " ForwardLimitType: " + ForwardLimitType + "\n"; 712 ss += " ForwardLimitAutosetPositionEnable: " + ForwardLimitAutosetPositionEnable + "\n"; 713 ss += " ForwardLimitAutosetPositionValue: " + ForwardLimitAutosetPositionValue + " rotations" + "\n"; 714 ss += " ForwardLimitEnable: " + ForwardLimitEnable + "\n"; 715 ss += " ForwardLimitSource: " + ForwardLimitSource + "\n"; 716 ss += " ForwardLimitRemoteSensorID: " + ForwardLimitRemoteSensorID + "\n"; 717 ss += " ReverseLimitType: " + ReverseLimitType + "\n"; 718 ss += " ReverseLimitAutosetPositionEnable: " + ReverseLimitAutosetPositionEnable + "\n"; 719 ss += " ReverseLimitAutosetPositionValue: " + ReverseLimitAutosetPositionValue + " rotations" + "\n"; 720 ss += " ReverseLimitEnable: " + ReverseLimitEnable + "\n"; 721 ss += " ReverseLimitSource: " + ReverseLimitSource + "\n"; 722 ss += " ReverseLimitRemoteSensorID: " + ReverseLimitRemoteSensorID + "\n"; 723 return ss; 724 } 725 726 /** 727 * Get the serialized form of this configuration group. 728 * 729 * @return Serialized form of this config group 730 */ 731 @Override 732 public final String serialize() { 733 String ss = ""; 734 ss += ConfigJNI.Serializeint(SpnValue.Config_ForwardLimitType.value, ForwardLimitType.value); 735 ss += ConfigJNI.Serializeboolean(SpnValue.Config_ForwardLimitAutosetPosEnable.value, ForwardLimitAutosetPositionEnable); 736 ss += ConfigJNI.Serializedouble(SpnValue.Config_ForwardLimitAutosetPosValue.value, ForwardLimitAutosetPositionValue); 737 ss += ConfigJNI.Serializeboolean(SpnValue.Config_ForwardLimitEnable.value, ForwardLimitEnable); 738 ss += ConfigJNI.Serializeint(SpnValue.Config_ForwardLimitSource.value, ForwardLimitSource.value); 739 ss += ConfigJNI.Serializeint(SpnValue.Config_ForwardLimitRemoteSensorID.value, ForwardLimitRemoteSensorID); 740 ss += ConfigJNI.Serializeint(SpnValue.Config_ReverseLimitType.value, ReverseLimitType.value); 741 ss += ConfigJNI.Serializeboolean(SpnValue.Config_ReverseLimitAutosetPosEnable.value, ReverseLimitAutosetPositionEnable); 742 ss += ConfigJNI.Serializedouble(SpnValue.Config_ReverseLimitAutosetPosValue.value, ReverseLimitAutosetPositionValue); 743 ss += ConfigJNI.Serializeboolean(SpnValue.Config_ReverseLimitEnable.value, ReverseLimitEnable); 744 ss += ConfigJNI.Serializeint(SpnValue.Config_ReverseLimitSource.value, ReverseLimitSource.value); 745 ss += ConfigJNI.Serializeint(SpnValue.Config_ReverseLimitRemoteSensorID.value, ReverseLimitRemoteSensorID); 746 return ss; 747 } 748 749 /** 750 * Take a string and deserialize it to this configuration group. 751 * 752 * @return Return code of the deserialize method 753 */ 754 @Override 755 public final StatusCode deserialize(String to_deserialize) { 756 ForwardLimitType = ForwardLimitTypeValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ForwardLimitType.value, to_deserialize)); 757 ForwardLimitAutosetPositionEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ForwardLimitAutosetPosEnable.value, to_deserialize); 758 ForwardLimitAutosetPositionValue = ConfigJNI.Deserializedouble(SpnValue.Config_ForwardLimitAutosetPosValue.value, to_deserialize); 759 ForwardLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ForwardLimitEnable.value, to_deserialize); 760 ForwardLimitSource = ForwardLimitSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ForwardLimitSource.value, to_deserialize)); 761 ForwardLimitRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_ForwardLimitRemoteSensorID.value, to_deserialize); 762 ReverseLimitType = ReverseLimitTypeValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ReverseLimitType.value, to_deserialize)); 763 ReverseLimitAutosetPositionEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ReverseLimitAutosetPosEnable.value, to_deserialize); 764 ReverseLimitAutosetPositionValue = ConfigJNI.Deserializedouble(SpnValue.Config_ReverseLimitAutosetPosValue.value, to_deserialize); 765 ReverseLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ReverseLimitEnable.value, to_deserialize); 766 ReverseLimitSource = ReverseLimitSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ReverseLimitSource.value, to_deserialize)); 767 ReverseLimitRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_ReverseLimitRemoteSensorID.value, to_deserialize); 768 return StatusCode.OK; 769 } 770 771 @Override 772 public HardwareLimitSwitchConfigs clone() { 773 try { 774 return (HardwareLimitSwitchConfigs)super.clone(); 775 } catch (CloneNotSupportedException ex) { 776 /* this should never happen */ 777 throw new RuntimeException(ex); 778 } 779 } 780} 781