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 014/** 015 * Configs related to sensors used for differential control of a 016 * mechanism. 017 * <p> 018 * Includes the differential sensor sources and IDs. 019 */ 020public class DifferentialSensorsConfigs implements ParentConfiguration 021{ 022 /** 023 * Choose what sensor source is used for differential control of a 024 * mechanism. The default is Disabled. All other options require 025 * setting the DifferentialTalonFXSensorID, as the average of this 026 * Talon FX's sensor and the remote TalonFX's sensor is used for the 027 * differential controller's primary targets. 028 * <p> 029 * Choose RemoteTalonFX_Diff to use another TalonFX on the same CAN 030 * bus. Talon FX will update its differential position and velocity 031 * whenever the remote TalonFX publishes its information on CAN bus. 032 * The differential controller will use the difference between this 033 * TalonFX's sensor and the remote Talon FX's sensor for the 034 * differential component of the output. 035 * <p> 036 * Choose RemotePigeon2_Yaw, RemotePigeon2_Pitch, and 037 * RemotePigeon2_Roll to use another Pigeon2 on the same CAN bus (this 038 * also requires setting DifferentialRemoteSensorID). Talon FX will 039 * update its differential position to match the selected value 040 * whenever Pigeon2 publishes its information on CAN bus. Note that 041 * the Talon FX differential position will be in rotations and not 042 * degrees. 043 * <p> 044 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus 045 * (this also requires setting DifferentialRemoteSensorID). Talon FX 046 * will update its differential position and velocity to match the 047 * CANcoder whenever CANcoder publishes its information on CAN bus. 048 * 049 */ 050 public DifferentialSensorSourceValue DifferentialSensorSource = DifferentialSensorSourceValue.Disabled; 051 /** 052 * Device ID of which remote Talon FX to use. This is used when the 053 * Differential Sensor Source is not disabled. 054 * 055 * <ul> 056 * <li> <b>Minimum Value:</b> 0 057 * <li> <b>Maximum Value:</b> 62 058 * <li> <b>Default Value:</b> 0 059 * <li> <b>Units:</b> 060 * </ul> 061 */ 062 public int DifferentialTalonFXSensorID = 0; 063 /** 064 * Device ID of which remote sensor to use on the differential axis. 065 * This is used when the Differential Sensor Source is not 066 * RemoteTalonFX_Diff. 067 * 068 * <ul> 069 * <li> <b>Minimum Value:</b> 0 070 * <li> <b>Maximum Value:</b> 62 071 * <li> <b>Default Value:</b> 0 072 * <li> <b>Units:</b> 073 * </ul> 074 */ 075 public int DifferentialRemoteSensorID = 0; 076 077 /** 078 * Modifies this configuration's DifferentialSensorSource parameter and returns itself for 079 * method-chaining and easier to use config API. 080 * <p> 081 * Choose what sensor source is used for differential control of a 082 * mechanism. The default is Disabled. All other options require 083 * setting the DifferentialTalonFXSensorID, as the average of this 084 * Talon FX's sensor and the remote TalonFX's sensor is used for the 085 * differential controller's primary targets. 086 * <p> 087 * Choose RemoteTalonFX_Diff to use another TalonFX on the same CAN 088 * bus. Talon FX will update its differential position and velocity 089 * whenever the remote TalonFX publishes its information on CAN bus. 090 * The differential controller will use the difference between this 091 * TalonFX's sensor and the remote Talon FX's sensor for the 092 * differential component of the output. 093 * <p> 094 * Choose RemotePigeon2_Yaw, RemotePigeon2_Pitch, and 095 * RemotePigeon2_Roll to use another Pigeon2 on the same CAN bus (this 096 * also requires setting DifferentialRemoteSensorID). Talon FX will 097 * update its differential position to match the selected value 098 * whenever Pigeon2 publishes its information on CAN bus. Note that 099 * the Talon FX differential position will be in rotations and not 100 * degrees. 101 * <p> 102 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus 103 * (this also requires setting DifferentialRemoteSensorID). Talon FX 104 * will update its differential position and velocity to match the 105 * CANcoder whenever CANcoder publishes its information on CAN bus. 106 * 107 * 108 * @param newDifferentialSensorSource Parameter to modify 109 * @return Itself 110 */ 111 public DifferentialSensorsConfigs withDifferentialSensorSource(DifferentialSensorSourceValue newDifferentialSensorSource) 112 { 113 DifferentialSensorSource = newDifferentialSensorSource; 114 return this; 115 } 116 /** 117 * Modifies this configuration's DifferentialTalonFXSensorID parameter and returns itself for 118 * method-chaining and easier to use config API. 119 * <p> 120 * Device ID of which remote Talon FX to use. This is used when the 121 * Differential Sensor Source is not disabled. 122 * 123 * <ul> 124 * <li> <b>Minimum Value:</b> 0 125 * <li> <b>Maximum Value:</b> 62 126 * <li> <b>Default Value:</b> 0 127 * <li> <b>Units:</b> 128 * </ul> 129 * 130 * @param newDifferentialTalonFXSensorID Parameter to modify 131 * @return Itself 132 */ 133 public DifferentialSensorsConfigs withDifferentialTalonFXSensorID(int newDifferentialTalonFXSensorID) 134 { 135 DifferentialTalonFXSensorID = newDifferentialTalonFXSensorID; 136 return this; 137 } 138 /** 139 * Modifies this configuration's DifferentialRemoteSensorID parameter and returns itself for 140 * method-chaining and easier to use config API. 141 * <p> 142 * Device ID of which remote sensor to use on the differential axis. 143 * This is used when the Differential Sensor Source is not 144 * RemoteTalonFX_Diff. 145 * 146 * <ul> 147 * <li> <b>Minimum Value:</b> 0 148 * <li> <b>Maximum Value:</b> 62 149 * <li> <b>Default Value:</b> 0 150 * <li> <b>Units:</b> 151 * </ul> 152 * 153 * @param newDifferentialRemoteSensorID Parameter to modify 154 * @return Itself 155 */ 156 public DifferentialSensorsConfigs withDifferentialRemoteSensorID(int newDifferentialRemoteSensorID) 157 { 158 DifferentialRemoteSensorID = newDifferentialRemoteSensorID; 159 return this; 160 } 161 162 163 164 @Override 165 public String toString() 166 { 167 String ss = "Config Group: DifferentialSensors\n"; 168 ss += "Name: \"DifferentialSensorSource\" Value: \"" + DifferentialSensorSource + "\"" + "\n"; 169 ss += "Name: \"DifferentialTalonFXSensorID\" Value: \"" + DifferentialTalonFXSensorID + "\"" + "\n"; 170 ss += "Name: \"DifferentialRemoteSensorID\" Value: \"" + DifferentialRemoteSensorID + "\"" + "\n"; 171 return ss; 172 } 173 174 /** 175 * 176 */ 177 public StatusCode deserialize(String to_deserialize) 178 { 179 DifferentialSensorSource = DifferentialSensorSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_DifferentialSensorSource.value, to_deserialize)); 180 DifferentialTalonFXSensorID = ConfigJNI.Deserializeint(SpnValue.Config_DifferentialTalonFXSensorID.value, to_deserialize); 181 DifferentialRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_DifferentialRemoteSensorID.value, to_deserialize); 182 return StatusCode.OK; 183 } 184 185 /** 186 * 187 */ 188 public String serialize() 189 { 190 String ss = ""; 191 ss += ConfigJNI.Serializeint(SpnValue.Config_DifferentialSensorSource.value, DifferentialSensorSource.value); 192 ss += ConfigJNI.Serializeint(SpnValue.Config_DifferentialTalonFXSensorID.value, DifferentialTalonFXSensorID); 193 ss += ConfigJNI.Serializeint(SpnValue.Config_DifferentialRemoteSensorID.value, DifferentialRemoteSensorID); 194 return ss; 195 } 196} 197