Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   General Forum (http://www.chiefdelphi.com/forums/forumdisplay.php?f=16)
-   -   Java to Labview, using "if else" statements and pressing buttons (http://www.chiefdelphi.com/forums/showthread.php?t=92756)

Lemonsy 22-02-2011 23:18

Java to Labview, using "if else" statements and pressing buttons
 
I'm originally a java programmer, but I've taken on Labview since this past last year. I'm trying to make a code that will assign a value of 0 when a button ( button 1) is pressed and then change that value into a 1. When the button is then pressed again the value is changed back into a 0.

This code is for a claw that will open and close. Any advice, help, or screenshots?

int x=reader.nextInt(); // takes value of pressing the claw button
while (y==1) //the robot is turned on
{
if(x==-1)
{
claw=0; //open position
}
else(x==0)
{
claw=1; //close position
}

x=reader.nextInt(); //checks the next value of the claw button
y=OnOrOff.nextInt() //checks if robot is on or off
}

Mark McLeod 22-02-2011 23:25

Re: Java to Labview, using "if else" statements and pressing buttons
 
Here's a button toggle example.

As the example stands the green output alternates between a 1 or 0. You can eliminate the inside Case statement if you don't put anything inside it.
If you want a real number output use "Boolean To (0,1)" located on the boolean palette.

If the claw is solenoid operated you can just stick the activate inside the toggle where indicated and use this in Teleop.
A motor operated claw would require a longer cycle, but could be used, as is, inside Periodic Tasks or Autonomous Independent, not in Teleop.

davidthefat 22-02-2011 23:25

Re: Java to Labview, using "if else" statements and pressing buttons
 
x=reader.nextInt();
claw = !x;

There you go, I optimized it.

WizenedEE 23-02-2011 00:31

Re: Java to Labview, using "if else" statements and pressing buttons
 
1 Attachment(s)
I'm assuming you know about case structures.

To make an else if statement, you just go to the false case of the case structure and put another case structure inside that.

There are also other ways to do it, like taking all your inputs and making them into a number (with a boolean array to number function, if you're interested) and wiring that one number to the structure. However, it's easiest (although ugliest) to just nest the case structures.

I attached an optimized program for you.

Lemonsy 24-02-2011 20:59

Re: Java to Labview, using "if else" statements and pressing buttons
 
Oh wow, thanks! I've tested both of them, but I need to discuss with my driver and team which they would prefer.

Much appreciated :D

frasnow 24-02-2011 22:55

Re: Java to Labview, using "if else" statements and pressing buttons
 
Quote:

Originally Posted by Mark McLeod (Post 1029709)

LabVIEW can certainly make something simple look really complex. I'd be curious to know how long it took to draw that.
Quote:

Originally Posted by davidthefat (Post 1029710)
x=reader.nextInt();
claw = !x;.

Simple, easy to read, and can be written in a few seconds. Even when you count the variable declaration.

Alan Anderson 25-02-2011 00:07

Re: Java to Labview, using "if else" statements and pressing buttons
 
Quote:

Originally Posted by frasnow (Post 1031035)
LabVIEW can certainly make something simple look really complex. I'd be curious to know how long it took to draw that.

I just redrew it in just under a minute.

Quote:

Code:

x=reader.nextInt();
claw = !x;.

Simple, easy to read, and can be written in a few seconds. Even when you count the variable declaration.
Alas, it doesn't do anything like what the original poster wants.


All times are GMT -5. The time now is 09:56.

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