We have 4 buttons and each button controls the directions of 2 motors.
We have a case structure for each button where true sends a value (0.5, or -0.5) to the “Motor Set Output” and false sends a value of 0. We have run into a problem when we have multiple outputs set to a motor.
Attached is an image of the case structure for Button 1. We have tested it and it works. But we get lost when we try to add case structures for the rest of the buttons.
Read each button and put into a binary array. Then convert the array to a number. Your select case can then test for which number shows up. If you are watching four buttons, there would be a possible 16 cases. But since you probably only need to detect if one button is pressed, your test cases would be 1, 2, 4, 8. A very similar technique is being used in the sample line follower code that came with LabView this year.
If you need sample code, let me know. I will be at the lab tonight and can make it real quick.
If I really had to do something like this, I would make a subvi, using a typedef’ed enum. This enum would then be used on the case selector with the output options/code. This would allow future changes pretty easily.
I have to say that this would become hard to follow whenever extra code is added. It would also be very difficult to scale, and modify into the future. (Like on competition day)
Your Motor Output needs to be told which motor you are talking about.
You have not defined what to do with all the possible cases of joystick buttons. At the very least you need a “default” case to cover all uncovered bases.
Add a Motor reference (this motor needs to be opened in Begin.vi)
Put the cursor on the cases and right-click to choose “Add Case for Every Value”
Then look for every new case that needs a motor value added to it.
The output tunnel carrying the motor value will be solid when you have them all. It’ll have a white center if you haven’t fixed all the missing cases.