Catapult Drawback Issue

First, I did use the search bar and couldn’t find something specific to my problem.

My issue is, at the beginning of autonomous I want the catapult to spin forward until it hits the limit switch AFTER it fires. So, it would need to start pressing the limit switch and then spin until it hits the limit switch.

This is what I have so far, but it just doesn’t do anything, even when it isn’t contacting the limit switch. I need guidance to help resolve this issue, as for I am not great at programming.

You’d need to put your lines 81-86 inside a while loop. Think about what the exit condition of that while loop should be. You may also want to think thru the logic of the if statement and what the LimitState boolean is actually doing, compared to the Limit.pressing() call.


This was similar to a problem I had in VIQC Pitching In, back in my IQ days. I added a delay so that it would spin the catapult, and then after 0.3 seconds, I started checking to see if the catapult was down. That gives the catapult enough time to shoot before it starts checking again.

In this case, I think the problem is that you are using “else if”. It checks, sees that LimitState is false, and ignores the “else if” entirely, so the catapult would never stop. Try replacing the else if statement with just a regular if statement.


Your code needs a while loop around it if you want it to run more than once.


Ok, so, I need to put it in a while loop? I only want this to run once.

I can exit the while loop when LimitState = true right?

Should I add a second if statement? It would set LimitState = true if the limit switch is pressing.

if (limit.pressing())
  LimitState = true
  LimitState = false
1 Like

Technically you don’t even need LimitState because you can just have

if (!limit.pressing())...

since you are essentially just setting the value of LimitState to limit.pressing().