Limitswitch coding help

I am trying to code my team’s catapult using a limitswitch, and i do not know if i am doing anything wrong.
I have a callback after autonomous at the bottom of the competition template which calls to a function that sets a variable to true, which is later checked in the driver control code using an if statement, which will stop the code if true. There is also a callback similar to this for a button so the if statement checks if the button press bool is true and if the limitswitch press bool is true and then only will it spin the catapult. And then i have an else statment that says to stop the catapult.

If you send your code it will be easier to help you fix it.

1 Like

At the moment I do not have the copy of the code, sorry! I can send you some pictures as soon as I have it through. Is there anything that seems wrong upon my description?

any help would greatly appreciated !!!

The snippets give us some insight but it would be better if you cut / paste all of the code between two sets of three of single quotes (```)



///Then it formats the code properly


What is your expected behavior?(what do you want the code to do) I recommend telling the motor to spin to a position for a cata.

We had a task for the cata that the motor spins unless touching a limit switch and not a button pressing. This may also be fine to do in the driver loop. There was a little more to it but that was the general concept.

1 Like

hello everyone, I figured out the problem. thanks for all of the help. the issue was the way I wrote the if statement that checked if both variables were true. there was some error in that, so I changed it to an if statement inside of an if statement so both things would be checked and then an else statement to stop the catapult.

You can probably just check motor degrees instead of adding the additional complexity of a limit variable.

this is what I had in mind originally, but it was inconsistent as the degrees changed a lot, and caused a lot of variability in the stopping position of the catapult. this is why we chose to do a limit switch, as it would always stop at the command of the limitswitch and there wouldn’t be any change in the stopping position.

Ok. Maybe could program it to monitor watts then. Switch might still be the go-to solution, but checking the watt usage could be a fun exercise.