LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Iterate through a cluster of errs so I can implement my guard clause in my state machine

Solved!
Go to solution

alex_b2_0-1755506700861.png

I have a cluster of 3 error clusters. Each error cluster relates to a translation stage. I would like to have a guard clause in my state machine but the case structure only allows 1 error cluster to be wired to it at a time. I have used a for loop in the hope of passing out a single error cluster at a time.

 

I think I am on the wrong track here... I would appreciate some advice on a better alternative.

Thank you for your time

Alex

0 Kudos
Message 1 of 12
(398 Views)
Solution
Accepted by alex_b2

Use Build Array instead of Bundle, then autoindex the array into the For loop.

However the Case structure must be into the loop. Whether this is appropriate for your program or not cannot be assessed without additional details.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 12
(377 Views)

Hi Alex,

 

in the example as shown in your image you should use BuildArray instead of Bundle to get an array of clusters (as already suggested).

When your question is more general "how to process each element of a cluster of same elements" then you could use ClusterToArray to convert the cluster (consisting of elements of the same datatype!) into an array.

 

In the end you get an array where you can apply an autoindexing FOR loop!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 12
(342 Views)

Good morning, Alex.

 

     I'm curious why you need three Error lines on Shift Registers within a State Machine.  Can a single State give rise to two separate Error Lines, each of which are capable of generating an Error, meaning the State can have 0, 1, or 2 Errors within it?  [I can envision such a scenario, but I'll discuss it later ...].

 

     I use a Channel Message Handler as my model for a State Machine.  The Message consists of "Next State" (an Enum) and "Arg" (a Variant, in case I need to pass something "into" the State).  At the end of the Case Structure that encapsulates the State's code, there is an (optional) "Send Message" sub-VI that has as inputs the new "Next State" and any other Argument you need to pass (often unwired).  Between the exit from the Case and the exit from the surrounding While, there is an Error Handler routine that checks for Errors.

  • If there are no Errors, it just passes on the incoming Message (a Cluster of Next State and Arg) to the input side of the While Loop.
  • If there is an Error, it first bundles the "Error State" as Next State and the passed-in bundle that has "what would be done if there were no error" as the variant "Arg" part of the Cluster.  It then clears the Error Line so when the State Machine loops, it goes to Error State with the information about what caused the Error in the variant Arg component of the Cluster.

The net effect is that instead of going to "my next state", it goes to "Error State" with an Argument that tells what State caused the Error and the Error itself.  Now you can write code to do something with this information, including, if you want, to simply log it, and then (since you know what was going to be done next if there were no error) simply exiting the Error State and going to the "Next State".  [I don't advocate this -- I'd say "Save the Error Information to a file, and do a graceful shut-down, if possible".]

 

Bob Schor

Message 4 of 12
(322 Views)

Thank you both for the solution, but sadly it has raised further questions. The whole programme is shown below.

alex_b2_1-1755522627466.png

 

 

The producer loop will actually generate an image(5-10 per sec) to the user, once I receive my camera, for know I just generate a number. The consumer loop will be an event state machine.  It will deal with things like move only x,y or z, scan over x-y plane (nested loop) from x_min to x_max in steps of delx and y_ to y_max in step of del_y and a few other things.

 

I see now that the guard clause will send only the last err cluster, so I have now connected the error wires to the case structure. I want to use these to ensure sequential operation of the stages.  However, with so many error wires it is starting to look a mess..

 

Thank you once again.

Alex

 

0 Kudos
Message 5 of 12
(308 Views)

Hi Alex,

 


@alex_b2 wrote:

The producer loop will actually generate an image(5-10 per sec) to the user, once I receive my camera, for know I just generate a number. The consumer loop will be an event state machine.  It will deal with things like move only x,y or z, scan over x-y plane (nested loop) from x_min to x_max in steps of delx and y_ to y_max in step of del_y and a few other things.

 

I see now that the guard clause will send only the last err cluster, so I have now connected the error wires to the case structure. I want to use these to ensure sequential operation of the stages.  However, with so many error wires it is starting to look a mess..


This XYZ stage is just one device, so why do you need 3 error wires for a single device?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 12
(303 Views)

Hello Gerd,

The x,y z stage is not a single stage. There are 3 actuators (Thorlabs DRV014) which are connected to a stepper motor controller (Thorlabs BSC203) and controlled independently. The x & y actuators will move a sensor, which I will raster over the plane parallel to the table. The z stage will move a light spot up and down, normal to the table.

 

Thanks for your input.

Alex

0 Kudos
Message 7 of 12
(281 Views)

If you want to stop on any error while keeping error info separate for each stage, use Merge Errors to get a single output error wire (it's similar to an OR).

To Merge Errors you can wire the three error wires separately, or an array of errors.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 8 of 12
(277 Views)

Hello, Alex.

 

     Now I am more confused than ever!  You have described your code as a "Producer/Consumer", with the Producer being the acquisition of an Image from your Camera at 5-10 Hz, and the Consumer being a movement with three degrees of freedom (with X-Y being a stage, I think, and Z being an image source).

 

     It sounds (to me) as though you don't need a Producer/Consumer pattern -- acquisition of an Image shouldn't be "controlling" the timing of the move, rather you move, take a picure, move again, take a picture, move the light, take a picture, etc.  You note that the moves can involve one, two, or all three axes, and I assume you want to take the pictures when you are not moving.

 

     So this is a simple State Machine.  One State does "Next Move", then (when the Move finishes) goes to the "Acquire Image" State (which you might want to save on disk, so you "Produce" the Image and send it to a separate "Consumer" that writes to disk), then you go to "Configure Next Move" (where you worry about computing the next step in your 3D space) and transition back to "Next Move" (with a check, somewhere in there, to determine that you've finished all the moves and have saved all the data).  Of course, you need States to set up the equipment, figure out the parameters of the movements, handle Errors, worry about File Names for Images, etc.

 

Bob Schor

Message 9 of 12
(224 Views)

Hi Bob,

 

The reason I want to have the camera on an independent loop is so that I see something even when I am in the wait state or some other event which takes a while to complete. Honestly, it is something my boss will want and I want to keep him happy.

 

Anway, thank you everyone for their help. I would say this is solved. 🙂

Alex  

0 Kudos
Message 10 of 12
(171 Views)