|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Change in buttons and axes sub vi's
I programmed in labview last year using the 2013 version and am using the 2014 this year like most people also. I have a question. In the 2013 edition of labview, you declared buttons and axes much differently than you do now. I actually like 2013 version of labview more than the 2014 for this reason.
Can someone explain the difference between the two images I have uploaded and how to pick which axes and buttons to use from it? File named axes and button is 2014 version and the other file is 2013 version. |
|
#2
|
|||
|
|||
|
Re: Change in buttons and axes sub vi's
The joystick VIs were modified so that they support a wider variety of joysticks and in particular they support Xbox controllers better. One result of this was that the number of buttons, axes, and POVs were not really known, and the names given to them were not necessarily that accurate. Sure, they still had a name, but it may be a bit off.
The new Joystick Get function returns an array of each item, and they can be accessed using the index array function. If unwired, the top element defaults to returning element zero and other elements increment the previous index by one. For Example: If you want to index elements 3, 4, and 5, you simply wire a 3 to the top and the others still increment. If you want 2, and 5, you can wire the numbers to two elements, and you can do so in any order you want. If you do not want to use index array and prefer to have names, determine the names you want for your axes. Perhaps (run, strafe, rotate). Build a cluster of three numbers with those names. Then cast your array to your cluster. I'd do this in a new subVI that is your own joystick customization VI that you layer on top. Then you can access the elements as before, but with your robot's specific names. Note that this is even more useful for buttons, as they can be named (up and down) instead of Button 1 and Button 2. Greg McKaskle |
|
#3
|
||||
|
||||
|
Re: Change in buttons and axes sub vi's
Quote:
Last edited by Ragingenferno : 25-02-2015 at 14:51. |
|
#4
|
||||
|
||||
|
Re: Change in buttons and axes sub vi's
Not necessarily. Since NI has decided to not cluster the axes and buttons in the get joystick values vi for the current version of LabVIEW, you would not be able to do the unbundle function to get your axes and buttons. Now I understand it's hard for you to differentiate between which button is which and how to figure out which element of the array to which. Use the game controller settings on the joystick or controller you're using to find out which buttons or axes correspond with which. You can access this by going into the devices and printers, which can be found on the windows start menu and right click on the controller. Click game controller settings and navigate to settings and there you should be able to test out what number the axes or button is. If you are having trouble with this check on Microsoft's website to find detailed instructions to access the game controller settings. After finding your numbers, you can correspond this with the element number in the array for instance the x-axis is by default on array element #1 (or 0, I don't recall if LabVIEW's starting index for arrays).
|
|
#5
|
||||
|
||||
|
Re: Change in buttons and axes sub vi's
Quote:
|
|
#6
|
||||
|
||||
|
Re: Change in buttons and axes sub vi's
Don't matter. If your DS can see it than your computer can. All joysticks conform to a standard for USB devises called HID (Human Interface Devise). Mice, Keyboards, and joysticks fall under this and anything that can be recognized as an HID joystick devise you can follow Kevin Phan's advise to see the buttons/axis. We used this microprocessor before with custom buttons and even it can be seen as an HID joystick: https://www.pjrc.com/teensy/teensy31.html
The button/axis number you see corresponds to the element number for the array of buttons/axis you get out of the WPIlib joystick VI. Note when you go to program this the first element in an array and subsequently button #1 on the joystick will be the number zero. Things in programming count up starting at zero not one. |
|
#7
|
|||
|
|||
|
Re: Change in buttons and axes sub vi's
The joystick VIs had not changed in five years, and it was commonly requested to have better Xbox controller support. You can use the 2013 description if that is what you want.
You will want to copy the cluster that has the buttons and use that as the output from your wrapper subVI. The attached images shows an example. Then use that one instead of the one in the palette. Greg McKaskle |
|
#8
|
|||
|
|||
|
Re: Change in buttons and axes sub vi's
Quote:
|
|
#9
|
||||
|
||||
|
Re: Change in buttons and axes sub vi's
Quote:
Code:
/* Complete USB Joystick Example
Teensy becomes a USB joystick with 16 or 32 buttons and 6 axis input
You must select Joystick from the "Tools > USB Type" menu
Pushbuttons should be connected between the digital pins and ground.
Potentiometers should be connected to analog inputs 0 to 5.
This example code is in the public domain.
*/
// Configure the number of buttons. Be careful not
// to use a pin for both a digital button and analog
// axis. The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 16; // 16 for Teensy, 32 for Teensy++
void setup() {
// you can print to the serial monitor while the joystick is active!
Serial.begin(9600);
// configure the joystick to manual send mode. This gives precise
// control over when the computer receives updates, but it does
// require you to manually call Joystick.send_now().
Joystick.useManualSend(true);
for (int i=0; i<numButtons; i++) {
pinMode(i, INPUT_PULLUP);
}
Serial.println("Begin Complete Joystick Test");
}
byte allButtons[numButtons];
byte prevButtons[numButtons];
int angle=0;
void loop() {
// read 6 analog inputs and use them for the joystick axis
Joystick.X(analogRead(0));
Joystick.Y(analogRead(1));
Joystick.Z(analogRead(2));
Joystick.Zrotate(analogRead(3));
Joystick.sliderLeft(analogRead(4));
Joystick.sliderRight(analogRead(5));
// read digital pins and use them for the buttons
for (int i=0; i<numButtons; i++) {
if (digitalRead(i)) {
// when a pin reads high, the button is not pressed
// the pullup resistor creates the "on" signal
allButtons[i] = 0;
} else {
// when a pin reads low, the button is connecting to ground.
allButtons[i] = 1;
}
Joystick.button(i + 1, allButtons[i]);
}
// make the hat switch automatically move in a circle
angle = angle + 1;
if (angle >= 360) angle = 0;
Joystick.hat(angle);
// Because setup configured the Joystick manual send,
// the computer does not see any of the changes yet.
// This send_now() transmits everything all at once.
Joystick.send_now();
// check to see if any button changed since last time
boolean anyChange = false;
for (int i=0; i<numButtons; i++) {
if (allButtons[i] != prevButtons[i]) anyChange = true;
prevButtons[i] = allButtons[i];
}
// if any button changed, print them to the serial monitor
if (anyChange) {
Serial.print("Buttons: ");
for (int i=0; i<numButtons; i++) {
Serial.print(allButtons[i], DEC);
}
Serial.println();
}
// a brief delay, so this runs "only" 200 times per second
delay(5);
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|