How to make VEX IQ robot drive straight with VEXcode blocks

Last Updated: January 16th, 20211.9 min readCategories: VEX IQ, Robotics, Scratch

Mini Series – How to make a reliable VEX IQ programming skills with VEXcode blocks

Robot skills challenge in VEX IQ Challenge (VIQC) consist of Driving Skills Matches, which will be entirely driver controlled, and Programming Skills Matches, which will be autonomous with limited human interaction. In the programming skills matches, beginner teams have always struggled with unreliable autonomous routine. I have heard the same lines over and over again

This worked yesterday.

It worked at my home!

Kids are very frustrated with the unreliable autonomous routine, and choose to give up on autonomous and simply focus on Driving Skills Matches, because it’s more fun and under their control. 80%+ of VEX IQ teams in worlds don’t have or don’t know how to have a reliable autonomous program.

VIQC skills ranking with low programming skills highlighted

Latest VEX IQ Middle School World Skills Standings leader board, some of the top 50 teams in world (total 618 teams on the board) still suffer from unreliable programming skills code.

We have decided to publish a mini series of tutorials to help the teams to improve their Programming Skills Matches score.

839 coding tutorial

Drive straight code snippet for VEXcode Blocks.

VEXcode blocks drive straight

Create a my block for driveStraight. We are implementing a simple PID controller (technically, this is only a P controller). PID (proportional–integral–derivative) controller is a control loop mechanism employing feedback that is widely used in industrial control systems and a variety of other applications requiring continuously modulated control. If you would like to know more PID controller’s algorithm, you can start with the Wikipedia page. Matlab has a great video tutorial published to explain PID control on YouTube.

Calling driveStraight my block

VEXcode blocks call drive straight

At the beginning of the program, make sure you set the motor brake mode to brake and calibrate the gyro for 2 seconds. Then you can simply call driveStraight we created earlier.

  • Distance: 500 – how far you want your robot to travel in degrees
  • Heading: 0 – target heading of the robot
  • Velocity: 60 – how fast you want your robot to travel, we recommend to start slow like 50 – 70 before you go full speed at 100. But it also depends on your robot’s gear ratio.
  • Kp: 2 – proportional control value, the bigger the number, the faster the robot correct itself, but if the value is too big, correction will overshoot, and you will see robot zigzag. Kp = 0 means there is no correction applied.

How to make a reliable VEX IQ programming skills continues with part 2 – Precise turn with VEX IQ gyro

Share This Story!

4.3 3 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments

Wow! This helps a lot with my program! Thanks!


Thanks for this wonderful tutorial. My question is how do you set up your drive? It is not using the standard set up? Also does this work with 2 and 4 motor drive?


Do you recommend to use only proportional control from PID, or the whole proportional, integral, derivative system from PID? My team is using the Razorbill robot from Ben Lipper’s channel.


That really helps, thank you so much! We were just wondering because we saw your turns for autonomous at the start of a Vex IQ Rise Above match in this video: at 0:34. We were wondering how we could do that. Do you have any suggestions on how to make that work?


How would you run both motors at the same time? Also, do you recommend to use Vexcode or RobotC for programming?


That really helps, thank you! I was trying to get both motors to run at the same time, but they would only run one at a time. Attached is an image of something similar to what I was trying. So I ran my left and right motors sequentially like that, but only ran one at a time and not both at the same time. Do you have any suggestions on how to get that to work?


Okay, I have tried it and it worked! I want to really thank you for your help because our team was having so much trouble with programming and just gave up to focus on driving. We can now start programming again and the sky’s the limit. Thank you!

Brad Sweet

I inputted the image attached. sometimes it goes straight and stops. Usually it goes straight and then does 360 turns forever. Help

Brad Sweet

Thank you, it now goes straight and stops.
Next question, how do I get it to back up, NOT turn and go forward?

Brad Sweet

Thank you. It works. I think I tried every combination but that one last night!!!!!!!!

Jason G

Great article, thanks! So we’ve looked at this code sample and we understand it at a high level. We got it to run and it appears to do a good job. Two questions.
1. When trying to find a KP value for your robot, what are the usually increments you test in? And what is a general range to test between? So if we start with KP of 2, should we test in increments of .25, .5, 1,ect? Also, what is the general range? 0-2, 0-5, 0-10, 0-100, ect? Just trying to set a baseline for how and what to test.
2. As the velocity value increases, will the KP value change as well? Or your KP value will always be the same regardless of velocity? In our test, it seemed more accurate at 50% velocity with a KP value as 1, but when increasing the velocity to 80%, it didn’t feel like it was doing much. So trying to understand if velocity increases, is there a correlation to the KP value going up or down.

Jason G

Thanks Daniel!

one more question. As velocity increases, does the distance value decrease as well? I tried to look up ‘motor clicks’ as it was mentioned in the video to see how that corelates to the distance, but couldn’t find anything. We ask as we up our velocity, it seems like the distance increase a little bit. Thanks?!



Recent Tweets

Join Our Champion Team to Start Your STEM Journey Today

Become Part of Caution Tape to Dream the Impossible.

Thank you for your message. It has been sent.
There was an error trying to send your message. Please try again later.

Partners, Sponsors and Features