I’ve got this code which sets the ‘shooter’ motor to full forward speed for 1 second when button 2 is pressed on joystick 1. Now, I had this within teleop, but it caused data loss due to the timing. So, as advised, I put it within the periodic tasks.
Now my issue is how do I tell teleop to use code within periodic tasks? When the code was within teleop, it functioned as expected (less the data loss), but when it’s inside periodic tasks, it doesn’t work at all.
Any help? Thanks.
This looks like the correct way to write it. The periodic should be running during all phases, even disabled, so if the Joystick 1 and Shooter are opened properly, I’d expect the code to work.
Have you checked the Diagnostics tab to see if errors are being returned. That may help.
The next thing I’d do is to place breakpoints or probes within the switch statement and in the teleop to see the point where it fails.
There’s one other thing needed to make it work. Teleop is inside a while loop. Periodic tasks is not. To get the same behavior, put your code inside a while loop in Periodic Tasks. The way it’s written now, it’s running once and then not running again.
No, I haven’t checked the Diagnostics tab, I’ll check tomorrow morning when I’ve got a cRIO under my nose.
How would I implement breakpoints and probes? From what I was told, the Driver’s Station will miss out on data if teleop doesn’t execute and return data within 20ms. Is there a way to have the motors run for a set time while making teleop think it’s fully executed? I’m not sending any data from this particular loop to the DS, so I’m wondering how to just exclude it.
Edit - @Joe Ross: So, can I move the Periodic Tasks block within the teleop while loop? I noticed that teleop was within a while loop, but thought nothing of the fact that periodic wasn’t!
Doh. Joe gets the prize. Make sure your code doesn’t run just once by putting it in a loop.
Keep the code in periodic tasks, but make sure that the joystick code is checked more than once. Put it in a loop and put a delay of 100ms or so to make sure the code doesn’t run faster than needed.
You place a breakpoint in the code by opening the diagram, right clicking and choosing to probe or breakpoint. As you mention, when if the robot stops responding, it will shutdown the I/O, but you can still debug the code. Generally, whenever debugging, start with the robot on blocks, and don’t remove it until you know how it will respond.
Doh indeed. Added a while loop with a 100ms delay.
Thanks guys, I’ll let you all know how it worked tomorrow!