1. last week

    I need help with this code. It loads the catapult into the loading position so we can load balls but when we press the button to launch it it lags

    //launcher
    if (vexRT[Btn7D] == 1)
    {
    motor[port5] = 84;
    motor[port10] = 84;
    }

    }
    //set catapult
    if (SensorValue(potentiometer)<= 2200)
    {
    motor [port10] = 84;
    motor [port5] = 84;
    }
    else
    {
    motor[port10] = 15;
    motor[port5] = 15;

  2. 536Mentor

    Jan 9 Event Partner, V5 Beta Tester Appleton, WI 536

    One: Without seeing a bit more detail about how the code is supposed to trigger the catapult or the catapult mechanism itself, this is difficult to answer.
    Two, what is the purpose of setting the motors to 15?

  3. I use graphical but you may have somehow put in a wait or delay.

  4. I'm assuming that setting the motors to 15 is to effectively "hold" them in place while loading. I believe that your problem is that once the catapult reaches the potentiometer loading spot the motors are always being set to 15. So when you press Btn7D you set the motors to 84 but then they are immediately reset to 15 because of the potentiometer reading.

  5. callen

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

    Small change: second "if" to "else if." The problem is that if you press the button to go beyond 2200, the motors will be set to 84, no 15, no 84, no 15, ... That's because you set them with the button press and then immediately reset them with the else on the following if statement.

    //launcher
    if (vexRT[Btn7D] == 1)
    {
    motor[port5] = 84;
    motor[port10] = 84;
    }
    //set catapult
    else if (SensorValue(potentiometer)<= 2200)
    {
    motor [port10] = 84;
    motor [port5] = 84;
    }
    // hold in place presumably
    else
    {
    motor[port10] = 15;
    motor[port5] = 15;
    }

    You could shorten this using || to put both the button press and the pot value in the same line:

    //launcher & set catapult
    if (vexRT[Btn7D] == 1 || SensorValue(potentiometer)<= 2200)
    {
    motor[port5] = 84;
    motor[port10] = 84;
    }
    // hold in place presumably
    else
    {
    motor[port10] = 15;
    motor[port5] = 15;
    }
  6. @536Mentor One: Without seeing a bit more detail about how the code is supposed to trigger the catapult or the catapult mechanism itself, this is difficult to answer.
    Two, what is the purpose of setting the motors to 15?

    the potentiometer code is supposed to set the catapult to the spot where we load the balls. the code with the just button programs is to launch. Im using robotc by the way

 

or Sign Up to reply!