Sensor Issue

We have a catapult that is supposed to set with a limit switch but it wont. We’ve tried everything, replacing the sensor, manually pressing it, changing the port, changing where the code is. Nothing works. Heres the code:
cat.spin(FORWARD)
while not cat_set.pressing():
pass
cat.stop()
cat_set is the name of the limit switch and cat is the name of the motor. Please help!

This syntax doesn’t look like C++ so correct me if I’m wrong, but it looks like cata.spin is outside of the while loop, where it should be inside. I would caution you that this is blocking code that will prevent other code in the same thread from running while the switch isn’t pressed. You might want to use an if statement instead.

This is my catapult code
Screenshot 2024-02-14 7.28.30 PM

Well, it’s python, just not pasted into the post correctly.

It’s fine for spin to be outside the while loop.

try using sleep rather than pass inside the while loop.
check the limit switch is working using the V5 devices screen.

2 Likes

Ah, only used Python for stats stuff so I’m not used to seeing Vex objects. If this code is in the main driver control while loop, this isn’t a great way to do this (assuming the while loop is purely to block the code until the cata is pulled back all the way). It should work though.

I think a modified version of this would work for my cata code but we dont have a ratchet and we need it to spin to the limit switch at the begining of the code.

It works according to the vex devices page