code not working

We tried each of these sections of code separately and they worked then, but when we combined them they did not work. I did copy over the refnums to the build.vi for this project. Any errors that you see? please help!


other cases.GIF



other cases.GIF

This appears to be the diagram of the teleop VI. If that is True, as the comment says, you want your code to respond to the telelop message and complete within 20ms. That will be difficult when the Button 1 on joystick 3 is False and the code sleeps for 2 seconds. I’m not sure what you are resetting after 2 seconds, but you can either build a small state machine, storing the timestamp when the button was pressed, then leaving the state after two seconds even thought code returns quickly each time.

You can also put the code to set and reset in a parallel loop such as Periodic tasks. In there, you can wake up every 20ms or so, and if a global is set, you set the relay and DIO, then wait 2 seconds in the parallel loop, reset the relay and DIO and the global. Meanwhile, the teleop will read the button and set the global only.

Greg McKaskle

so, essentially if i just move the case structure with the delay out of the main case structure and just put it on its own, it should work? or do i have to reduce the delay down to just 20ms and have it repeat a bunch of times?
in any case, thanks

You do not want a 2 second delay in the teleOp code.

Either break it up into a larger number of 20ms teleop packets and use a state machine to keep track, or move it out and run it in parallel. The thing you’d do in the teleop is to quickly modify a global informing the other loop what state you want the motor to be in. By the way, don’t just move it outside the teleop loop, but completely outside the teleop VI.

Greg McKaskle

ok… so I just put it in main if i dont want to change how it works? if so, how does that work?

You could put it in Robot Main in a parallel loop, but the framework has a VI called Periodic Tasks which is pretty much what this is. So you could try to put it there and keep things organized by function.

Greg McKaskle