sleepingsword
Posts: 2
Joined: Tue Jan 16, 2018 10:44 am

Controlling 4 gear motors with encoders

Tue Jan 16, 2018 10:52 am

I am looking into better motors for a robot project. I am using 4 of the classic yellow 6v motors at the moment with a single l298n.

I have found these: 'DC 12V 320rpm Encode Gear Reducer Motor Electric Gear Box Motor' (will find em on ebay, banggood etc)

I cant find any information about controlling 4 of these on one pi, I assume I need a new controller but cant find anything, any pointers would be great!

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling 4 gear motors with encoders

Tue Jan 16, 2018 12:52 pm

How are you controlling four motors with one L298N? Are you driving two motors in parallel?

Treat those encoder motors as two devices, one DC motor plus one encoder. Plenty of software is available to read encoders.

I'm not convinced encoders are a great deal of use for simple robots. They take no account of wheel slip and the maths must be tricky working out a position when the robot travels a curve.

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Controlling 4 gear motors with encoders

Tue Jan 16, 2018 8:11 pm

I hadn't seen that exact motor before it must be a new release but looks good. I have a similar setup that I have been playing with, it uses the same encoder and same ratio gearbox but slightly different motor. 320RPM is a very fast robot motor.

See my 2 videos where I played with them.

first video explains what the encoder is and how to write the software to read it https://www.youtube.com/watch?v=p4BCFhIuC88&t=25s

the second is about the problems with using software to read the encoders and using a hardware encoder counter counter https://www.youtube.com/watch?v=41ogu0U ... 0681570184

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling 4 gear motors with encoders

Tue Jan 16, 2018 8:39 pm

320RPM is quite high for a wheeled robot with normal sized tires. However it is less than 6 revolutions per second so should not present much of a problem to read an attached encoder in software (assuming something like 30 detents per revolution).

mattmiller
Posts: 2245
Joined: Thu Feb 05, 2015 11:25 pm

Re: Controlling 4 gear motors with encoders

Tue Jan 16, 2018 9:18 pm

However it is less than 6 revolutions per second
Sometimes the encoder is not on the gear-reduced output shaft but is on the actual high-rpm motor-shaft so that's something to watch out for

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling 4 gear motors with encoders

Tue Jan 16, 2018 9:34 pm

mattmiller wrote:
Tue Jan 16, 2018 9:18 pm
However it is less than 6 revolutions per second
Sometimes the encoder is not on the gear-reduced output shaft but is on the actual high-rpm motor-shaft so that's something to watch out for
I've just bought a couple of motors with attached encoders. They are on the motor shaft with 30 vanes, no load speed of 7800RPM. Somehow I doubt I'll read them reliably at full speed.

I'll know in 2-8 weeks depending on delivery.

sleepingsword
Posts: 2
Joined: Tue Jan 16, 2018 10:44 am

Re: Controlling 4 gear motors with encoders

Tue Jan 16, 2018 9:51 pm

joan wrote:
Tue Jan 16, 2018 12:52 pm
How are you controlling four motors with one L298N? Are you driving two motors in parallel?
yes
joan wrote:
Tue Jan 16, 2018 12:52 pm
Treat those encoder motors as two devices, one DC motor plus one encoder. Plenty of software is available to read encoders.
I figured as much but could not see how 4 would be connected to the gpio, was hoping of some sort of board or hat I could go through.
joan wrote:
Tue Jan 16, 2018 12:52 pm
I'm not convinced encoders are a great deal of use for simple robots. They take no account of wheel slip and the maths must be tricky working out a position when the robot travels a curve.
I want better motors for control, and like the idea of accurate control of each wheel. I am open to alternatives if you have suggestions.

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Controlling 4 gear motors with encoders

Wed Jan 17, 2018 6:31 am

You will find that the encoder is attached to the motor shaft and is a 11 pole quadrature encoder so 4 signals per pole on a 30:1 gear box will come out at 1320 signals per rotation by 6 rotations per second = 7920 signals per second at full RPM then if you have 4 motors that is a total of 31,680 signals per second to count over the 4 motors. Unless your using really low resolution encoders it is usually easier to off load the over heads onto a counter chip which you pole at about 5 times per second to check the speed and adjust the duty cycle to maintain constant speed.

Using a counter chip will also off load the amount of needed GPIO pins as all 4 counter chips will use the same SPI pins but each will have a different CS pin then all the encoder pins will connect to the counter chip not the RPi

If you have lots of spare time check out this video especially the first half hour as this guy is a very respected robotics professor https://www.youtube.com/watch?v=8CXReb7f0Eo

Return to “Automation, sensing and robotics”