Go Down

Topic: getting angle from encoder (Read 9098 times) previous topic - next topic

jhern

I want to convert he value from a rotary encoder to an angle value. I looked it up but couldn't find anything. Is there a way to do it?
One solution I think of is to turn the encoder 360 degrees, read the values, see how much it changes and use that as the basis for and angle.
(value read) / 360 would give me how much it changes for every angle.
then I can do angle = (value read/(total value for 360 degrees) * 360

MAS3

You'll always be guessing that way.
An encoder (2 out of phase switches) does not give you this information.
You need at least an extra reference signal, telling you you reached your zero or home position.
If you want an immediate angle readout without a need to go to some home position, look into "gray code".
That will give you an exact angle, but you will need more than 2 bits for that.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

KenF

The whole point of a rotary encoder is that it ISN'T position oriented.  If you want to have a control that's positional, use a potentiometer.  Encoders simply give you pulses to tell you that it's moving in one direction or the other.

polymorph

You must first start with finding out how many pulses per revolution your rotary encoder is. Then you need a Home position sensor and it has to find that first. Or is this a relative angle measure only?

Which rotary sensor? Website link?
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

raschemmel

Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

MarkT

There are 3 kinds of encoder the OP might be talking about:

incremental
incremental with index pulse,
absolute.

The first one can't do absolute position and only the last one can do absolute
position without a calibration action at start up.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Grumpy_Mike


jhern

Thank you for the replies. I have an incremental encoder. The project is that I have a gear attached to the encoder and meshed with another gear attached to a continuous rotation servo. I can turn the servo to a particular angle and know where it is, but if the servo gets turned manually I won't know the position and that's why I need the encoder.

michinyon

Encoders vary  in resolution.    Some have only 2 or 4 pulses per revolution,  which would be almost useless for estimating the angle.    Others have 100 or 200 or 1000 pulses per revolution,   which would be quite useful for estimating angle,   provided you had a means of identifying the reference or zero position.

MarkT

The whole point of a rotary encoder is that it ISN'T position oriented.  If you want to have a control that's positional, use a potentiometer.  Encoders simply give you pulses to tell you that it's moving in one direction or the other.
You seem to lack a knowledge of what a rotary encoder is.

Encoder means any one of a number of technologies for detecting position or change in position, here rotary position.

You can get analog encoders, digital encoders analog+digital encoders, incremental encoders, absolute encoders and
incremental encoders with index pulse.  Rotary and linear encoders both come in absolute,
incremental and incremental with index pulse forms.

An absolute encoder returns angle directly (many give you the turn count too, some are
accurate to millions of steps per revolution).  They can be expensive or extremely
expensive.

Incremental encoders are generally cheaper, but the ones which generate an index pulse
can be used as absolute position sensors once calibrated.

Incremental encoders require constant attention to maintain a position / angle value,
which often means interrupt handler is used to let that all work in the background.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

polymorph

Here are examples of several. The top row are relative encoders, only telling you how far it has moved. The second row (I don't know about the one bottom right) are absolute encoders. Grey code works better than binary, as only one bit changes at a time.



This can generate printable encoder wheels.

https://code.google.com/p/wheel-encoder-generator/

Here is one torn out of something:

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

raschemmel

Great link for the encoder wheel generator !
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

polymorph

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

qianyujiao

hi,recently i am doing a project similar to you. i have a optical rotary encoder from a printer.I want to read the angle from the encoder like you but have no idea.Did you fix the problem?

Southpark

#14
Nov 24, 2016, 08:00 pm Last Edit: Nov 24, 2016, 09:52 pm by Southpark
I want to convert he value from a rotary encoder to an angle value. I looked it up but couldn't find anything. Is there a way to do it?
One solution I think of is to turn the encoder 360 degrees, read the values, see how much it changes and use that as the basis for and angle.
(value read) / 360 would give me how much it changes for every angle.
then I can do angle = (value read/(total value for 360 degrees) * 360

I bought a few 10-bit 'absolute' rotary encoders (TRD-NA1024NW) from ebay ... which I had initially assumed to use 'common gray code', but unfortunately they used some unorthodox or unconventional gray code.

I ended up needing to measure (automatically) the 1024 consecutive gray code patterns to get the full set of patterns for the unconventional gray code (of this particular rotary encoder). But once all the patterns were obtained, there was the issue of how to 'quickly' translate any single pattern to an angle.

The reason why I ordered TRD-NA1024NW encoders was because I had assumed that they had typical gray code patterns. My rotary encoders that I ordered did not have typical patterns. But.... it doesn't mean to say that all TRD-NA1024NW encoders are like that. So I recently ordered 1 more (from a different source), but haven't yet tested it to see whether it has conventional gray code patterns.

There's a link to some discussion about my particular decoders at......click here....

Go Up