Hello, I have 4WD robot using a Speeedseed Motor Shield V2.0. Whenever i put new batteries in the robot or when they fade out after a bit of use, i have to constantly adjust the speed out of 255 to make it move smoothely not to quickly or slowly. Which is very frustrating to constantly adjust depending on the battery current. is there a practical way to allow it to constantly regulate the speed depending on the current? Any help will be greatly appreciated.
You could use the Arduino to measure the battery voltage and make adjustments to the analogWrite() value to compensate for changes in voltage. However I don't know if that would solve the problem. Measuring current would be a lot more complex.
What sort of batteries are you using?
Im using about ten double A batteries. & Yes that does sound complex considering that i would have to write an if statement for every case. How does everyone else deal with this issue?
Have you considered my suggestion for measuring the voltage?
It sounds like this robot uses either a voltage regulator or no regulator at all. A speed regulator would automatically adjust the voltage applied to the motor to compensate for battery voltage--until the battery collapsed.
AndrewKaram: Im using about ten double A batteries.
The battery type makes a big difference to the discharge curve. Lithium Ion/ Polymer is fairly flat then drops off quickly at the end of its charge. NiMH and Nicd have a big drop at the start of their discharge, A long gradual slow drop through its charge then drops off fast at the end too. Alkaline have a pretty steady voltage drop all through their discharge ( a little faster at beginning and end).
The problem with a 10 aa battery pack when driving motors is the internal resistance of the batteries will cause quite a drop when the motor is drawing current. It would be hard to be accurate when measuring voltage.
Lithium Polymer (or LiPo) will have a much flatter discharge curve and also not drop as much under load.
Sounds like a speed and/or position control loop might be useful? You want an encoder for either, measuring current only tells you the torque which is more about gradient than speed.
phoxx: It sounds like this robot uses either a voltage regulator or no regulator at all. A speed regulator would automatically adjust the voltage applied to the motor to compensate for battery voltage--until the battery collapsed.
I don't believe my motor shield has a voltage regulator http://www.seeedstudio.com/wiki/Motor_Shield_V2.0 . A speed regulator sounds perfect and sounds exactly like the fix Im looking for, any references you can send me to?
I never mentioned a regulator.
I mentioned a control loop. That's software you write to automatically adjust the drive to keep the speed as you want it. You need to understand a bit about control theory and PID loops ideally, but a control loop is any code that repeatedly takes a reading from the system and adjusts an input to it (here motor PWM) to affect the behaviour.
Is any additional hardware necessary or is it just code?
AndrewKaram: Is any additional hardware necessary or is it just code?
As MarkT said above you need an encoder. As it happens I'm fiddling with some code for one as we speak. Various forms: a magnet passing a Hall sensor say, or a slot passing a light beam, probably others.
You take the time each time the sensor (whatever it may be) is triggered and so get the RPM.
Have a look in the Playground, I recall seeing some stuff there.