Possible Encoder Talon Code - MDHSRobotics/TeamWiki GitHub Wiki
###US DIGITAL E4T-360-250 ENCODER IS AN INCREMENTAL ENCODER
- encoder enc;
- enc = new Encoder(0, 1, false, Encoder.EncodingType.k4X);
- Encoder sampleEncoder = new Encoder(0, 1, false, Encoder.EncodingType.k4X);
- sampleEncoder.setMaxPeriod(.1);
- sampleEncoder.setMinRate(10);
- sampleEncoder.setDistancePerPulse(5);
- sampleEncoder.setReverseDirection(true);
- sampleEncoder.setSamplesToAverage(7);
- Encoder sampleEncoder = new Encoder(0, 1, false, Encoder.EncodingType.k4X);
- sampleEncoder.reset();
- Encoder sampleEncoder = new Encoder(0, 1, false, Encoder.EncodingType.k4X);
- int count = sampleEncoder.get();
- double distance = sampleEncoder.getRaw();
- double distance = sampleEncoder.getDistance();
- double period = sampleEncoder.getPeriod();
- double rate = sampleEncoder.getRate();
- boolean direction = sampleEncoder.getDirection();
- boolean stopped = sampleEncoder.getStopped();
##How to Analog the Code (only for Absolute Encoders)
- AnalogInput ai;
- ai = new AnalogInput(0);
- AnalogInput exampleAnalog = new AnalogInput(0);
- int bits;
- exampleAnalog.setOversampleBits(4);
- bits = exampleAnalog.getOversampleBits();
- exampleAnalog.setAverageBits(2);
- bits = exampleAnalog.getAverageBits();
- AnalogInput.setGlobalSampleRate(62500);
- AnalogInput exampleAnalog = new AnalogInput(0);
- int raw = exampleAnalog.getValue();
- double volts = exampleAnalog.getVoltage();
- int averageRaw = exampleAnalog.getAverageValue();
- ouble averageVolts = exampleAnalog.getAverageVoltage();
- AnalogInput exampleAnalog = new AnalogInput(0);
- exampleAnalog.setAccumulatorInitialValue(0);
- exampleAnalog.setAccumulatorCenter(2048);
- exampleAnalog.setAccumulatorDeadband(10);
- exampleAnalog.resetAccumulator();
- AnalogInput exampleAnalog = new AnalogInput(0);
- long count = exampleAnalog.getAccumulatorCount();
- long value = exampleAnalog.getAccumulatorValue();
- AccumulatorResult result = new AccumulatorResult();
- exampleAnalog.getAccumulatorOutput(result);
- count = result.count;
- value = result.value;
##Terms and WhatNot
- Max Period - The maximum period (in seconds) where the device is still considered moving. This value is used to determine the state of the getStopped() method and effect the output of the getPeriod() and getRate() methods. This is the time between pulses on an individual channel (scale factor is accounted for). It is recommended to use the Min Rate parameter instead as it accounts for the distance per pulse, allowing you to set the rate in engineering units.
- Min Rate - Sets the minimum rate before the device is considered stopped. This compensates for both scale factor and distance per pulse and therefore should be entered in engineering units (RPM, RPS, Degrees/sec, In/s, etc)
- Distance Per Pulse - Sets the scale factor between pulses and distance. The library already accounts for the decoding scale factor (1x, 2x, 4x) separately so this value should be set exclusively based on the encoder's Pulses per Revolution and any gearing following the encoder.
- Reverse Direction - Sets the direction the encoder counts, used to flip the direction if the encoder mounting makes the default counting direction unintuitive.
- Samples to Average - Sets the number of samples to average when determining the period. Averaging may be desired to account for mechanical imperfections (such as unevenly spaced reflectors when using a reflective sensor as an encoder) or as oversampling to increase resolution. Valid values are 1 to 127 samples.
- Count - The current count. May be reset by calling reset().
- Raw Count - The count without compensation for decoding scale factor.
- Distance - The current distance reading from the counter. This is the count multiplied by the Distance Per Count scale factor.
- Period - The current period of the counter in seconds. If the counter is stopped this value may return 0. This is deprecated, it is recommended to use rate instead.
- Rate - The current rate of the counter in units/sec. It is calculated using the DistancePerPulse divided by the period. If the counter is stopped this value may return Inf or NaN, depending on language.
- Direction - The direction of the last value change (true for Up, false for Down)
- Stopped - If the counter is currently stopped (period has exceeded Max Period)