Why does the robot ride crookedly?

I tried to make different robots with different motors and i get the same problem.

The motors do not start at the same time and brake first one then after a second the other.

I made a line follower. when robot stops on the line, one wheel overrides a line and the he can't find the line afterwards.

I use capacitors, but can not solve the problem, could you advise, how to solve it.

Thanks in advance.

Motors never rer identical. Either use DC motors + encoder|index, or steppers. Ther other thing: the error is in line 42.

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.

The code is open source, not a secret.

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.

Why not send one signal to go and stop to both motors at the same time? Something like a Y connector might work, no?

No, won't work.

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?

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.

Hi,
Welcome to the forum.

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.

Thanks.. Tom.... :slight_smile:

The code is very simple, just to know if robot motors start at the same time, see how strait robot goes and stops.

#define SPEED_2      6
#define DIR_2        7
#define SPEED_1      5
#define DIR_1        4

void setup() {
 
    pinMode(SPEED_1, OUTPUT);
    pinMode(SPEED_2, OUTPUT);
    pinMode(DIR_1, OUTPUT);
    pinMode(DIR_2, OUTPUT);
}

void loop() {

 digitalWrite(DIR_1, LOW);
  analogWrite(SPEED_1, 75);
  digitalWrite(DIR_2, LOW);
  analogWrite(SPEED_2, 75);
delay(5000);

  digitalWrite(DIR_1, HIGH);
  analogWrite(SPEED_1, 0);
  digitalWrite(DIR_2, HIGH);
  analogWrite(SPEED_2, 0);
  delay(5000);
}

But motors do not stop at the same time? I cant understand why?

What happens if you try the code below? (where I removed a couple of lines)

#define SPEED_2      6
#define DIR_2        7
#define SPEED_1      5
#define DIR_1        4

void setup() {
 
    pinMode(SPEED_1, OUTPUT);
    pinMode(SPEED_2, OUTPUT);
    pinMode(DIR_1, OUTPUT);
    pinMode(DIR_2, OUTPUT);
}

void loop() {

 digitalWrite(DIR_1, LOW);
 digitalWrite(DIR_2, LOW);

 analogWrite(SPEED_1, 75);
 analogWrite(SPEED_2, 75);

 delay(5000);


 analogWrite(SPEED_1, 0);
 analogWrite(SPEED_2, 0);
 delay(5000);
}

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.