Autonomous Programing Question

So in our autonoums my robot has to be exactly aligned for it to work. Is their any type of sensor or something that will make our robot stay exactly straight without using a bumper swith? One idea I had was to have the wheels turn at the same speed but I don’t know how to do that? If you have any ideas please let me knoww!! The program we are using is EasyC.

You could place encoders on a wheel on each side of the robot. Then have a program that will keep track of how many encoder counts each wheel has seen. If one wheel is getting behind the other, then it will be told to speed up.

Another sensor is the gyro. It is sensitive to angular deviations, but it is only good for about 20 seconds before it starts to drift and give errors.

Ultrasound can provide distance sensing.

Here is an example of a drive straight code we use. This code requires a motor encoder on each side of the drive.



void driveforwardstraight(int g, int a)  // g = encoder count, a = motor speed
{
	while (nMotorEncoder[rightbackdrive] < g)
{
if (nMotorEncoder[rightbackdrive] > nMotorEncoder[leftbackdrive])
{
		motor[leftbackdrive] = a;
		motor[leftfrontdrive] = a;
		motor[rightbackdrive] = a/2;
		motor[rightfrontdrive] = a/2;
}
else if (nMotorEncoder[rightbackdrive] < nMotorEncoder[leftbackdrive])
{
		motor[leftbackdrive] = a/2;
		motor[leftfrontdrive] = a/2;
		motor[rightbackdrive] = a;
		motor[rightfrontdrive] = a;
}
else if (nMotorEncoder[rightbackdrive] == nMotorEncoder[leftbackdrive])
{
		motor[leftbackdrive] = a;
		motor[leftfrontdrive] = a;
		motor[rightbackdrive] = a;
		motor[rightfrontdrive] = a;
}
}


Using Justin’s kalman filter + a full PID loop on the gyro seems to work wonders, I haven’t had it drift terribly, and it is completely usable in game!

We are using easyc so the coding won’t help but is there way we can use it on easyc that would be great!

I don’t use easyC, but I would imagine the basic “logic” should be the same. Perhaps you can use it as a guide? I believe easyC even has a block that allows you to enter “c” code if that helps.