Hey everyone, I’m working to program a catapult and have some questions.
The catapult is powered by one motor, and is built on a slip gear. There is a limit switch placed so it is triggered right before the slip gear releases the catapult; so it is basically extended fully back. Basically like every catapult design out there right now.
I’m looking to code it so in matches, the catapult is fully back, at the limit switch, by default. Only when a button (L1) is clicked, it moves back further, engaging the slip gear, shooting the disks, and returning back to where it was before.
So far I have coded parts of it [clicking the button so the catapult stops at the limit switch], but I don’t think I am on the right path. If anyone can help me out please lmk. Thanks
Sounds like a similar setup to what many users used in the IQ game last year. Review this post that includes a vexcode file on one way of coding a catapult.
Press button - spin
Spin until a sensor is actuated
Stop
It is now “loaded”
So if you press the button again, the stop sensor is already pressed, so you have to ignore it for X seconds (enough to get off the sensor but before it gets back around to press the sensor again)
Therefore our code is more like
Press button - spin
Wait 1 second (or enough to get off the sensor)
Spin until sensor is actuated
Stop motor
When you talk about the wait/timer, would that basically mean the motor is moving forward, then backward again? Not quite sure what you mean, specifically with the limit switch
You have a pretty good start. What I do is when my button is pressed, I spin the motor for a fraction of a second–just enough for the slip gear to disengage–then I run the conditional.
Just as an update, I came up with this based on some logic and I think it makes sense. Lmk if not
if (!limitswitch.pressing()){
cataspin();
} else {
if (Controller1.ButtonL1.pressing()){
cataspin();
} else {
Catapult.stop(brakeType::hold);
}
}
}
Essentially the catapult is always spinning, unless the limit switch is clicked. When the limit switch is clicked, it stops. But, if L1 is clicked, it spins more, shooting it.
You may want to make your button the first option so it takes precedence over all other modes. The limit switch could interfere if you were trying to manually fix an issue. A reverse option might be helpful too.
if (!limitswitch.pressing()){ //<-- First priority
cataspin();
}
The limit switch is the first priority and will ignore the driver’s buttons if the switch is not pressed. This means if the catapult jams during a cycle, the driver can’t fix the issue. The limit switch is not pressed so the motor continues to run and the buttons are ignored.
In the pseudo-code example below, the driver buttons are first priority and if they aren’t pressing, then the automatic cycle continues to assist the driver.
if (Controller1.ButtonL1.pressing()){
Catapult.spin(forward ...
}
else if (Controller1.ButtonL2.pressing()){
Catapult.spin(reverse ...
}
else if (!limitswitch.pressing()){
Catapult.spin(forward ...
}
else {
Catapult.stop(brakeType::hold);
}