# What does the absolute encoder do?

Hey guys, for programming, I am asked to find the absolute encoder offset. What is the absolute encoder, and why is there an offset? Can someone please explain this to me in relatively noob terms?

I strongly recommend you read the WPIlib documentation for hardware and software encoders

An absolute encoder is a an encoder that gives an angle measurement that is preserved throughout power cycles.

Absolute encoder offset is the distance between the zero of the mechanism and the zero of the encoder reading.

To find it set the mechanismâ€™s position to â€śzeroâ€ť and read from the encoder.

3 Likes

Do you mind explaining what the â€śzeroâ€ť is?

For swerve drive, your â€śzeroâ€ť position would likely be when the wheel is facing forwards

2 Likes

The absolute encoder measures angle, usually 0-360 degrees. Unlike a relative sensor, which says 0 is wherever it is when the robot turns on, an absolute encoder will return a consistent angle between robot restarts. This is good since you donâ€™t always have to make sure your mechanism is in its proper starting spot before the turning on, but it also means you canâ€™t choose what direction the mechanism is pointing when the sensor says itâ€™s at 0 degrees.

The absolute encoder offset is whatever the sensor reports the angle at when your mechanism is pointing in whatever direction you want to be 0 degrees. You can then subtract that number from the sensor to get a measurement that lines up with the real world.

2 Likes

The â€śzeroâ€ť is whatever location youâ€™ve modeled/chosen to be zero. The encoder reading will likely be different, but it will be consistent. So all you need to do is move your mechanism to your zero location, and read the encoder value at that point. From there, you can use that offset to transform the encoder angle into your modelâ€™s system.

2 Likes

Thanks! Wait so if the absolute encoder measures angle, then what does a normal encoder measure? I noticed on the WPILib docs that there is a function `encoder.getDistance();`. I am slightly confused.

I believe @Knufire mentioned that the difference between an absolute encoder and â€śnormalâ€ť relative encoder is where the encoder zero is on startup. While an absolute encoder maintains a constant zero for as long as itâ€™s installed, a regular encoder sets its zero to whatever the position it is in when itâ€™s powered on.

This is usually fine when you only need speed control (ie. shooter flywheels, propulsion drive wheels), but if you need position control, a relative encoder would need some extra work to be consistent (ie. always start in same position, limit switch on mechanism).

2 Likes

encoder.getDistance(); returns the total distance traveled for a relative encoder.

1 Like

oh wait is that angular distance or like distance traveled on the ground or something?

It is angular distance. You can use some math to convert it to distance traveled on the ground (for a wheel)

2 Likes

it appears that you can use `setDistancePerPulse(double)` to set a scalar for each pulse to be multiplied by when running `getDistance()`. For example, if your encoder has 100 ticks per rotation,

``````encoder.setDistancePerPulse(360/100);
encoder.getDistance();
``````

would give you the angle in degrees. But you can really do whatever you want with this. If you have a 10:1 gearbox after your encoder running into a rack and pinion with a 0.75 inch diameter spur gear, then

``````encoder.setDistancePerPulse((2*pi/100)/10*(0.75/2));
encoder.getDistance();
``````

will give you the distance from zero that your rack has travelled in inches.

2 Likes

What is a pulse and what is a tick?

Inside a relative encoder, there is a multicolored disk (think wheel of fortune without the spokes and clicker, colored used very loosely) which spins with the moving shaft. There is a magnetic or laser reader on one part of the disk, and every time it crosses from one â€ścolorâ€ť to another, it sends a signal to increment/decrement the encoder angle. Both â€śtickâ€ť and â€śpulseâ€ť refer to this signal and/or the color change which generates it. (There is some slight distinction in their usage, but they are basically interchangable.) Iâ€™m not familiar with the inner workings of an absolute encoder, but I assume they work on the same principle.

The â€ś100 ticks per rotationâ€ť number is a measure of the resolution (ie. precision) of the sensor, and it physically represents the number of pulses sent and detected when a shaft attached to the encoder makes 1 full revolution. Conversely, this means the smallest angle your encoder can measure is 1/100 of a rotation, or 3.6 degrees.

The resolution of your encoder should be listed on the specification sheet, although it may be in different units (ticks/revolution, degrees/tick, etc.). The spec sheet should be available anywhere you can buy the encoder online.

2 Likes

ohhhh ok got it thank you so much!