Help coding a catapult without limit switch

Hi. I’m new to robotics and I need help coding a catapult without a limit switch (if that’s even possible). We have a vision sensor if that could work. No one at my school knows the programming and we have a competition on this Saturday. From what I’ve learned so far, I would assume the code looks somewhat like this:

if (Controller1.ButtonR1.pressing()){
catapult.spin(forward, 100, vex::velocityUnits::pct);
else if (Controller1.ButtonR2.pressing()){
	catapult.spin(reverse, 100, vex::velocityUnits::pct);
else {

You could use the built-in motor encoders, which work well with a gear ratio in a catapult. This is how I did it (supplanted by an optical sensor):

if controller_1.buttonUp.pressing()==True:
            while optical_8.is_near_object()==False and ready==False:
                cata.spin(FORWARD, 50, PERCENT)
                cata.spin_for(FORWARD, 70, DEGREES)
                cata.set_position(0, DEGREES)
        if controller_1.buttonL1.pressing()==True:

Right now it freezes the robot during the “pulling back” part, but that can be fixed.

I will check with my mentors to see if they still have any optical sensors left. Thank you ^^

Me and my team use cata, and we decide to manually put down the catapult using almost the same code that you’ve shown. However, the difference is that we have another driver who uses a partner controller, and that teamate puts down the catapult while I search for more disks, making a respectable rhythm without sensors/ extra code.

You could try bumper or rotation sensor, those works too