Im having trouble with this catapult code

#1

I am having trouble with this code here. Everything works fine except when i press b, the catapult doesn’t go down. I’m not sure how to fix it. Any thoughts?

while (1){
{
{
//Drive Control
//Set the left and right motor to spin forward using the controller Axis values as the velocity value.
//Since we are using a single joystick, we will need to calculate the final volicity for each motor.
Left.spin(vex::directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value()), vex::velocityUnits::pct); //(Axis3+Axis4)/2
Right.spin(vex::directionType::fwd,(Controller1.Axis3.value() - Controller1.Axis4.value()), vex::velocityUnits::pct);//(Axis3-Axis4)/2
BackLeft.spin(vex::directionType::fwd, (Controller1.Axis4.value() + Controller1.Axis3.value()), vex::velocityUnits::pct); //(Axis4+Axis3)/2
BackRight.spin(vex::directionType::fwd,(Controller1.Axis4.value() - Controller1.Axis3.value()), vex::velocityUnits::pct);//(Axis4-Axis3)/2
}

           //BallLoader Control
        if(Controller1.ButtonL1.pressing()) { //If buttonl1 is pressed...
               //...Spin the motor forward.
            Loader.spin(vex::directionType::fwd, 50, vex::velocityUnits::pct);
        }
        else if(Controller1.ButtonL2.pressing()) { //If buttonl2 is pressed...
            //...Spin the motor backward.
            Loader.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
        }
        else { //If the the buttons are not pressed...
            //...Stop the motor.
            Loader.stop(vex::brakeType::coast);
            {
                {
    if (Controller1.ButtonR2.pressing())
    {
        Catapult.spin(vex::directionType::fwd, 100,vex::velocityUnits::pct);
    }
    else if (LimitSwitch.pressing())
    {
        Catapult.stop(brakeType::hold);
    }
    if (Controller1.ButtonB.pressing())
    {
        Catapult.spin(vex::directionType::fwd, 50,vex::velocityUnits::pct);\
       }
     }
   }
 }

}
}

0 Likes

#2

Is the Catapult pressing the LimitSwitch, when you’re wanting the B button to make it go farther down? With the previous code, the B button wouldn’t do anything when the Limit switch was pressed.

The adjusted code below, you’d can hold down the B button and it would continue even when the limit switch is pressed. I assume this would allow the catapult to engage the way you want.

The code had a lot of extra brackets that you won’t need.

while (1)
{
	//Drive Control
	//Set the left and right motor to spin forward using the controller Axis values as the velocity value.
	//Since we are using a single joystick, we will need to calculate the final volicity for each motor.
	Left.spin(vex::directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value()), vex::velocityUnits::pct); //(Axis3+Axis4)/2
	Right.spin(vex::directionType::fwd,(Controller1.Axis3.value() - Controller1.Axis4.value()), vex::velocityUnits::pct);//(Axis3-Axis4)/2
	BackLeft.spin(vex::directionType::fwd, (Controller1.Axis4.value() + Controller1.Axis3.value()), vex::velocityUnits::pct); //(Axis4+Axis3)/2
	BackRight.spin(vex::directionType::fwd,(Controller1.Axis4.value() - Controller1.Axis3.value()), vex::velocityUnits::pct);//(Axis4-Axis3)/2
	
	//BallLoader Control
	if(Controller1.ButtonL1.pressing()) { //If buttonl1 is pressed...
		//...Spin the motor forward.
		Loader.spin(vex::directionType::fwd, 50, vex::velocityUnits::pct);
	}
	else if(Controller1.ButtonL2.pressing()) { //If buttonl2 is pressed...
		//...Spin the motor backward.
		Loader.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
	}
	else { //If the the buttons are not pressed...
		//...Stop the motor.
		Loader.stop(vex::brakeType::coast);
	}
	
	if (Controller1.ButtonR2.pressing())
	{
		Catapult.spin(vex::directionType::fwd, 100,vex::velocityUnits::pct);
	}
	else if (Controller1.ButtonB.pressing())
	{
		Catapult.spin(vex::directionType::fwd, 50,vex::velocityUnits::pct);
	}
	else if (LimitSwitch.pressing())
	{
		Catapult.stop(brakeType::hold);
	}
}
0 Likes

#3

You can post your code with Syntax Highlighting to make it easier to read:

0 Likes

#4

Thank you for your help!

1 Like

#5

Just FYI, this isn’t the category to post this in. Try #edr-technical-support

0 Likes