Driver Control Issues

I am trying to get my robot to turn to the angle “Goal” simultaneously while driving when R1 is being pressed. Right now I can only do one at a time. Any suggestions? I am currently using a two motor drive if that helps.

while (1) {
if (Controller1.ButtonR2.pressing()){
Brain.Screen.print(Goal);
}
if (Controller1.ButtonL1.pressing()){
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
if (Controller1.ButtonR1.pressing()){
RightMotor.setVelocity(100,percent);
LeftMotor.setVelocity(100,percent);
RightMotor.spin(reverse);
LeftMotor.spin(forward);
waitUntil(OrientationDegrees > Goal - 1 or OrientationDegrees < Goal +1);
RightMotor.stop();
LeftMotor.stop();
}
RightMotor.spin(forward, Controller1.Axis3.value() - Controller1.Axis1.value(), velocityUnits::pct);
LeftMotor.spin(forward, Controller1.Axis3.value() + Controller1.Axis1.value(), velocityUnits::pct);

You should probably use something else that isn’t the waitUntil function. The wait until, obviously, waits until the rotation finishes before allowing any input from you. You can probably do spinFor, and make sure you put “, false” at the end to disable wait for completion to allow you to run it simultaneously.

Is there any way I could use a false command, but keep it in absolute terms, such as orientation?

I would look into somthing called multithreading, there are a lot of posts on the forum about it and it looks to be the solution you are looking for

1 Like

Is multi threading the same thing as multitasking?

Yes,

I personally use threading, but there is no difference

I’ve been experimenting with something like this but it just keeps twitching around.

bool enableAim = true;

int Aim(){
while (enableAim){
RightMotor.setVelocity(100,percent);
LeftMotor.setVelocity(100,percent);
RightMotor.spin(reverse);
LeftMotor.spin(forward);
waitUntil(OrientationDegrees < Goal - 1 or OrientationDegrees > Goal + 1);
LeftMotor.stop();
RightMotor.stop();
vex::task::sleep(20);
}

return 1;
}

void usercontrol(void) {
vex::task Odom(Odometry);
while (1) {
if (Controller1.ButtonR1.pressing()){
vex::task LockOn(Aim);
}
RightMotor.spin(forward, Controller1.Axis3.value() - Controller1.Axis1.value(), velocityUnits::pct);
LeftMotor.spin(forward, Controller1.Axis3.value() + Controller1.Axis1.value(), velocityUnits::pct);