0

I've recently succeeded in building my Autonomous robot with DC motors, and it works well. However, it doesn't move in a straight line yet, when it should. I'm now studying which method should I implement to make the robot go straight. I pretty much understand how to use the encoders, but I'm not sure about the gyro. I had written a program for straight motion using encoder, but it's not moving straight exactly because of front brush speed, for further improvement I have decided to use gyro, If I use gyro possible to make straight motion ? or else any suggestion ?

1 Answers1

0

First, make sure you conceptually understand what it means for a robot to drive in a straight line. You will not get a robot that moves perfectly in a straight line. You may get one to move straight-enough (perhaps more perfect than humans can determine) but there will always be error.

A gyroscope may not be able to determine you're going off course if it's gradual enough and depending on the quality of your gyro it may have a buildup of drift, causing it to think it's turning ever-so-slightly when it's sitting perfectly still. The more expensive of a gyro you get, the less this will be, but still.

Even if you assume perfect sensors, there is still a difference between "driving straight" and "keeping on the straight and narrow". Imagine you had coded a robot to drive such that it tried to keep its bearing as consistent as possible (drive straight). If, while it was moving you knocked it a bit, it would swerve to the side some and then correct itself to the original angle. However, it would be on a different path. Sure, the path would be parallel to the original one, but it would not be the same path.

Then there's the option of having it try to figure out just how far off the beaten path it was pushed and try to get back on it. That'll either take a constant reference (as a line follower robot would do) or more sensors (like a 3D gyro and 3D accelerometer).

That second option sounds a bit more than what you're doing, so here's the first option done in no particular robotics framework:

//initialize
double angle = gyro.get_heading_degrees();
//...
//logic code that may be looped or fired by events
{
  //this is our error; how far off we are from our target heading
  double error = angle - gyro.get_heading_degrees() - 360;

  drive_system.drive_arcade(error / 180, 1);
}

This assumes driving in an arcade fashion; you can adapt it to tank drive or swerve drive or mecanum drive or H-drive or...

The '1' is just a speed

The '-360' and '180' are values to reduce the angle to a value between -1 and 1. If your drive method uses a different range to determine angle, that'll have to be adapted.

Finally, this example isn't foolproof, but it should get you thinking about how to correct for errors when you've detected them.

Altainia
  • 1,347
  • 1
  • 7
  • 11