Coding an Autonomous in Vex Coding Studio

I feel dumb asking this question, however, I am new to coding and my autonomous is not working. I have a competition coming up very soon and not much time to test so this is urgent. The problem with my autonomous is that the program reads it line by line which instead of having multiple actions done simultaneously, it instead does each command individually. So, for instance, to move the actual robot, the front right motor spins to the degrees I have it set at, then the back right motor, then the left front motor and so on and so forth. How do I get the autonomous to run multiple commands simultaneously? (I want to be able to spin my intake and collect a ball while the robot is moving, then turn and shoot the ball, etc.)

This is an example of my code:
void autonomous (void){
Intake.rotateFor(3,timeUnits::sec,100,velocityUnits::pct);
LeftDriveFront.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
LeftDriveBack.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
RightDriveFront.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
RightDriveBack.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
task::sleep(1000);
}

1 Like

For the first four motors you want to use startRotateFor that way the code won’t stop at that line it just starts it then moves on.

blocking and non-blocking - by default all the rotateFor are blocking … they wait until they have finished their tasks… try

void autonomous (void){
Intake.rotateFor(3,timeUnits::sec,100,velocityUnits::pct);
LeftDriveFront.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct, false);
LeftDriveBack.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct, false);
RightDriveFront.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct, false);
RightDriveBack.rotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
task::sleep(1000);
}

this way the motors will all start their tasks, but wait until RightDriveBack has completed.

Just to make sure I’m not doing something wrong, you could accomplish the same thing by using startRotateFor instead of rotateFor right?

You have it right

just giving an example of how to make the code work with the same functions the OP used.

1 Like

gotcha thanks

I actually wished that VCS would not have so many functions in their API but instead on work on simple things - like say CTRL-S to save your project… Not asking for versioning, but simple common sense implementation of develop GUI.

Honestly, I feel you. IDK if anyone else encounters this issue either but when you use THEIR competition template, it doesn’t even compile the code. Like it’s very iffy, one minute it compiles, the next minute even after I didn’t touch the code, it doesn’t compile and it gives an error on their line of text then I save and restart the application and it works perfectly…

I was going to do this but haven’t gotten around to testing it on the field. One more question, lets say I wanted to condense the code and make each movement a procedure. (when I call the procedure it runs the set of commands). So, lets say I get the exact degrees needed for my robot to get from one tile to the next and instead of rewriting it over and over again, I simply call the procedure instead. How would I set it up? In robotC it would be something like:

void DriveTrain (int x);{
LeftDriveBack = x;
LeftDriveFront =x;
RightDriveFront = x;
RightDriveBack = x;
}

Except of course the motors didn’t have built in encoders. But instead of having to call each motor, I would simply call Drivetrain(127) and it would move the entire robot forward. How would I do something similar to that but with exact measurements?

Our teams do something like:
driveRotateFor( double count) {

LeftDriveFront.rotateFor(count,rotationUnits::deg,50,velocityUnits::pct, false);
LeftDriveBack.rotateFor(count,rotationUnits::deg,50,velocityUnits::pct, false);
RightDriveFront.rotateFor(count,rotationUnits::deg,50,velocityUnits::pct, false);
RightDriveBack.rotateFor(count,rotationUnits::deg,50,velocityUnits::pct);
// put delay here to let robot settle

}

then they have another abstraction for converting distances to rotations, ditto for turns degrees to rotation.

Makes it easier for teams to write a plan then implement It, test it on field - measure offsets.

Don’t you need to put a while(1) after the void thing in order for the auton to work?

no you don’t - you might just run through your routine once…

In user control it is important to maintain control of the robot for as long as is needed.

How did you define the intake? I’ve been struggling with that.

You can instantiate the intake the same way you do for any motor and you can create a helper function to simplify your code. What coding platform are you using?

(Also, this thread is so old. I’ve come such a long way in just 9 short months, wow.)

1 Like