LabVIEW Robotics Documents

Showing results for 
Search instead for 
Did you mean: 

Joystick Button Control (Using a Functional Global Variable)

by Active Participant Nate.H on ‎02-02-2009 11:31 AM

Manipulating button input from a joystick can be useful in controlling and switching between different robot behaviors. This example demonstrates how to implement a functional global variable to change the action of joystick buttons.

A functional global variable is a subVI that stores data in uninitialized shift registers. It consists of a While loop that executes once each time the subVI is run. This While loop contains a case structure that is used to choose which code the functional global executes, and how the shift registers are updated with the most recent value.

  Functional Global.png

This example demonstrates the use of a functional global variable to implement different button actions. This functional global could be used to do anything you want based on button input, but in this particular case the buttons are used to control a motor. There are four different "modes":


1. Timed On
Perform an action for a specified period of time, then stop the action.

Timed On.png

2. Hold On
When button is true, execute one action. When button is false, execute a different action.

Hold On.png

3. On/Off
Start an action on a button push, and continue this action until the same button is pushed again.

On-Off.png

4. 2 Button
Two button control. Each button is tied to a separate case structure, and can perform a separate action.

2 Button.png

To run this example, create a cRIO Robot project with the basic framework selected. Replace Basic Robot Main with Basic Robot Main Button Control FUNCT GLOB. Make sure that the digital module and PWM channel you have selected correspond to your physical setup. Run Robot Main Button Control and observe the motor behavior when using button one (buttons one and two for two button control).

Comments
Member Todd S.
Member

Great stuff and very well documented!  Could you please save your attachment with the version number included?  End with something like "_verXX".

Thanks!

Member ctrostad
Member

I added the button code to my program.  What do I click on to change the speed of the motor and how do I change the direction of the motor in the code to be Positve or Negative to turn a motor in opposite directions.  I ultimately want to press one button to turn a motor clockwise or be able to press another button to turn a motor counter clockwise.  My e-mail is ctrostad@crookston.k12.mn.us if you would prefer to e-mail me directly.

Thanks!!!

Active Participant Nate.H
Active Participant

Dear ctrostad,

To implement different behaviors, you are going to have to put code in various case structures that depend on the value from your button logic.

To implement a forward/backward motor control based on buttons, you should be able to modify the two button control case of the functional global included above. If you look at the included code, it basically implements forward/backward motor behavior based on 2 button input, but it does it in increments. You could modify this code to output a set forward speed based on button 1 input, and a set reverse speed based on button 2 input.

Be careful though. It may not be desirable to try to go from a high forward commanded speed to a high reverse commanded speed instantaneously...

Member ChrisTrostad
Member

What do we do to replace the basic robot main with the button program that we just downloaded and configured to our needs?  I am completely new to this so I don't want to screw it up at this point.

Member webby
Member

This documentation helped us get started, but now we are stuck implementing forward/backward. We have restricted the limits of the reverse case to 0, -1 and the limits of the forward case to 1, 0. But when using the reverse button, we only slow down continued forward motion to a stop. No reverse motion is ever intiated. We could post our vi, but not clear how to do that. Thanks for any help or ideas. Team 2145

Member Deirdre
Member

To make sure an engineer sees your question, please post your question in the discussion section of the