Code doesnt work With While Loops

Whenever I try to use while loops the robot farts out and decides to not let anything work (Drive system, arm motors, sensors, ect.). But when I take the loop out everything is fine and dandy. I have the while loop set to always run (constant false to a stop if true) and I have a 50ms timer. I’m trying to use a button latching system like it has in the example code. I figured out a way around it with globals but I’m afraid that when I put in the autonomous it won’t work. Any suggestions?

Loops in the teleop section of the code will not work. Teleop already loops at speeds between 15 and 50 ms (depending on the comms from the driver station and your code). Putting a loop in means that teleop has to wait to loop until your loop is complete. That will cause all the watch-dog safety timers to trip because teleop will take too long.

That is in direct opposition to autonomous independent, which only runs once and CAN have loops in it.

That’s why I’ve never like having independent - it’s a distinctly different programming structure than what happens in teleop and causes confusion.

Alright thanks I’ve been wondering about that. As for latching writing the opposite of the global value when the button is true works just fine.

Loops in periodic tasks run in parallel with the rest of the code. You can put your while loop there.

for button latching like the example you cited, you can do one of two things. if you only need to latch one button, go to the teleop front panel and drag two Boolean controls and two Boolean constants onto the front panel. I recommend naming the controls something like ‘previous button value’ &‘last latched value’ and the indicators ‘button value’ & ‘latched value’. in the upper right corner of the front panel, right click on the vi icon and choose show connectors. hover over an empty box on the left side until the wire spool shows up,click the box and then click one of the controls, repeat for other control. then do the same for the indicators on the right side of the vi. now in the teleop block diagram you can recreate the case structures from the example but wire the shift registers on the while loop to the controls and indicators. finally in the robot main vi right click on the while loop and ‘add shift register’(twice) then wire the shift registers to the new terminals we created on the teleop vi. this gives your latching function access to the main loop. 2nd option check out the typedef tutorial on FRCMastery.com, it is similar but way more useful for multiple reasons.