PWM - compensate for variances between 2 motors
Ron Czapala
Posts: 2,418
I am trying to figure out how to make my robot move in a relative straight line. It seems that even though the motors are "identical", the robot veers hard to one side. (I know rotary encoders providing feedback to the MCU are the best method, but hope to compensate thru program code.)
I tried switching the motors on the Dual MC33926 Motor Driver Carrier and connected the inputs for both input channels together to make sure the difference was in the motors, not the H-Bridge driver module.
The robot is described in this forum topic Homemade StingRay.
I am using a simple BS2 program to ramp up/down the motors to just move forward, pause, and backward. I tried increasing the Duty value for the second motor but it doesn't make much difference.
Any suggestions would be appreciated...
bs2
2K
Comments
1) add an encoder of some type
-OR-
2) set both motors at 50% duty cycle
3) let it run for 10 feet, measure the difference of where it ended up compared to a straight line
4) if significantly off a straight line, use the difference to increase or decrease the duty cycle on one of the motors, goto 3
5) now you should have settings for a straight line; and you should be able to increase/decrease the "default" by the same % to go faster/slower more or less straight
I am building the above algorithm into my RoboProp boards firmware.
This is a good approach to compensating for motor differences. If the difference is not linear you may need to have % values for several speeds and extrapolate between those points.
For my RoboProp firmware, I intend to make an array (potentially for 1..100%) to store the offset value, but 10%/20%/.../100% should suffice, with linear interpolation between the steps.
Thanks for your suggestions - I will experiment some more.
Do you think the reference points will be affected by the battery level?
The kids in the robot club said "two motors never just go straight, you have to steer."
We found wheel alignment, motor coil resistance variation, uneven surface, defect in the tread, and contamination on the test area all affect "strainghtness".
The result was a standard assumption that the robot will not go straight when you want it to, some feedback for steering must be provided.
If you find to the contrary there a bunch of kid with Legos that will be interested .
You are most welcome.
I'd first ignore the battery level, get it going straight with a full charge... then test at different battery levels.
Setting the encoder from 0 to 15 (0xF) and hitting the stamp reset let me change the speed for a short run.
The best results were setting the PWM Duty value of the slower motor 7 higher than the faster motor.
The are differences between repeated runs at the same speed - for various reasons I'm sure, but
adding sensors to detect objects and change direction seems more practical now that I can get it to move relatively straight...
This video shows two runs at different speeds:
Thanks erco! I found your thread on making your own encoders but it looks like the Hamamatsu P5587 is discontinued and similar components are hard to find.
Do you know of any place to get them or an alternative?
I may just spring for the Pololu motors with the Hall effect encoder
Your video with the laser pointer was pretty neat.
I guess they went with their highest torque motor. They offer a similar motor with slightly lower torque, but a lot lower stall current. Assuming your platform can handle the lower torque, I'd advise getting that one instead.
-- Gordon
The MC33926 has an analog current load feedback output pin that lets you detect a current overload.
The Pololu 12V motors all have a free-run 300mA and 5A stall (not sure what moter you are referring to)
My bot weighs over 9 lbs so I don't want to underpower it.
The current wheel/motor combo - Pololu 90mm (3.54") wheels at 310 rpm gives 4.8 ft/sec.
I just ordered 4 7/8" BaneBot wheels (same as StingRay) from Trossen Robotics.
I also ordered the Pololu 50:1, 200 rpm motors (170 oz/in torque) with two-channel Hall effect encoder
That wheel/motor combination should give 4.25 ft/sec with 170 oz/in torque vs. the current 110 oz/in.
Looks like a good combination. How will you be reading those encoders?
-- Gordon
Pretty sure a Propeller is the way to go. Especially when I add object detection sensors -
I have some Sharp GP2Y0A02YK0F Distance Measuring Sensors (20 to 150 cm) and some Pings.
I guess I can use a cog for PWMing each motor and a cog to read each encoder.
Better start researching the OBEX...
The Sharp IR distance measuring sensors are being phased out, too. Stock up now!
What I'm hearing is that they have a newer series of smaller and less expensive PSD-based sensors, but they are currently "not available in North America" so as to clear out the gray market channel. Pololu is selling one or two of the units marked as not available in the US, so apparently they're getting them somehow.
The new sensors are digital only, have a 300 Hz refresh rate (as opposed to the ~20 Hz of the older version) and use much less current. Not sure if they plan on bringing back any analog sensors in this style, but I'd think they would.
These sensors seem to be an important part of Sharp's IP portfolio. I'd be really surprised if they disappeared altogether. It would be a shame if they didn't, unless Sharp sells or licenses their patents.
-- Gordon
erco,
Check out this Honeywell HLC2701 sensor - does it sound like a comparable sensor based on youe experience with the 5587?
DigiKey $4.42
Mouser $2.83
It needs a separate IR emitter though...
With differential steering / drive it is a different story altogether. The most common method is a PID drive which of course requires encoders and some type of feedback.
There are also other more "interesting" methods such as line following or wire guided that can keep you on the straight and narrow.
If I just monitor one channel I will get 800 pulses per wheel revolution (16 per motor shaft revolution).
Since the wheels are roughly 15.3125 inches in circumference, I would get about 52 pulses for each inch the wheel rolls.
If I monitor both channels as a quadrature encoder setup I would get 3200 pulses per wheel revolution but I can't imagine needing that much precision.
I found OBEX objects for quadrature encoders but haven't tried them yet...