Binary ror

Hi,

I have a platform consisting of 2 wheels that are being driven by these real large motors which are controlled by the Sabertooth motor driver, 25 Amps.

The Problem:

The platform veers off to the left or right cause the motor speed and other hardware like ball bearings etc are not perfectly matched.

So i slapped on 2 hall effect sensors one for each wheel hoping that if i could read the rpm of each wheel and found that they dont match i could control the power of the motor driving the faster/slower wheel, effectly making my platform go straight.

These sensors give me a logic 1 when a magnet attached to the wheel passes by it.

A line like "ST.motor(1, power);" controls the power to motor 1 and "ST.motor(2, power);" controls motor 2.

My values of power can run from 0 for stop to 30 for maximum speed (technically that speed number can go upto 128).

Also for simplicity I need to have the motors go in one direction only.

Can anyone direct me how can i use the 2 interrupts of the Arduino Uno to help me compute the speed of each wheel?

Thanks.

Ryan

You don’t need to calculate the speed in RPM, only the difference in time between ‘clicks’ on each wheel. Use millis() to get the time of the first ‘click’ on wheel 1 and then the second ‘click’ on wheel 1. Calculate the time difference between ‘clicks’(= speed). Do the same for wheel 2. Compare the two timings. If wheel one is faster, slow it down or speed up wheel two. If wheel two is faster…
Repeat for each wheel ‘click’.
This will give you an approximation to a straight line.
For turning, use an offset value when comparing the speed of the two wheels.
E.g. (timediffwheel1 - timediffwheel2 + offset) offset = 0 for straight, a negative value for left and a positive value for right (or vice versa).

Once you get the feedback information as suggested above, you will need to incorporate the PID library (or your own PID routine) to dynamically adjust the speed of the motors so that there is no error (difference) between them.

Wouldn't repeatedly checking the timings and adjusting the speed of one or the other of the motors, to get them to (approx.) match, be enough? Using a PID (What does PID stand for?) library seems like over-complicating things.

Wouldn't repeatedly checking the timings and adjusting the speed of one or the other of the motors, to get them to (approx.) match, be enough?

Maybe. The tricky part is to do it so the algorithm is stable under all conditions.

What does PID stand for?

PID Control (or Controller)... Proportional Integral Derivative Control... It's the solution to the mathematical model for a first-order system.

Henry_Best:
Wouldn't repeatedly checking the timings and adjusting the speed of one or the other of the motors, to get them to (approx.) match, be enough? Using a PID (What does PID stand for?) library seems like over-complicating things.

Doing that is not really any less complicated than using the PID library (probably even more so.) You are essentially doing a dirty hack of PID with what you are suggesting anyway. Using the library, he only needs a couple of lines of code to do it. The tuning is the hard part, and it wouldn't be any easier doing it the other way.

Thanks for that, Retroplayer.

As I know nothing about the PID library, I won't argue.
I doubt that any software can get the two motor's speeds to exactly match so it would have to constantly make corrections, hence my use of "approximation to a straight line." :slight_smile:
I presume by 'tuning' that you mean getting a less wobbly 'straight' line.
A more accurate method of collecting the wheel speed data would be a slotted disc passing between an optical coupler, as in a mouse's scroll wheel, but that might not be practicable in this case.

A properly tuned PID loop should match exactly. That is basically what it does is check the feedback, and correct on a timed basis.

P = Proportional. That means it will apply more force when the "error" is large
I = integral which modifies P to reduce overshoot
D = derivative, which compares how long the error has existed and modifies the P term to apply more force if the rate of change is too slow to keep up.

The error is obviously the difference between the two speeds. Tuning means adjusting the P, I, and D terms to keep them from oscillatiing (meaning over and undershooting the speed.)

The tuning is the hardest part. Using the library itself is very simple and only requires a couple lines of code. But getting the correct values for P, I, and D is the hard part. Properly tuned, it should have no problem making the speed exact, the response to change very quickly, and dynamically.

As you can see, that is essentially what you were suggesting anyway (check the difference in speed and adjust on a timed basis.)

I read a bunch of stuff on PID because I couldn't wrap my mind around it, and of all of them, this is the tutorial that really clicked for me:

It's funny how, after reading several sources and not 'getting it' you eventually find something that makes it crystal clear. Although I have programmed in Z80 assembler, when I learnt C++, about 15 years ago, I just couldn't get my head around Object Orientation. I've asked several people to explain it to me, but their explanations were as clear as mud. Recently, I needed some PHP for a website and while I was looking it up I noticed, on the same website, a tutorial on OO. Bingo! I'll have to read it again to refresh my memory, but it was like a lightbulb going on in my head.