I'm trying to create a car that's being controlled by an Arduino. I'm using the following chasis: http://www.aliexpress.com/item-img/New-2WD-car-chassis-DC-gear-motor-wheels-easy-assembly-and-expansion-car-toys-robot-toys/32310649967.html
And L298N motor driver.
The problem is it's hard to make the car go straight. Giving the same PWM value to the motors still makes them spin in different speeds, trying to calibrate the value is hard and every time I recharge my batteries the value changes.
What are my options on making the car go straight when I want (well, sometimes I'll want to turn it around of course)?
I've thought about using an encoder but I wish to avoid that since it will complicate the whole project, is there any other viable option? and even when using an encoder, Does it means I will need to keep track all the time and always adjust the motors value continuously? is there some built-in library for that?
Thanks in advance!
2 Answers 2
I used a simple optical encoder and the little disks that came with my kit. The encoders cost < 1ドル for 2 of them.
Failing that use an accelerometer and measure the lateral motion, should also cost about 1ドル.
Modern tiny 20ドル toy quadcopters use a magnetometer to maintain a steady heading. Duplicating that effect could be cheaper and more reliable than dual encoders. On certain surfaces, like carpet, even perfect encoding with perfect voltage and wheels can't guarantee maintaining the heading.
One viable option might be to drive one wheel with your control system, drive the other wheel to maintain the magnetometer heading, and then steer by adjusting the target heading.
-
1Actually the cheap ones try to integrate the gyro. Magnetometers only come in at a higher price point. Even if you do get a magnetometer it will be harder to interpret and more interference prone than encoders. But it is possible with care if an external reference is what is desired.Chris Stratton– Chris Stratton2016年05月11日 19:54:38 +00:00Commented May 11, 2016 at 19:54
@my past self.
It sounds fairly stupid to use a hall effect sensor near a electric motor. (Never mind that suggestion.)