001/* 002 * Copyright (c) 2019-2021 REV Robotics 003 * 004 * Redistribution and use in source and binary forms, with or without 005 * modification, are permitted provided that the following conditions are met: 006 * 007 * 1. Redistributions of source code must retain the above copyright notice, 008 * this list of conditions and the following disclaimer. 009 * 2. Redistributions in binary form must reproduce the above copyright 010 * notice, this list of conditions and the following disclaimer in the 011 * documentation and/or other materials provided with the distribution. 012 * 3. Neither the name of REV Robotics nor the names of its 013 * contributors may be used to endorse or promote products derived from 014 * this software without specific prior written permission. 015 * 016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 017 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 019 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 020 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 021 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 022 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 023 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 024 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 025 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 026 * POSSIBILITY OF SUCH DAMAGE. 027 */ 028 029package com.revrobotics; 030 031/** @deprecated use {@link RelativeEncoder} instead. */ 032@Deprecated(forRemoval = true) 033public interface CANEncoder extends MotorFeedbackSensor { 034 /** 035 * Get the position of the motor. This returns the native units of 'rotations' by default, and can 036 * be changed by a scale factor using setPositionConversionFactor(). 037 * 038 * @return Number of rotations of the motor 039 */ 040 double getPosition(); 041 042 /** 043 * Get the velocity of the motor. This returns the native units of 'RPM' by default, and can be 044 * changed by a scale factor using setVelocityConversionFactor(). 045 * 046 * @return Number the RPM of the motor 047 */ 048 double getVelocity(); 049 050 /** 051 * Set the position of the encoder. By default the units are 'rotations' and can be changed by a 052 * scale factor using setPositionConversionFactor(). 053 * 054 * @param position Number of rotations of the motor 055 * @return {@link REVLibError#kOk} if successful 056 */ 057 REVLibError setPosition(double position); 058 059 /** 060 * Set the conversion factor for position of the encoder. Multiplied by the native output units to 061 * give you position. 062 * 063 * @param factor The conversion factor to multiply the native units by 064 * @return {@link REVLibError#kOk} if successful 065 */ 066 REVLibError setPositionConversionFactor(double factor); 067 068 /** 069 * Set the conversion factor for velocity of the encoder. Multiplied by the native output units to 070 * give you velocity 071 * 072 * @param factor The conversion factor to multiply the native units by 073 * @return {@link REVLibError#kOk} if successful 074 */ 075 REVLibError setVelocityConversionFactor(double factor); 076 077 /** 078 * Get the conversion factor for position of the encoder. Multiplied by the native output units to 079 * give you position 080 * 081 * @return The conversion factor for position 082 */ 083 double getPositionConversionFactor(); 084 085 /** 086 * Get the conversion factor for velocity of the encoder. Multiplied by the native output units to 087 * give you velocity 088 * 089 * @return The conversion factor for velocity 090 */ 091 double getVelocityConversionFactor(); 092 093 /** 094 * Set the average sampling depth for a quadrature encoder. This value sets the number of samples 095 * in the average for velocity readings. This can be any value from 1 to 64. 096 * 097 * <p>When the SparkMax controller is in Brushless mode, this will not change any behavior. 098 * 099 * @param depth The average sampling depth between 1 and 64 (default) 100 * @return {@link REVLibError#kOk} if successful 101 */ 102 REVLibError setAverageDepth(int depth); 103 104 /** 105 * Get the average sampling depth for a quadrature encoder. 106 * 107 * @return The average sampling depth 108 */ 109 int getAverageDepth(); 110 111 /** 112 * Set the measurement period for velocity measurements of a quadrature encoder. When the SparkMax 113 * controller is in Brushless mode, this will not change any behavior. 114 * 115 * <p>The basic formula to calculate velocity is change in position / change in time. This 116 * parameter sets the change in time for measurement. 117 * 118 * @param period_us Measurement period in milliseconds. This number may be between 1 and 100 119 * (default). 120 * @return {@link REVLibError#kOk} if successful 121 */ 122 REVLibError setMeasurementPeriod(int period_us); 123 124 /** 125 * Get the number of samples for reading from a quadrature encoder. 126 * 127 * @return Number of samples 128 */ 129 int getMeasurementPeriod(); 130 131 /** 132 * Get the counts per revolution of the quadrature encoder. 133 * 134 * <p>For a description on the difference between CPR, PPR, etc. go to 135 * https://www.cuidevices.com/blog/what-is-encoder-ppr-cpr-and-lpr 136 * 137 * @return Counts per revolution 138 */ 139 int getCountsPerRevolution(); 140 141 REVLibError setInverted(boolean inverted); 142 143 boolean getInverted(); 144}