Is an Arduino Capable of Reading All Four Rover 5 Quadrature Encoders?
September 15, 2013
Note: Sorry this post is so long. I used bold text to indicate the main point of the post.
I didn't want to hijack Oddbot's Rover 5 thread, so I'm starting this one here in the forum.
In replying to odong's question about the quadrature encoders I stated (among other things):
"From what I've read, I think most Arduinos aren't fast enough to capture all the quadrature encoder interrupts and still have time to perform other tasks. I believe reading all four quadrature encoders requires a fast microcontroller. I used a Propeller in both of my Rover 5 projects."
I'm glad I used "From what I've read" and "I believe" to indicate my uncertainty about the topic because bdk6 soon corrected me with:
"The arduino running at 16 MHz (the normal speed) processes close to 16 million instructions per second. At 180 RPM on each wheel, using all four encoders, and the motors turning 180 RPM, there would be a total of right at 1000 interrupts per second. With each interrupt taking about 20 instruction cycles, that would be 20000 out of 16000000 each second, or 00.125% of the total processing cycles available. That amount is negligible. Even horrible code that took 100 times longer would still leave over 87% of the processing cycles for other things."
This is very encouraging for anyone wanting to control the individual motors of a 4WD Rover 5 with an Arduino. What I don't understand is where are the four quadrature reading Arduino controlled Rover 5's?
I know of two examples of people stating all the interrupts were causing problems for their Arduinos.
CliffO improved my technique of mounting Vex Mecanum wheels to his Rover 5 and mentions his frustrations of having the interrupts overwhelming the Arduino.
amano001 mentioned in my thread over at the Parallax forums:
"we were looking into using one of the propeller proto boards instead of the arduino mega as we have seen the code response get very sluggish with interrupts going off all the time for the encoders."
I also recall Oddbot mentioning the need of a fast microcontroller (I think he was suggesting one of the faster Arduinos) to read four quadrature encoders. Sorry, I couldn't find a link.
There are a lot of Rover 5 chassis on LMR. I'm pretty sure I've looked at all the robot projects on LMR using the Rover 5 and I haven't found any (other than mine) using four quadrature encoders.
Most of the builders/programers of the Rover 5 projects on LMR state they are new to programming and robotics. Is this why there aren't any Arduino controlled Rover 5's using all four quadrature encoders? (I don't recall seeing any using two quadrature encoders.)
amano001 who I previously mentioned ended up using a Propeller QuickStart board as a slave to the Arduino. The Arduino would send direction and speed commands to the Propeller and the Propeller (using my code) would drive the motors while monitoring the encoders to produce the desired movements.
Is a 16MHz Arduino really capable of monitoring four quadrature encoders (with time left over for other tasks)? I'd really like to know.
Just yesterday I started designing a shield with a Propeller. My intention is to make it easier for others to use the Propeller as a slave to an Arduino. The Arduino would send speed and direction commands to the Propeller. The Propeller would then drive the motors appropriately based on a PID algorithm using feedback from the encoders.
If an Arduino can do this on its own, then the Propeller shield I plan to make wouldn't be needed.
Here are some numbers to help any interested parties to aid me in my decision to continue to develop a Propeller shield.
In my tests the max rotation speed of a Rover 5 wheel is 90 rpm. This produces 500 encoder transitions per second per wheel. All four wheels would generate 2000 transitions per second at 90 rpm. (This was a free spinning wheel. The speed will likely be lower when used in contact with the ground.)
Besides simple odometry (how far has the wheel traveled), I think it's very useful to also compute the speed of each wheel. The speed of each wheel should probably be computed at about 50Hz.
Are these interrupt rates and computation requirements within an Arduino's capability?
I have plenty of other projects I'd like to work on if a quadrature encoder reading Propeller shield isn't needed for an Arduino controlled 4WD Rover 5. I presently do not have enough experience with the Arduino to know if the proposed shield is needed. I'd really apperciate information about the Arduino's ability to monitor four quadrature encoders unassisted.