Roboclaw - I can't reset the encoders when in absolute mode

Hello folks,

I have a problem trying to drive a couple of “75:1 Metal Gearmotor 25Dx54L mm HP with 48 CPR Encoder” with a Roboclaw 2x5A v4.0.5 controller.

I am using a Raspberry pi b+ and Python. When I try to reset the encoders absolute counter and then read their state, it only works in encoders Quadrature Mode. It reads 0 counts for both motors. Everything’s correct so far. But then, if I just change the encoders mode mode to Absolute Mode and then read again, it shows something between 12 and 14 (around 2052 if I swap the encoders cables). My question is: is this normal? Why I am not able to reset the encoders to zero in absolute mode? I got the same results when I tried with an Arduino Uno and the arduino library provided by roboclaw.

An exemplepiece of python code is shown below. It resets correctly when in Quadrature mode, but when I uncomment the lines for changing to Absolute mode, it doesn’t work anymore and it gives that value around 12-14 or 2052 if the encoders cables are swapped.

[code]import controller
import time

print “Roboclaw Encoders Test \r\n”

#Get version string
controller.sendcommand(128,21);
rcv = controller.port.read(32)
print repr(rcv)

Setting encoders mode to Quadrature Mode

controller.SetM1EncModeQuad()
controller.SetM2EncModeQuad()

Read the encoders counter values and print them

enc1 = controller.readM1encoder()
enc2 = controller.readM2encoder()
print "Encoder 1 before reset : ", enc1
print "Encoder 2 before reset : ", enc2

Reset the encoders counter

controller.ResetEncoderCnts()

Change the encoders mode to Absolute Mode

##print "Encoders Mode before = ", controller.readEncoderMode()
##controller.SetM1EncModeAbs()
##controller.SetM2EncModeAbs()
##print "Encoders Mode after = ", controller.readEncoderMode()

Read the encoders counter values and print them

enc1 = controller.readM1encoder()
enc2 = controller.readM2encoder()
print "Encoder 1 after reset : ", enc1
print "Encoder 2 after reset : ", enc2[/code]

Thanks!

Inigo

Hello, Inigo.

Absolute encoders are different from quadrature encoders. Absolute encoders output their current position of the shaft. Since the counter displays the current position it will not reset to zero.

Unlike absolute encoders, the quadrature encoders on our 25D mm gearmotors do not output the current position. You should set the “Encoder Mode” for your RoboClaw to “Quadrature” with our motors, and then you should be able to reset the count at anytime.

- Jeremy

Thank you very much for the reply Jeremy.

Just another question that may be related to it: Does that mean that these motors can not be driven using the PID Position functions (commands 65, 66 and 67)? Because I have succesfully sent them commands to control their speed, acceleration and traveled distance (in qpps), but I was struggling during the last week to achieve a position PID control of them and I couldn’t do it. If that is the reason, that’d explain a lot of things! If it’s not, I still have to found the reason why it doesn’t work.

Thank you again,

Inigo

According to the RoboClaw motor controller user manual, you should be able to use the encoders to do position control. If you continue to have problems getting position control to work, you might try contacting the manufacturer, Orion Robotics, for additional assistance.

- Jeremy