12-27-2011 12:41 PM - edited 12-27-2011 12:47 PM
Hi, I am new to labview and I have a task that I am not capable of completing.
My task is to read the values of two encoders simultaneously. I am reading the encoders using 2 counters. I am generating a clock using a third counter, allowing the encoders to use that clock for simultaneous sampling.
Then, using a physical push button, I want to trigger writing the angular positions of the two encoders to one spreadsheet file, making sure that ONLY both values at that same sample are written to the file. I want to write the ouputs of the encoders everytime I press the trigger, multiple times during execution, appending the new values to the same spreadsheet file. (Each column in the spreadsheet file should contain several outputs of each encoder: Column 1 for Encoder 1 and Column 2 for Encoder 2)
My problem is not knowing how to implement the writing of the encoder outputs at the same sample the trigger is pressed.
I hope it is clear what I am trying to do and I would greatly appreciate your help.
Please find the working VI attached.
Thank you,
r15
12-28-2011 02:17 AM
12-28-2011 02:23 AM
Hi r15,
I've checked your code quickly. I see two issues (at least from a quick glance). First of all, you keep the Trigger button (do you mean this as the "physical button" you refer to?) outside of the while loop - this means, that the case structure is either set to true or false, depending on the state of the button at the time it is read (the value red through the tunnel will remain the same for all iterations of the loop). A fix for this would be moving the button inside the while loop. It would be read each iteration and set accordingly.
As for the reading of current values - do not use shared variables. This way, there is no way to determine, if they will be updated before the counter values are read (this means that you could actually get a previous reading from Encoder 2 and a current reading from Encoder 1). Simply drag a wire from the output of the DAQmx read to the input of the build array function.
Could I ask you what's the goal of your application? I'm curious why write 2 values depending on pushing a button (couldn't you use some sort of condition for it?).
12-28-2011 10:18 AM - edited 12-28-2011 10:24 AM
Hi again
Thanks for your replies.
I followed your advices but I still need some adjusting for my code to work the way I intend it to.
To be more specific, I am building a robotic coordinate measuring arm where I aim to place the end-probe of the arm on an object and get the (x,y,z) coordinate at that specific point. To get the coordinate, I have to get the angular positions of the encoders (placed at the degrees of freedom of the arm) at that specific point. Hence, I will be using this physical trigger to signal writing the encoder values, at that specific point, to a spreadsheet file. After registering one point, I would like to be able to move the end-probe of the arm to another point and to follow the same procedure. (Use the trigger to signal writing the angular values of that new coordinate to the same spreadsheet file).
The problem with placing the trigger in the while loop is that on each iteration the value of the encoder is saved, which is not what is required of my task.
I want the trigger to be somehow independent of the while loop because of my application I described above.
I hope this makes it clearer as to what I am aiming for.
I modified my VI as you advised (find modified VI attached), and I will be gratefull if you can help me further with this task.
Thank you,
r15
12-29-2011
03:07 AM
- last edited on
06-09-2025
02:19 PM
by
Content Cleaner
Hi r15,
there is a simple fix for your issue (whilst you are still using the software button) - just change the mechanical action of the button (go to front panel, rightclick the button and change the mechanical action to "Latch when pressed") - now it has switch when pressed (you can find the behaviour for the mechanical actions in the Help and I would also strongly recommend to try the LabVIEW example "Mechanical Action of Booleans.vi").
For the hardware design, you could probably implement shift registers and only change the case selector control to true, after the previous one has been false (see the logic in the snippet - this also works for a switch button).