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