1. last week

    tanigross

    Jan 3 61300A

    Can someone explain why the motors LeftBackDrive and LeftMiddleDrive don't run when Button L1 is pressed?

    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

  2. 7517H

    Jan 3 Malvern,PA 7517H
    Edited last week by 7517H

    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. tanigross

    Jan 3 61300A

    I meant when button R1 is pressed lol

  4. tanigross

    Jan 3 61300A

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

  5. tanigross

    Jan 3 61300A

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

  6. 7517H

    Jan 3 Malvern,PA 7517H
    Edited last week by 7517H

    @tanigross I meant when button R1 is pressed lol

    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. tanigross

    Jan 3 61300A

    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. 7517H

    Jan 3 Malvern,PA 7517H

    Can you post the most updated code then?

  9. tanigross

    Jan 3 61300A

    #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. callen

    Jan 4 Braintree, MA, USA
    Edited last week by callen

    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. tanigross

    Jan 4 61300A

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

  12. tanigross

    Jan 4 61300A

    This is the latest function

  13. callen

    Jan 4 Braintree, MA, USA

    What does the rest look like now?

  14. tanigross

    Jan 5 Answer 61300A

    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

 

or Sign Up to reply!