001/* Copyright (C) Cross The Road Electronics 2024 */ 002package com.ctre.phoenix.sensors; 003 004import com.ctre.phoenix.CustomParamConfiguration; 005 006/** 007 * Configurables available to CANCoder 008 * 009 * @deprecated This device's Phoenix 5 API is deprecated for removal in the 010 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the 011 * Phoenix 6 API. A migration guide is available at 012 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html. 013 * <p> 014 * If the Phoenix 5 API must be used for this device, the device must have 22.X 015 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in 016 * the firmware year dropdown. 017 */ 018@Deprecated(since = "2024", forRemoval = true) 019public class CANCoderConfiguration extends CustomParamConfiguration { 020 /** 021 * Velocity measurement period to use 022 */ 023 public SensorVelocityMeasPeriod velocityMeasurementPeriod = SensorVelocityMeasPeriod.Period_100Ms; 024 /** 025 * Velocity measurement window to use 026 */ 027 public int velocityMeasurementWindow = 64; 028 029 /** 030 * Desired Sign / Range for the absolute position register. 031 * Choose unsigned for an absolute range of[0, +1) rotations, [0, 360) deg, etc. 032 * Choose signed for an absolute range of[-0.5, +0.5) rotations, [-180, +180) deg, etc. 033 */ 034 public AbsoluteSensorRange absoluteSensorRange = AbsoluteSensorRange.Unsigned_0_to_360; 035 /** 036 * Adjusts the zero point for the absolute position register. 037 * The absolute position of the sensor will always have a discontinuity (360 -> 0 deg) or (+180 -> -180) 038 * and a hard-limited mechanism may have such a discontinuity in its functional range. 039 * In which case use this config to move the discontinuity outside of the function range. 040 */ 041 public double magnetOffsetDegrees = 0; 042 /** 043 * Choose which direction is interpreted as positive displacement. 044 * This affects both "Position"and "Absolute Position". 045 * False(default) means positive rotation occurs when magnet 046 * is spun counter - clockwise when observer is facing the LED side of CANCoder. 047 */ 048 public boolean sensorDirection = false; 049 /** 050 * The sensor initialization strategy to use.This will impact the behavior the next time CANCoder boots up. 051 * 052 * Pick the strategy on how to initialize the CANCoder's "Position" register. Depending on the mechanism, 053 * it may be desirable to auto set the Position register to match the Absolute Position(swerve for example). 054 * Or it may be desired to zero the sensor on boot(drivetrain translation sensor or a relative servo). 055 * 056 * TIP: Tuner's self-test feature will report what the boot sensor value will be in the event the CANCoder is reset. 057 */ 058 public SensorInitializationStrategy initializationStrategy = SensorInitializationStrategy.BootToZero; 059 /** 060 * Scalar to multiply the CANCoder's native 12-bit resolute sensor. Defaults to 0.087890625 to produce degrees. 061 */ 062 public double sensorCoefficient = 360.0 / 4096.0; 063 /** 064 * String holding the unit to report in. This impacts all routines(except for ConfigMagnetOffset) and the self-test in Tuner. 065 * The string value itself is arbitrary.The max number of letters will depend on firmware versioning, but generally CANCoder 066 * supports up to eight letters.However, common units such as "centimeters" are supported explicitly despite exceeding the eight-letter limit. 067 * Default is "deg" 068 */ 069 public String unitString = "deg"; 070 /** 071 * Desired denominator to report velocity in. This impacts GetVelocityand the reported velocity in self-test in Tuner. 072 * Default is "Per Second". 073 */ 074 public SensorTimeBase sensorTimeBase = SensorTimeBase.PerSecond; 075 076 public CANCoderConfiguration() { } 077 078 /** 079 * @return String representation of configs 080 */ 081 public String toString() { 082 return toString(""); 083 } 084 085 /** 086 * @param prependString 087 * String to prepend to configs 088 * @return String representation of configs 089 */ 090 public String toString(String prependString) { 091 String retstr = prependString + ".velocityMeasurementPeriod = " + velocityMeasurementPeriod.toString() + ";\n"; 092 retstr += prependString + ".velocityMeasurementWindow = " + String.valueOf(velocityMeasurementWindow) + ";\n"; 093 094 retstr += prependString + ".absoluteSensorRange = " + absoluteSensorRange.toString() + ";\n"; 095 retstr += prependString + ".magnetOffsetDegrees = " + magnetOffsetDegrees + ";\n"; 096 retstr += prependString + ".sensorDirection = " + sensorDirection + ";\n"; 097 retstr += prependString + ".initializationStrategy = " + initializationStrategy.toString() + ";\n"; 098 retstr += prependString + ".sensorCoefficient = " + sensorCoefficient + ";\n"; 099 retstr += prependString + ".unitString = \"" + unitString.toString() + "\";\n"; 100 retstr += prependString + ".sensorTimeBase = " + sensorTimeBase.toString() + ";\n"; 101 retstr += super.toString(prependString); 102 103 return retstr; 104 } 105}