LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Choosing Cursor position in the acquired XY graph for further processing

Hi all,

 

I am at a scenario, where I would acquire xdata (position) and ydata (intensity) from two different instruments and plot it in a waveform graph as it acquires each data point. The program stops after saving xdata and ydata array. Recently I learned about cursors in XY graph. I would like to know if I can ask the user to input a cursor point (a,b) in the waveform graph so that I can process [newX=xdata-a] and [newY=ydata/b] and save newX and newY. I would want to press a button after satisfactorily choosing the cursor a,b for the data process to start. I would also like to know how could I make the program wait till the point (a,b) is chosen.

I am using LabVIEW 2021 community version.

Thanks and Regards,

Pradeep

0 Kudos
Message 1 of 18
(1,221 Views)

Hi Pradeep,

 


@pclab wrote:

Recently I learned about cursors in XY graph. I would like to know if I can ask the user to input a cursor point (a,b) in the waveform graph so that I can process [newX=xdata-a] and [newY=ydata/b] and save newX and newY. I would want to press a button after satisfactorily choosing the cursor a,b for the data process to start. I would also like to know how could I make the program wait till the point (a,b) is chosen.


  • Yes, you can have your user set/move some cursors on your graph. You should just provide those cursors…
  • And you can read the cursor properties (including their postion on the graph) easily.
  • When you want to wait for some user actions (button, cursor moves) you should look into using an event structure.

What have you tried and where are you stuck?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 18
(1,219 Views)
  • A simple state machine allows you to program any condition that needs to be satisfied before going to the next state. The program should NEVER "stop" unto you are completely done with it.
  • Cursors can be made moveable by the user and their position read using event data nodes (of a cursor move or release event) or via property nodes.
  • You can also use mouse down events and calculate the click position in graph coordinates and programmatically do your calculation based on a and b, no cursors needed.
  • You could also use plot images to interactively draw arbitrary shapes (using "plot images").

Once we see your code (VI, not pictures!) and know a bit more about your use case, we can give much more specific advice.

0 Kudos
Message 3 of 18
(1,176 Views)

Thank you GerdW and Altenbach.

 

What property node should I choose to allow the user to drag and set the cursor at the user-desired position?

 

Also where the XY Graph is saved as a picture file, I could see the cursor in the saved picture. Is it possible to hide the cursor in the saved bmp file, yet visible to the user in the front panel? The saved file is around 1.25 MB. It would be nice to see the file size reduced as I do not need good clarity. Is it possible to save as jpeg? Sorry to ask many unrelated questions in a single post.

 

This is the program that I am working on for the past two months. This is almost close to complete. Let me know your suggestions. Anything that you would have done differently, if so why.

 

Thanks and Regards,

Pradeep

Download All
0 Kudos
Message 4 of 18
(1,140 Views)

Hi Pradeep,

 


@pclab wrote:

The saved file is around 1.25 MB. It would be nice to see the file size reduced as I do not need good clarity. Is it possible to save as jpeg?


Don't export to BMP when you don't like the large BMP files!

Export to PNG (or JPG) instead:

("Bild lesen": "get image data" or similar…)

 


@pclab wrote:

What property node should I choose to allow the user to drag and set the cursor at the user-desired position?

 

Also where the XY Graph is saved as a picture file, I could see the cursor in the saved picture. Is it possible to hide the cursor in the saved bmp file, yet visible to the user in the front panel?


  • In the properties for cursors you will find a "Draggable?" item…
  • When the cursors should be hidden in the exported image you can hide them before exporting and show them afterwards…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 18
(1,134 Views)

Hello GerdW,

 

In graph properties >> cursors >> i have checked allow dragging and opted free dragging. The cursor can be moved before running the vi and after the vi has stopped. But I need to choose the cursor position after the acquisition of data and before the normalize event structure. At that time, the cursor cannot be moved. Also that the normalize button does not respond and the txt file is not generated. What could be wrong here?

 

Pradeep.

0 Kudos
Message 6 of 18
(1,126 Views)

Hi Pradeep,

 


@pclab wrote:

In graph properties >> cursors >> i have checked allow dragging and opted free dragging. The cursor can be moved before running the vi and after the vi has stopped. But I need to choose the cursor position after the acquisition of data and before the normalize event structure. At that time, the cursor cannot be moved.


The problem is: there is no time between "after the acquisition" and "before the normalize"!

You need to provide some "time" to the users so they can actually move the cursors…

 

(This is purely dictated by THINK DATAFLOW!)

 


@pclab wrote:

Also that the normalize button does not respond and the txt file is not generated. What could be wrong here?


When do you know that the "normalize button does not respond"?

The normalize action is embedded in an event structure - and this event case is only executed "after the acquisition". Due to "THINK DATAFLOW!" there is no other way to execute that event case! (Additionally you block the UI handling with this event case…)

 

Based on your questions I suggest to rethink your whole program design: when the program should react to user actions ALL THE TIME then you need to place the event structure into its own loop. You should also think about using a statemachine to implement your sequence of actions (DAQ, cursor movements, normalizing, …)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 18
(1,117 Views)

@pclab wrote:

In graph properties >> cursors >> i have checked allow dragging and opted free dragging. The cursor can be moved before running the vi and after the vi has stopped.


Your code is inside out and will never work right as written!

 

  • Never place extended interactive code inside an event case (your big "Run" event!).
  • (Your event locks the panel until it completes, but it can never complete, preventing all user interactions.
  • never place event structures inside event structures.
  • Built array is better than "insert into array" to append elements.
  • Greedy polling loops are pointless since you defined a "." as termination character.
  • Most, if not all, your sequence structures can be avoided.
  • "Index array" is resizable.
  • ...

You need to untangle your code into a reasonable state machine. It will be significantly simpler, easier to debug, and will do what you want. Have a look at the templates that ship with LabVIEW.

0 Kudos
Message 8 of 18
(1,114 Views)

Thank you for your valuable suggestions. I am convinced to use event-driven state machines. 

I have a few questions, actually a lot. But for the time being...

Say, I have few states, viz. Initialize, Idle, Play, Run, Cursor, Normalize, Save, and Stop. The events would be Play, Pause, Run, Normalize.

 

I want to sequentially run two events (Run, and Normalize), which would be bound by a for loop. How can I do this? Or is this the right way?

 

@Altenbach: Regarding the "greedy polling loop" how else would I wait for a particular code to be received from the instrument. Depending on the current position of the stage, the time to move to the home position would vary.

 

Thank you for your support.

Pradeep.

Download All
0 Kudos
Message 9 of 18
(1,101 Views)

Hi pclab,

 


@pclab wrote:

I want to sequentially run two events (Run, and Normalize), which would be bound by a for loop. How can I do this? Or is this the right way?


Your statemachine can (internally) store more information than just the "next state" information, like a counter value to simulate that FOR loop!

Like:

IF state == "Save" AND counter <> max_iterations
  THEN next_state := "Run"
  ELSE next_state := "Stop"
ENDIF

 


@pclab wrote:

Regarding the "greedy polling loop" how else would I wait for a particular code to be received from the instrument. Depending on the current position of the stage, the time to move to the home position would vary.


Right now those loops may never stop: what do you do when the expected response will not occur? How do you react on communication problems or a stucked stage?

Best regards,
GerdW


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