VexCode IQ Autonomous Driving with Left and Right Motors and Gyro

Please refer to the program below…we are not able to get the motors to run.
Without the ‘set BotDistance’ and the ‘while’…the motors run.
Trying to use the Gyro to make the robot go straight and use the Left and Right Motors rather than a Drive Train.

What does the brain say BotDistance is? You may need to reset the encoders when you start this part of the code.

You should be recalculating botdistance in the while loop.

Finally, the only thing you are telling the motors is to go forward. So they should always go forward with this code as this is written because you never tell them to stop. If you want the bot to stop at any point, or ever, you need to give the motors a stop.

1 Like

BotDistance is 0 before we get into the ‘while’ loop. It seems like the code is not progressing into the ‘while’ loop.
We assume that the bot should stop moving forward when BotDistance exceeds 120. Tried with BotDistance recalculation in the ‘while’ loop…still cannot get the Bot to move ahead.

Do you have other block sequences also controlling the same motors ?


You are absolutely right…had a bunch of left over blocks that were probably conflicting. Our bad !!!

Gyro sequence does not seem to work well for long distances. Bot is tending to go right. Any suggestions ?

If you are still using the code in your original post, It’s not really using the gyro to do anything at all. You only tell the motors to go forwards, you would need to adjust motor speed to keep the robot driving straight.

1 Like

GyroTest.pdf (6.2 MB)

GyroTest.iqblocks (16.4 KB)

You might try something like the attached program. It doesn’t work, as is, but it gives a bit of an idea as to what your approach might be. There are probably lots of different approaches to this problem. I have seen some that look promising. They look at the amount of error, then apply a correction that is proportional to the error.

The program I have attached overcorrects. If there is a little bit of error, it magnifies it.

I designed a 4 wheel bot, where the front wheels are steered, and the rear wheels are both driven on the same shaft. I think my heading straight program works, but it was difficult to test.

Have fun,

1 Like

Sorry, I tried to write the program in too much of a hurry. The attached program injects an error, and you can see the bot correct the error. I set the right speed greater than the left speed, so the bot tends to drift to the left.

GyroTestOne.iqblocks (16.1 KB)

1 Like