Page 1 of 2

Command to read both encoders at once?

Posted: Thu Apr 02, 2015 1:40 pm
by jwatte
I'm trying to do dead reckoning on a differential drive robot using encoders, and I get a little bit of slip because the RoboClaw takes a while to read one encoder, and then the other. In my capture below, you will see that it takes 3.05 milliseconds just to respond to the command to read; the interval between reading one and reading the other is over 5 milliseconds (even though I'm running at the highest baud rate and am turning around to read the next very quickly.)

If there were a command to read both encoder positions at the same time, that would be a lot more accurate. Is there such a command that I'm missing in the docs?

Image

Channel 1, RoboClaw Cmd, is sending the command. Channel 2, RoboClaw Rsp, is the RoboClaw responding. The timing between the two green markers is shown in the "T2 - T1" calculation in the upper-right of the Logic window.

This is using a RoboClaw 2x30A, serial control at 38400 bps.

Re: Command to read both encoders at once?

Posted: Tue Apr 07, 2015 11:03 am
by Basicmicro Support
There is not currently a command to read both encoders at once. Ill see if I can add one in the next firmware release.

With the current system it takes 2 * (1ms + (10*6/38400) = 5.125ms to read both encoders. With a command that could read both at once it would take 1ms + (10 * 10bytes *1/38400) = 3.6ms. So faster but not massively so.

Note the 1ms delay added is on purpose so slower processors without hardware uarts can get ready to read the data.

Its also possible you could use the distance commands(or position commands) to handle the motion inside the Roboclaw, however the PID routines are updated 300 times a second. So you are still at an average delay of 1.66ms(eg any command will start from 0ms to 3.33ms before the next PID cycle).

Post some more info about your project and I may be able to help you out or make other suggestions.

Re: Command to read both encoders at once?

Posted: Tue Apr 07, 2015 4:59 pm
by jwatte
So faster but not massively so.
Thanks!

I'm not so worried about the total time it takes to read the command, as I am about the skew between read samples, because if the wheels run at the same speed, but are sampled at different times, I will get skew between the wheel encoders, which my sensor fusion will translate into a slight rotation of the chassis.

The reading is actually asynchronous in the higher-level code that does sensor fusion, short-term planning, and tells the RoboClaw what to do. That update loop is actually multiple overlapping loops running at frequencies between 1000 Hz (IMU integration,) 100 Hz (the roboclaw poll and control loop,) 30 Hz (vision detection) and 10 Hz (GPS and magnetometer.) This is for a navigating/pathfinding rover robot.

As long as I can avoid the skew, that'd be great!

Re: Command to read both encoders at once?

Posted: Tue Apr 14, 2015 8:26 am
by Basicmicro Support
OK. i got it now. I will see if I can add a new command that will let you read both values at once.

Re: Command to read both encoders at once?

Posted: Tue Apr 14, 2015 11:45 am
by jwatte
That would be super. Thanks for looking into it!

Re: Command to read both encoders at once?

Posted: Thu Sep 24, 2015 7:50 am
by mabrouk
has this new command been added and if so what is the command # and usage?

also you mentioned one can use the distances commands instead - which commands are you referring too?

thanks,
Jack

Re: Command to read both encoders at once?

Posted: Mon Oct 05, 2015 9:12 am
by Basicmicro Support
Its hasn't yet but Ill see if we can fit it in. The manual is being updated and we are finishing updates to all teh libraries and examples. Im current working on a java library and possibly a LabView driver as well. Im expecting the new release with manuals and updated libraries/examples to be done in the next day or two.

Re: Command to read both encoders at once?

Posted: Mon Feb 08, 2016 2:03 pm
by jwatte
I see command 78 (GET ENCODERS) in the sample code, but it's not in the documentation I just downloaded.
I assume that it simply returns the M1 and M2 raw encoder values? If so, that's perfect :-)

Re: Command to read both encoders at once?

Posted: Tue Feb 09, 2016 8:26 am
by Basicmicro Support
Correct. It returns two long values(8 bytes plus the CRC16).

Re: Command to read both encoders at once?

Posted: Wed Mar 16, 2016 11:09 pm
by billy
I have a 2x15A roboclaw running 4.1.6. It does not respond to command 78.
Is 4.1.6 the newest version? Any hints?