Coding Help


#1

Can someone explain why the motors LeftBackDrive and LeftMiddleDrive don’t run when Button L1 is pressed?
Screen Shot 2019-01-03 at 5.14.00 PM.png


#2

This might be a silly mistake, but you currently have your intake running when button L1 is pressed.

Change the intake.spin command to LeftBackDriveSpin and LeftMiddleDrive and it should work.


#3

I meant when button R1 is pressed lol


#4

No I want the code in the function goToGear to run when R1 is pressed


#5

When R1 is pressed i want it to call the function which then turns the wheels


#6

Okay then. Currently you have:

LeftBackDrive.rotateFor(10,sec);
LeftMiddleDrive.rotateFor(10,sec);

Change it to this:

LeftBackDrive.rotateFor(10,timeUnits::sec);
LeftBackiddle.rotateFor(10,timeUnits::sec);

I’m not sure if this will fix it, but hopefully it will.


#7

No, it doesn’t, I think the issue is that the function might be getting called many times because I added Brain.Screen.Print to it and it prints something on the brain like 20 times


#8

Can you post the most updated code then?


#9

#include “robot-config.h”

void goToGear(){
Brain.Screen.print(“HI”);
LeftMiddleDrive.rotateFor(10, timeUnits::sec);
LeftBackDrive.rotateFor(10, timeUnits::sec);
}

int main() {
while(1){
LeftMiddleDrive.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
LeftBackDrive.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
RightMiddleDrive.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);
RightBackDrive.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);

    if(Controller1.ButtonL1.pressing()){ //INTAKE
        Intake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
    }
    else if(Controller1.ButtonL2.pressing()){ //INTAKE
        Intake.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
    }
    else {
        Intake.stop();
    }
    
    if(Controller1.ButtonUp.pressing()){
        Arm.spin(vex::directionType::fwd, 100, pct);
    }
    else if(Controller1.ButtonDown.pressing()){
        Arm.spin(vex::directionType::rev, 100, pct);
    }
    else {
        Arm.stop();
    }
    
       
    Controller1.ButtonR1.pressed(goToGear);
    }

}

#10

Controller1.ButtonR1.pressed(goToGear);

should be before the while loop, not inside of it. Once you call it it creates a new thread that watches for the button and uses goToGear. I’m not positive about how such a thread would interact with another version of itself, but you may be trying to create an infinite number of identical threads all watching for the same button to be pressed and all trying to do the same thing when they see it, and I know VEXos cannot handle that many threads.

Also, it doesn’t look like you’ve got using namespace vex; in your setup base on your use of vex::… all over the place, but you’re writing timeUnits::sec without vex:: attached to it.

Finally, rotateFor is blocking. Is that what you want? You’ve got it printing to the screen, then running LeftMiddleDrive for 10 s, and when that drive is done you’re running LeftBackDrive for 10 s. If you want them simultaneous, make sure you add the optional waitForCompletion Boolean as false at the end of your first rotateFor call.


#11

Now it’s printing on the brain once, but it is not running the function of the motor


#12

This is the latest function
Screen Shot 2019-01-04 at 1.42.31 PM.png


#13

What does the rest look like now?


#14

I figured it out, it wasn’t working because I also set up a button to run the intake motor so the function wouldn’t run it also