LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create a ramp like function in Formula node

Solved!
Go to solution

Hi all,

 

I need to create a ramp like function in Formula node which will be repeated every second. This is what I tried:

"

if (t==0)
y=0.1;
else if (t>0 && t<0.3)
y=t+0.1;
else if (t>=0.3 && t<0.4)
y=0.4;
else if (t>=0.4 && t<0.7)
y=-t+0.8;
else if (t>=0.7 && t<=1)
y=0.1;

"

It shows the correct profile for one cycle,. but I need it to be repeated after each second. I belive it should be done in a for loop structure but since I am a NI newbie, not sure how.

 

Any help is appreacited. 

Thanks

Navid

0 Kudos
Message 1 of 16
(1,155 Views)

No need for any formula node. Just use graphical primitives. 😄

0 Kudos
Message 2 of 16
(1,134 Views)

Thanks. It is going to have other parts to cycle synchronoise (phase lock) it with other equipment (laser, camera, sensors). The way the code is written so far (for other profiles) is based on Formula node. That is why I need to implement this into formula node. 

0 Kudos
Message 3 of 16
(1,124 Views)

@navidvd wrote:

Thanks. It is going to have other parts to cycle synchronoise (phase lock) it with other equipment (laser, camera, sensors). The way the code is written so far (for other profiles) is based on Formula node. That is why I need to implement this into formula node. 


Once you have your function output you have your function output.  It doesn't matter how you get it.  So, get it the easy way.

 

Each section you describe is a simple waveform section

 

if (t==0)
y=0.1;
else if (t>0 && t<0.3)

y=t+0.1;

Ramp pattern start 0.1, end 0.3 samples, TBD you didn't specify a dT

 

else if (t>=0.3 && t<0.4)
y=0.4; 

Initialize Array value 0.4 size TBD you didn't specify a dT


else if (t>=0.4 && t<0.7)
y=-t+0.8;

Ramp Pattern start 1.2 end 1.5 size TBD you didn't specify a dT


else if (t>=0.7 && t<=1)
y=0.1;

Initialize Array Value 0.1 Size TBD. (that dT again)

 

Concatenate them together in a single Array or better yet use a Waveform Datatype.  No ifs no ands no "but if onlys" and you can even test, adjust and add notes for each part.


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 16
(1,092 Views)

Thansk for your reply. This is how it looks like at the moment: 

navidvd_0-1696383152903.png

 

navidvd_1-1696383218441.png

dt is 10 ms. I need the profile to be repeated after each cycle. But with the way I wrote, it is only one cycle.

Thanks

Navid

0 Kudos
Message 5 of 16
(1,080 Views)

Hi Navid,

 


@navidvd wrote:

dt is 10 ms. I need the profile to be repeated after each cycle.

But with the way I wrote, it is only one cycle.


Yes, the way you wrote your code it will execute once. (Atleast what we can see from your images: you know we cannot edit/run/debug images in LabVIEW!?)

 

You also wrote:


@navidvd wrote:

I need to create a ramp like function in Formula node which will be repeated every second.


Right now your t will go from 0.00 to 24.99: how does it fit to your "repeat every second" requirement???

 

if (t==0)
  y=0.1;
else if (t>0 && t<0.3)
  y=t+0.1;

This is Rube-Goldberg: there's no need for the "t==0" case…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 16
(1,053 Views)

Hi,

 

Thanks for your response. 

I changed the loop count to 100. Now it looks like it can generate the second cycle immidiately after the first one and so on. Is that correcT? I attached the code as well.

 

Thanks again,

Navid

0 Kudos
Message 7 of 16
(1,045 Views)

Hi Navid,

 

I prefer LabVIEW2019: please use File->Save for previous and reattach your VI.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 16
(1,033 Views)

Sure, attached is the 2019 version.

 

Navid

0 Kudos
Message 9 of 16
(1,025 Views)

Hi Navid,

 

why is your code so large and does not follow the style guide?

 

See this:

I don't think your "length" calculation is correct, but it is up to you to judge this as only you know the requirements!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 16
(1,019 Views)