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.phoenixpro.configs; 008 009import com.ctre.phoenixpro.StatusCode; 010import com.ctre.phoenixpro.configs.jni.ConfigJNI; 011import com.ctre.phoenixpro.spns.*; 012import com.ctre.phoenixpro.signals.*; 013 014/** 015 * Configs that directly affect motor-output. 016 * <p> 017 * Includes Motor Invert and various limit features. 018 */ 019public class FeedbackConfigs implements ParentConfiguration 020{ 021 /** 022 * This offset is applied to the absolute integrated rotor sensor. 023 * This can be used to zero the rotor in applications that are within 024 * one rotor rotation. 025 * 026 * <ul> 027 * <li> <b>Minimum Value:</b> -1 028 * <li> <b>Maximum Value:</b> 1 029 * <li> <b>Default Value:</b> 0.0 030 * <li> <b>Units:</b> rotations 031 * </ul> 032 */ 033 public double FeedbackRotorOffset = 0.0; 034 /** 035 * This is the ratio of sensor rotations to the mechanism's output. 036 * This is equivalent to the mechanism's gear ratio if the sensor is 037 * located on the input of a gearbox. If sensor is on the output of a 038 * gearbox, then this is typically set to 1. Note if this is set to 039 * zero, device will reset back to one. 040 * 041 * <ul> 042 * <li> <b>Minimum Value:</b> -1000 043 * <li> <b>Maximum Value:</b> 1000 044 * <li> <b>Default Value:</b> 1.0 045 * <li> <b>Units:</b> scalar 046 * </ul> 047 */ 048 public double SensorToMechanismRatio = 1.0; 049 /** 050 * Talon FX is capable of fusing a remote CANcoder with its rotor 051 * sensor to produce a high-bandwidth sensor source. This feature 052 * requires specifying the ratio between the remote sensor and the 053 * motor rotor. Note if this is set to zero, device will reset back 054 * to one. 055 * 056 * <ul> 057 * <li> <b>Minimum Value:</b> -1000 058 * <li> <b>Maximum Value:</b> 1000 059 * <li> <b>Default Value:</b> 1.0 060 * <li> <b>Units:</b> scalar 061 * </ul> 062 */ 063 public double RotorToSensorRatio = 1.0; 064 /** 065 * Choose what sensor source is reported via API and used by 066 * closed-loop and limit features. The default is RotorSensor, which 067 * uses the internal rotor sensor in the Talon FX. Choose 068 * RemoteCANcoder to use another CANcoder on the same CAN bus (this 069 * also requires setting FeedbackRemoteSensorID). Talon FX will 070 * update its position and velocity whenever CANcoder publishes its 071 * information on CAN bus. Choose FusedCANcoder and Talon FX will 072 * fuse another CANcoder's information with the internal rotor, which 073 * provides the best possible position and velocity for accuracy and 074 * bandwidth (note this requires setting FeedbackRemoteSensorID). 075 * FusedCANcoder was developed for applications such as 076 * swerve-azimuth. 077 * <p> 078 * Note: When the Talon Source is changed to FusedCANcoder, the Talon 079 * needs a period of time to fuse before sensor-based (soft-limit, 080 * closed loop, etc.) features are used. This period of time is 081 * determined by the update frequency of the CANcoder's Position 082 * signal. 083 * 084 */ 085 public FeedbackSensorSourceValue FeedbackSensorSource = FeedbackSensorSourceValue.RotorSensor; 086 /** 087 * Device ID of which remote device to use. This is not used if the 088 * Sensor Source is the internal rotor sensor. 089 * 090 * <ul> 091 * <li> <b>Minimum Value:</b> 0 092 * <li> <b>Maximum Value:</b> 62 093 * <li> <b>Default Value:</b> 0 094 * <li> <b>Units:</b> 095 * </ul> 096 */ 097 public int FeedbackRemoteSensorID = 0; 098 099 @Override 100 public String toString() 101 { 102 String ss = "Config Group: Feedback\n"; 103 ss += "Name: \"FeedbackRotorOffset\" Value: \"" + FeedbackRotorOffset + "rotations\"" + "\n"; 104 ss += "Name: \"SensorToMechanismRatio\" Value: \"" + SensorToMechanismRatio + "scalar\"" + "\n"; 105 ss += "Name: \"RotorToSensorRatio\" Value: \"" + RotorToSensorRatio + "scalar\"" + "\n"; 106 ss += "Name: \"FeedbackSensorSource\" Value: \"" + FeedbackSensorSource + "\"" + "\n"; 107 ss += "Name: \"FeedbackRemoteSensorID\" Value: \"" + FeedbackRemoteSensorID + "\"" + "\n"; 108 return ss; 109 } 110 111 /** 112 * 113 */ 114 public StatusCode deserialize(String string) 115 { 116 FeedbackRotorOffset = ConfigJNI.Deserializedouble(SpnValue.Config_FeedbackRotorOffset.value, string); 117 SensorToMechanismRatio = ConfigJNI.Deserializedouble(SpnValue.Config_SensorToMechanismRatio.value, string); 118 RotorToSensorRatio = ConfigJNI.Deserializedouble(SpnValue.Config_RotorToSensorRatio.value, string); 119 FeedbackSensorSource = FeedbackSensorSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_FeedbackSensorSource.value, string)); 120 FeedbackRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_FeedbackRemoteSensorID.value, string); 121 return StatusCode.OK; 122 } 123 124 /** 125 * 126 */ 127 public String serialize() 128 { 129 String ss = ""; 130 ss += ConfigJNI.Serializedouble(1438, FeedbackRotorOffset); 131 ss += ConfigJNI.Serializedouble(1439, SensorToMechanismRatio); 132 ss += ConfigJNI.Serializedouble(1440, RotorToSensorRatio); 133 ss += ConfigJNI.Serializeint(1441, FeedbackSensorSource.value); 134 ss += ConfigJNI.Serializeint(1442, FeedbackRemoteSensorID); 135 return ss; 136 } 137} 138