# How to find overall speed of robot from speed encoders on two motors

Hi,

I am trying to write code to count the number of pulses from two motors driving a robot chassis, which are equipped with Hall encoders. This emits pulses that can be counted. My goal is to find the overall speed of the robot.

So, my thinking is that i can count the number of pulses for each motor within a specified time interval - i'm thinking using millis or maybe interrupts? Are there any other methods?

Then, to find the speed for each motor i could use the formula: speed = pulses / time interval. To find the overall speed of the robot, add both speeds (number of pulses from each motor). But what if motors are moving in different directions, like when the robot is steering?

I want to confirm that my thinking is right before i spend the next hours or maybe even days working on it.

if both motors are moving in the same direction, to find the overall speed of the robot, do i need to add both speeds (number of pulses from each motor) or just one?

If each wheel is going at the same speed then why would you add the speeds together to give a figure that is twice the speed ? What you might decide to do is to calculate average the speed of the two wheels.

Incidentally, don’t you need to use the circumference of the wheel in your speed calculation unless all you are interested in is relative speed under various conditions.

Hi,
You need to use speed of each wheel with a sign for forward and backward rotation.
If + speed is forward, -speed is backwards, then when you add them and divide by two, you average speed will be correct.

For example

1. If both wheels are going forward at say +10, then your average speed is

(10 + 10 )/2 = +10.

1. If one wheel is rotating forward at +10 and the other backward -10, as in a spin, zero speed.

(10 + (-10))/2 = 0.

3 ) If one wheel is rotating forward at +10 and the other stationary at 0.

(10 + 0)/2 = 5.

That would be right as the centre of your robot, between the wheels is travelling in a circle.

And any combination in between should give you your average speed.

You need to get direction as well as speed from your wheels.

One way is if your encoders are Quadrature Encoder then they will give direction indication.
OR
Look at the direction control to each motor, that will tell you if you are rotating forward or back.

I hope that makes sense..
Tom...

UKHeliBob:
If each wheel is going at the same speed then why would you add the speeds together to give a figure that is twice the speed ? What you might decide to do is to calculate average the speed of the two wheels.

Incidentally, don't you need to use the circumference of the wheel in your speed calculation unless all you are interested in is relative speed under various conditions.

I'm a bit confused about energy being added into the system from another motor so the speed should double if using 2 identical motors?? Let's say, in the case of a motorcycle, if each wheel is powered by an identical motor, then... if one motor is running and it gives the robot a forward speed of 10m/s, when the second motor is activated such that it also turns 10m/s in the same direction, then wouldn't the motorcycle go forwards at 20m/s??

I am omitting the inclusion of the calculation of the wheel diameter for now, as i think it should be possible to obtain the speed of the robot using the encoders only and then control the speed of the robot with PWM only? These are Hall encoders, incremental and magnetic type, attached at the end shaft of each DC geared motor.

TomGeorge:
Hi,
You need to use speed of each wheel with a sign for forward and backward rotation.
If + speed is forward, -speed is backwards, then when you add them and divide by two, you average speed will be correct.

For example

1. If both wheels are going forward at say +10, then your average speed is

(10 + 10 )/2 = +10.

1. If one wheel is rotating forward at +10 and the other backward -10, as in a spin, zero speed.

(10 + (-10))/2 = 0.

3 ) If one wheel is rotating forward at +10 and the other stationary at 0.

(10 + 0)/2 = 5.

That would be right as the centre of your robot, between the wheels is travelling in a circle.

And any combination in between should give you your average speed.

You need to get direction as well as speed from your wheels.

One way is if your encoders are Quadrature Encoder then they will give direction indication.
OR
Look at the direction control to each motor, that will tell you if you are rotating forward or back.

I hope that makes sense..
Tom...

That was helpful, but in my implementation, i am thinking of simplifying the process by only considering the output pulses from one encoder only. I have quadrature encoders on both DC geared motors but i will use only one encoder signal output. But i'm not sure what you mean by direction control to each motor... how would i be able to extract this data? Maybe if i write a speed function to convert the pulses or average pulses from each motor to PWM?

if one motor is running and it gives the robot a forward speed of 10m/s, when the second motor is activated such that it also turns 10m/s in the same direction, then wouldn't the motorcycle go forwards at 20m/s??

You are joking, I hope.

Wheel 1 moves at 10 m/s It is attached to the motorcyle which also moves at 10 m/s
Wheel 2 moves at 10 m/s It is attached to the motorcyle which also moves at 10 m/s

How could the motorcycle possible now go at 20 m/s when each of its wheels is only going at 10 m/s ?

It is certainly true that adding more power to the system could make the motorcycle go faster, but unless the wheels come off it they and the motorcycle will all move at the same speed. How could it be otherwise ?

UKHeliBob:
You are joking, I hope.

Wheel 1 moves at 10 m/s It is attached to the motorcyle which also moves at 10 m/s
Wheel 2 moves at 10 m/s It is attached to the motorcyle which also moves at 10 m/s

How could the motorcycle possible now go at 20 m/s when each of its wheels is only going at 10 m/s ?

It is certainly true that adding more power to the system could make the motorcycle go faster, but unless the wheels come off it they and the motorcycle will all move at the same speed. How could it be otherwise ?

Ah, yes! I apologise for my stupidity. I have been looking at equations of motion all night and trying to derive the torque vs voltage for my geared DC motor and i fear that my brain power might have dipped for a little while. I was thinking about the case when let’s say, i am on a speeding train going at 200 m/s and then i run inside or on top of the train in the same direction of the train at 3 m/s, so my overall speed would then be 200 m/s + 3 m/s. And i was trying to apply the same analogy to the 2 DC motors.

I am omitting the inclusion of the calculation of the wheel diameter for now, as i think it should be possible to obtain the speed of the robot using the encoders

You might think so but it is not.

Imagine if you have a vehicle with a 1” circumference wheel going at 60 RPM then the speed is 60 inches per minute. If the wheels had a one foot circumference then the speed would be 60 feet per minute.

DryRun:
That was helpful, but in my implementation, i am thinking of simplifying the process by only considering the output pulses from one encoder only. I have quadrature encoders on both DC geared motors but i will use only one encoder signal output. But i'm not sure what you mean by direction control to each motor... how would i be able to extract this data? Maybe if i write a speed function to convert the pulses or average pulses from each motor to PWM?

Are you able to make the motors go forward and reverse.
If so how are you controlling the motors, what signals are you using to control each motor?
Are you using a motor control board?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

If you are using a control board, then you usually supply the board with two signals, speed and direction.
You use the direction signal to know if the motor is going forwards or backwards.

i am thinking of simplifying the process by only considering the output pulses from one encoder only

Then why are you going through all this is you are going to only use one encoder?
Have you got the vehicle moving?
Or are you "thinking" instead of experimenting?

Thanks.. Tom..

I am omitting the inclusion of the calculation of the wheel diameter for now, as i think it should be possible to obtain the speed of the robot using the encoders only

Prepare to be disappointed

I have been looking at equations of motion all night

It is much better to sleep at night, and think about these problems with a clear head during the day.

Try it, and let us know if sleep helps or not.