001package com.ctre.phoenix.motorcontrol; 002 003import com.ctre.phoenix.ErrorCode; 004import com.ctre.phoenix.motorcontrol.can.BaseTalon; 005import com.ctre.phoenix.motorcontrol.can.MotControllerJNI; 006 007/** 008 * Collection of sensors available to the Talon FX. 009 * <p> 010 * For best performance and update-rate, we recommend using the 011 * configSelectedFeedbackSensor() and getSelectedSensor*() routines. However 012 * there are occasions where accessing raw sensor values may be useful or 013 * convenient. Particularly if you are seeding one sensor based on another, or 014 * need to circumvent sensor-phase. 015 * <p> 016 * Use the getTalonFXSensorCollection() routine inside your motor controller to create 017 * a sensor collection. 018 */ 019public class TalonFXSensorCollection { 020 private long _handle; 021 022 /** 023 * Constructor for SensorCollection 024 * 025 * @param motorController Motor Controller to connect Collection to 026 */ 027 public TalonFXSensorCollection(BaseTalon motorController) { 028 _handle = motorController.getHandle(); 029 } 030 031 /** 032 * Get the IntegratedSensor position of the Talon FX, regardless of whether 033 * it is actually being used for feedback. The units are 2048 per rotation. 034 * Note : Future versions of software may support scaling features (rotations, radians, degrees, etc) depending on the configuration. 035 * <p> 036 * This method relies on the Status 21 message, which has a default period of 240ms. For more 037 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html 038 * 039 * @return the IntegratedSensor position. 040 */ 041 public double getIntegratedSensorPosition() { 042 return MotControllerJNI.GetIntegratedSensorPosition(_handle); 043 } 044 045 /** 046 * Get the IntegratedSensor absolute position of the Talon FX, regardless of whether 047 * it is actually being used for feedback. This will be within one rotation (2048 units). 048 * The signage and range will depend on the configuration. 049 * Note : Future versions of software may support scaling features (rotations, radians, degrees, etc) depending on the configuration. 050 * <p> 051 * This method relies on the Status 21 message, which has a default period of 240ms. For more 052 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html 053 * 054 * @return the IntegratedSensor absolute position. 055 */ 056 public double getIntegratedSensorAbsolutePosition() { 057 return MotControllerJNI.GetIntegratedSensorAbsolutePosition(_handle); 058 } 059 060 /** 061 * Get the IntegratedSensor velocity of the Talon FX, regardless of whether 062 * it is actually being used for feedback. 063 * One unit represents one position unit per 100ms (2048 position units per 100ms). 064 * The signage and range will depend on the configuration. 065 * Note : Future versions of software may support scaling features (rotations, radians, degrees, etc) depending on the configuration. 066 * <p> 067 * This method relies on the Status 21 message, which has a default period of 240ms. For more 068 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html 069 * 070 * @return the IntegratedSensor velocity. 071 */ 072 public double getIntegratedSensorVelocity() { 073 return MotControllerJNI.GetIntegratedSensorVelocity(_handle); 074 } 075 076 /** 077 * Set the IntegratedSensor reported position. Typically this is used to "zero" the 078 * sensor. This only works with IntegratedSensor. To set the selected sensor position 079 * regardless of what type it is, see SetSelectedSensorPosition in the motor controller class. 080 * 081 * @param newPosition The position value to apply to the sensor. 082 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for 083 * config success and report an error if it times out. 084 * If zero, no blocking or checking is performed. 085 * @return error code. 086 */ 087 public ErrorCode setIntegratedSensorPosition(double newPosition, 088 int timeoutMs) { 089 return ErrorCode.valueOf(MotControllerJNI.SetIntegratedSensorPosition(_handle, newPosition, timeoutMs)); 090 } 091 092 /** 093 * Set the IntegratedSensor reported position based on the absolute position. 094 * This can also be done automatically on power boot depending on configuration. 095 * 096 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for 097 * config success and report an error if it times out. 098 * If zero, no blocking or checking is performed. 099 * @return error code. 100 */ 101 public ErrorCode setIntegratedSensorPositionToAbsolute(int timeoutMs) { 102 return ErrorCode.valueOf(MotControllerJNI.SetIntegratedSensorPositionToAbsolute(_handle, timeoutMs)); 103 } 104 105 /** 106 * Is forward limit switch closed. 107 * <p> 108 * This method relies on the Status 1 message, which has a default period of 10ms. For more 109 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html 110 * 111 * @return '1' iff forward limit switch is closed, 0 iff switch is open. This function works 112 * regardless if limit switch feature is enabled. Remote limit features do not impact this routine. 113 */ 114 public int isFwdLimitSwitchClosed() { 115 return MotControllerJNI.IsFwdLimitSwitchClosed(_handle); 116 } 117 118 /** 119 * Is reverse limit switch closed. 120 * <p> 121 * This method relies on the Status 1 message, which has a default period of 10ms. For more 122 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html 123 * 124 * @return '1' iff reverse limit switch is closed, 0 iff switch is open. This function works 125 * regardless if limit switch feature is enabled. Remote limit features do not impact this routine. 126 */ 127 public int isRevLimitSwitchClosed() { 128 return MotControllerJNI.IsRevLimitSwitchClosed(_handle); 129 } 130}