Code check ASAP

Hi CD, i wrote some code for teleop but i dont have te hardware to test the code because the electrical team is putitng it together and i dont think i will get much time to test after its put together becasue we have PD day friday and thursday its parents nights so we only have till thursday and the electrical team isnt done. Can someone just see if this code will do this:

When button for home is tapped ones, the motor will spin in the negative direction until the home switch comes on and then stops. Same goes for all the other buttons. But what i am wondering is, will it do it if i tap it ones, or will i have to hold it? tnx

teleop.doc (85 KB)


teleop.doc (85 KB)

With that you would have to hold it.

During every iteration of teleop, your code would set the motor to .4, then if the button was pressed, complete the true case. If the button is not pressed during any one iteration of teleop, the false case will be executed.

What do i have to change to make it work only by pressing it once? I do remember there was a extra library you had to download it was a little green thing, i remember in one of the Ben Zimmer’s video, but i cant find it. Argh.

I don’t use LabView myself, so I am not sure on what the best way to do it is, but here is how I would do it in a text-based language:

Create a boolean called “homeHasBeenPressed” that is initially false.
When the home button has been pressed, set that boolean to true.

if (homeHasBeenPressed)
doStuff();

I’ve always had a bit of a distaste for LabView’s lack of variables, but you should be able to take the above and apply it to LV without too much trouble.

Here’s an example of an action only once per button press

Here’s an example of A toggle button

The feedback node used for these can be found on the Programming -> Structures palette.

@Mark

Does it matter if i use more than one node in teleop vi? like one node for each button on a joystick?

It doesn’t change the functionality. It is more a style issue and a diagram space tradeoff.

Greg McKaskle

I have another question, with the http://team358.org/files/programming/ControlSystem2009-/LabVIEW/ActionOnButtonPress.jpg
code, if i attach that to 3 buttons, button 1 , 2 and 3, if i want to go to position 3 but i accidentaly press 2 and then i suddenly press 3, will that override the code of me pressing the “2”? So basically will it do something different depending on the button press, even if i change it half way?

Whcirobotics

If I understand correctly, the last button pushed would win, immediately.

The “once per button press” doesn’t care what other buttons were pressed in the past unless you explicitly write the program to do so. The Button 3 code can do anything you want it to do, including changing things that the Button 2 code did.

Reminder: don’t put any long-running loops inside those “run once” cases. That would stall the Teleop vi and the motor safeties for things like your drivetrain will trigger, shutting down the robot outputs until the loop completes. If you use the buttons to start a sequence of events, either that sequence will have to be written as a state machine in Teleop, or you will have to implement it in the Periodic Task vi.