Need help with inertial turning

Hi, whenever I used the example code from vex to turn right it never works. I found some other code from another thread but that also gives me issues. My team is running an x drive can someone help me out. I have attached a pictureScreen Shot 2020-10-17 at 12.03.09 PM of my code and the problem

Yeah so it seems like you can’t identify a function inside the autonomous section. My advice would be to take it out and stick it above the void autonomous(void){} function and call it and see if that works.


void turnRight (double degree, double speed) {
// stuff here

void autonomous(void) {
turnRight([insert degree argument here], [insert speed argument here]);

Hope that helps!


but this is in a comp template anything above the void autonomous won’t work…

That’s not true at all. The competition template acts just like any other project you can define variables and functions outside of the autonomous function and they will work if done correctly.


also what do I put in the //stuff here
do you guys a working example per se

[quote=“Str0ngkatTh1rteen, post:2, topic:85579”]
void turnRight (double degree, double speed) {
// stuff here

is it just my motors?

When tackling a programming problem, a common first step is to write out the steps you think are necessary to solve the problem. This is not intended to be done in the programming code, but should be more human readable. Something like:

  1. Turn on Left Motor
  2. Turn on Right Motor
  3. A miracle happens
  4. Stop Left Motor
  5. Stop Right Motor

Since you seem new to programming, try this out. Also, take some time and learn the basics of C++ from a site such as: or YouTube videos.

Vex Code comes with many basic Tutorial/Example programs. Learn from those for specific ways to use the Vex API.

Once you have these under your belt, you should have no trouble writing a function to turn the robot to the right.

Later, you’ll want to be able to turn to the left. Some people make 2 functions - one for left, one for right, while other’s have a single function that can turn in either direction. Think about which style makes the most sense for you. Think about why you would chose one approach over the other.


By //stuff here, I mean all the commands inside the turning function you already have. I didn’t want to copy it all down from the image you attached, which is why I subbed it with //stuff here.

Some tips

1 - Formatting
Right-click next to your code, and it’ll open up a little menu box. Hit “Format Document” and it’ll indent everything perfectly for you. It’s a super-useful tool that’ll make your code a little easier to read.

2 - Outlining before programming
As @Mentor_355v said,

This is especially useful when you get into some of the more complicated stuff in programming later. You can write in comments what the steps are, then go in and fill in the steps with the actual code that tells the robot how to do those steps.


void spinSeconds(int seconds) {
// Step 1: Turn on the motors

// Step 2: Wait for however many seconds were passed into the function
vex::task::sleep(seconds * 1000); // converting from milliseconds to seconds

// Step 3: Stop the motors

3 - Commenting your code
Make sure to comment your code correctly! It’ll help Future You, when you’re looking back through your code and might not understand something. Trust me, it’s worth the time to add a little note.
You can add a comment by typing // and then your note. That’s called a line comment, and it only works for that line. You can’t type that on one line and then type your note on another line without the two slashes.


// note here

If you want to do a comment that spans multiple lines, use the block comment. You can add that comment by typing a /* at the first line you need the block comment to span, and then */ on the last line you want it to span. Everything between those two asterisks and slashes will be commented out.


this is still part of the comment!

Hope that helps!