Code for Catapult Reload

Hi all, my team has a catapult and I have been working on a code to launch a ball and then bring the catapult back to a specific position and hold it there for a second to reload a ball and then shoot it again. Ideally this would all be done with one button. Confused about PID vs motor control and how to do this so let me know

Are you on cortex or V5? We’ve had has a PID build in just tell it to hold. However this is a bad idea.

Ultimately you should not have the motor hold it back in place because that’s a great way to kill your Motors. If you search around you’ll find a number of devices that will physically hold it in place once the motors get it almost there.

a ratchet my dude

Lol yes. I’m just sitting in the car in the middle of nowhere with my brain fried from the day.


+1 on a ratchet. In NBN we used a linear puncher with a ratchet on the drive gear. It can also be done with a catapult, at that point you should look at a sensor to determine when to stop the catapult. Either:

  1. Use an encoder on the drive shaft, determine how many encoder ticks it takes to get the launcher into position, and stop the motor once it gets into that position
  2. Use a sensor to detect when the motor gets into position right before it is released. With our linear puncher, we used a line follower to detect the presence of the plunger on its backstroke and stopped the motors when it was detected. That way, when we wanted to fire, we had to spin our motors for <.25 seconds to get the plunger to release and hit the balls. The same can be done with a light sensor or a limit switch.

If you need a quick and dirty solution, time can be used, but it will not be reliable. Battery voltage, friction in the launching system, and many other factors will change how effective it will be, and it may result in the launcher not being in firing position, or moving too far and firing prematurely.

catapult is pretty easy, stick a potentiometer on the swinging arm and just have it run until it gets to a certain spot, then cut the motor and the ratchet should be able to hold it somewhere close to that place, a little more and it should fire