Autonomous limit switch

I have been having trouble trying to make my autonomous work. The idea being that the shooter spin while our feeder will run three times. Going forward until hits limit switch then it will reverse until it hit seconds and stops, waits 2 seconds and repeats. Now I was able to get that to work in teleop just fine, I just can’t seem to simulate the button press and release correctly so it will continue to the limit switches.

Thanks in advanced

Autonomous (37.5 KB)

Autonomous (37.5 KB)

Autonomous Independent is not run 50 times a second like Teleop is.
You’ll need to add a While or For loop around your switch checks and motor set, so that the code keeps checking for them.

What’s the deal with that Time Delay inside the For loop at the start?
It basically waits 2 seconds, then waits two seconds again, then picks .6 for a motor speed, sets the motor then that’s it.
So the shooter motor and the feeder motor are left running until Teleop takes over.

Well what I am trying to do is simulate three button presses so that it would run through the feeding three times, but have not been able to do so. This is my first year using limit switches, so I am kinda lost for the autonomous part. The feed motor will stop when the second limit switch is pressed. Shooter right now is going to run until autonomous is over but I am not worried about that for now.

Aside from the loop problems, it seems like the First Limit Switch always starts off as pressed and will immediately override the .6 motor speed setting right in the beginning.
The motor needs some time to run before you start checking that first limit switch.

Also, make sure that the limit switch wiring matches the way it is checked in the code. Limit switches can be wired either Normally-Open (NO) or Normally-Closed (NC) and the code check might be reversed. I’ve had new electrical crew members wire one switch one way and the next switch the opposite, so double check. It’s best to run in debug the first time and probe the value you are getting.

I’d think this process would be better described as a flat sequence.

That 2000 ms delay will make the vi wait 2000 ms, then run. You should try setting a for loop to run 2000 times, and putting a 1ms delay in that loop. I don’t know about the limit switches, last time we ran a while loop in autonomous it didn’t work and we never investigated why, we just use for loops for everything in autonomous now.

The coment makes it sound as if you want to swap the motor set and the delay. The code is delaying 2000 ms, then setting the motor and immediately moving on. Put the motor set before or in parallel with the delay.

A while loop is nothing special. It is perfectly valid if you program it correctly and no worse than an incorrectly programmed for loop or other code.

Greg McKaskle

Thank you Mark that ended up working perfectly