Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Change in buttons and axes sub vi's (http://www.chiefdelphi.com/forums/showthread.php?t=135164)

Ragingenferno 25-02-2015 03:16

Change in buttons and axes sub vi's
 
3 Attachment(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.

Greg McKaskle 25-02-2015 07:18

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

Ragingenferno 25-02-2015 14:43

Re: Change in buttons and axes sub vi's
 
Quote:

Originally Posted by Greg McKaskle (Post 1449578)
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

I think i understand. Would i be able to copy and paste the button and axes from the third photo(labview 2013) into 2014 and it would work?

Kevin Phan 25-02-2015 15:06

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).

Ragingenferno 25-02-2015 16:34

Re: Change in buttons and axes sub vi's
 
Quote:

Originally Posted by Kevin Phan (Post 1449777)
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).

We aren't using a controller from microsoft. We are using one of mad cats 3d joysticks with a 3rd axis on it for rotation. We are using omni drive. I have the axis thing down. I'm just not understanding the buttons. In my opinion, instead of editing last years joystick get vi, they could have added a whole new section like a controller vi. lol. I'm not a big fan of change.

jman4747 25-02-2015 16:59

Re: Change in buttons and axes sub vi's
 
Quote:

Originally Posted by Ragingenferno (Post 1449823)
We aren't using a controller from microsoft.

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.

Greg McKaskle 25-02-2015 18:39

Re: Change in buttons and axes sub vi's
 
1 Attachment(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

AlDee 26-02-2015 14:22

Re: Change in buttons and axes sub vi's
 
Quote:

Originally Posted by jman4747 (Post 1449832)
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.

I'm planning to work on a custom controller using the teensy. Can you tell me, if there is any limit to the number of buttons or axis that the driver station will recognize? Did you have to do any additional programming to get it to work with the DS? Also, I'm curious as to how you mounted it. It doesn't look like there are any screw holes or any place to drill any either.

jman4747 26-02-2015 15:29

Re: Change in buttons and axes sub vi's
 
1 Attachment(s)
Quote:

Originally Posted by AlDee (Post 1450221)
I'm planning to work on a custom controller using the teensy. Can you tell me, if there is any limit to the number of buttons or axis that the driver station will recognize? Did you have to do any additional programming to get it to work with the DS? Also, I'm curious as to how you mounted it. It doesn't look like there are any screw holes or any place to drill any either.

I don't know about the limit of buttons the DS can read the teensy can do 16 (or 32 total if using the ++2 model) and up to 6 Axis. You do have to do additional programming on the teensy, the robot side is exactly the same. As for mounting you need to solder on header pins such that it looks like this: https://www.pjrc.com/store/teensy31_pins.jpg. Attach that to a bread board and then your wires from the switches to the bread board. Also check this: http://www.chiefdelphi.com/media/papers/2666 though be aware that we used the newer example code below for ours. One word of warning, make sure you strain relive the USB cable going from the teensy to the computer. We broke the micro USB off the teensy once and switching to a xbox controller mid competition isn't fun.

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);
}



All times are GMT -5. The time now is 10:28.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi