If your code involves motor speed (0 . 255), assuming you are only running on flat surface, just alter the motor speed of one side til it goes straight.
Yes, while moving i can adjust speed to go strait, but my problem is one motor starts earlier and continue to spin for a second while other motor already stoped. I tried different motors, motor shields and arduinos but problem is the same.
I agree with the comment about differences in DC motors. That is, even if two DC motors are the same model, and even if they look the same ..... they may be different in terms of input voltage versus output velocity behaviour. Also look up a term 'motor deadband', which should be considered especially in brushed DC motors.
One kind of quick duct-tape solution/fix that sometimes improves the situation is ---- as a member pointed out --- is to add a PWM offset to one of the motors.
So if it known in advance that a PWM level of say 50 will allow both wheels to begin to turn. Then you could set PWM level 50 for both wheels to begin with. Then observe the direction that the robot will undesirably veer off (ie. veers left, or veers right). If the robot veers left. Then add a small PWM offset for the left-hand motor....eg. a PWM offset (additional) of say 5.
PWM = 70
PWM_left = 5 + PWM
PWM_right = PWM
The above would mean PWM_left would be '75' when the level of PWM to the right-hand motor would be 70. This means purposely adding some kind of PWM offset to to one side to compensate ---- to balance things out.
Even better methods would probably require velocity measurement sensors or something like that.
Southpark:
I agree with the comment about differences in DC motors. That is, even if two DC motors are the same model, and even if they look the same ..... they may be different in terms of input voltage versus output velocity behaviour. Also look up a term 'motor deadband', which should be considered especially in brushed DC motors.
One kind of quick duct-tape solution/fix that sometimes improves the situation is ---- as a member pointed out --- is to add a PWM offset to one of the motors.
So if it known in advance that a PWM level of say 50 will allow both wheels to begin to turn. Then you could set PWM level 50 for both wheels to begin with. Then observe the direction that the robot will undesirably veer off (ie. veers left, or veers right). If the robot veers left. Then add a small PWM offset for the left-hand motor....eg. a PWM offset (additional) of say 5.
PWM = 70
PWM_left = 5 + PWM
PWM_right = PWM
The above would mean PWM_left would be '75' when the level of PWM to the right-hand motor would be 70. This means purposely adding some kind of PWM offset to to one side to compensate ---- to balance things out.
Even better methods would probably require velocity measurement sensors or something like that.
yes, at start i can increase PWM, but what to do when robot stops and turns at one direction, as motors do not stop simultaneously?
mikaletto:
yes, at start i can increase PWM, but what to do when robot stops and turns at one direction, as motors do not stop simultaneously?
If both of the motors become roughly matched by this simple sort of PWM offset compensation method, then the robot is expected to go more-or-less 'straight' - in a straight line.
For turning - where one wheel needs to move faster than other other one ------- it will be up to you (yourself) to understand some things about instantaneous velocity, inertia etc.
The simplest way to start looking at it is --- the faster the robot travels, you have to back-off on (ie. reduce) the sensitivity of turning. And --- if you approach a relatively tight corner or tight bend, you may need to slow down. You just have to think about what would actually happen if you were driving a car at high velocity around tight bends etc. And think about what happens if your robot is allowed to abruptly make a turn at high speed. It can get out of control unless you limit the angle of turning. And if you approach a sharp bend --- you might need the robot to 'see' or sense a tight bend coming up, and slow down for the bend. On the other hand, if your robot travels relatively slowly, then this might not be an issue.
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Can we see your code and a schematic please, we cannot give you concise answers if we do not have basic information.
mikaletto:
Yes, while moving i can adjust speed to go strait, but my problem is one motor starts earlier and continue to spin for a second while other motor already stoped. I tried different motors, motor shields and arduinos but problem is the same.
If you want position control, you'll need more than a motor. You need closed-loop control with an encoder.