Help reading encoders values

Thread Starter

TomasBernardo

Joined Mar 25, 2017
3
Hello,

We have a lab project, wich is a line following robot. We are with problems understanding the encoder's values.
When the encoder turns 5 degrees in one direction the reading is 86. When it turns 5 degrees in the other direction the reading is 16777131.
What is the reason for this?


Thank you
 

AlbertHall

Joined Jun 4, 2014
12,347
Because you are using a 24 bit bit absolute position encoder - my crystal ball tells me.
What encoder are you actually using?

2^24 = 16777216
Your two readings added together = 16777217. Much too close to be a coincidence.

[EDIT] But no, that's not right 'cos then 5° would give you a lot more than 86, so it's more likely a maths overflow in the software.

The question remains: what encoder are you using?
 

Thread Starter

TomasBernardo

Joined Mar 25, 2017
3
Thank you for your answer.
I do not know... We are not given the specs of the components.

Forget what I wrote about the 5 degrees. It was wrong.
Let me try to do a better description of the setup:
We have two motors, to whom we send 8-bit signals. Value 128 means that the motor is stopped.
When we give each wheel the value 133, the encoder reading is 86(on each wheel).
And when we give each wheel the value 144, the encoder reading is 298.
But when we give the value 123, the reading is 16777131.

I am sorry for not being able to do a better description. I am quite lost on this field of sensors and controllers.
 

AlbertHall

Joined Jun 4, 2014
12,347
OK. I take it that when sending 128 to the motors the encoder reads zero.
Then when sending values greater than 128 the encoder reads increasing positive values.
So, logically, when sending less than 128 to the motors the encoder should give increasing negative values.
144 gives 298
133 gives 86
128 gives 0
123 should give -86
112 should give -298

Now computers often do negative numbers using 2's complement. This is created by taking the binary representation of the positive number and flipping all the digits then adding 1.
86 base 10 in binary is 1010110 and if we extend this to 24 bits we get 000000000000000001010110
Convert to 2's complement, first invert all digits: 111111111111111110101001
Then add 1: 111111111111111110101010
Converting that to decimal gives 16777130 which is (almost) what you do get when sending 123 to the motors.
So your encoder is giving positive numbers for motor values greater than 128 and negative numbers for values less than 128.
They just don't look like negative numbers.

http://www.exploringbinary.com/twos-complement-converter/
 

Thread Starter

TomasBernardo

Joined Mar 25, 2017
3
I didn't know nothing about this.
Thank you very much for the patience to help me. Now I must go study this 2's complement and the decimal conversion.

Thank you AlbertHall
 
Top