LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to perfect pendulum measurement

I'm fairly new to Labview, so please be gentle.
 
I'm a work-study in the EET program here at Oklahoma State University, and nobody here really knows much about Labview.  I've been tasked with figuring the thing out for everyone else here, and I've made a lot of progress on my own.  In the furthering of figuring this software out, I've also been tasked with trying to modernize some of the lab experiments for our Physics classes.
 
The experiment I'm working on right now is simply to measure the average cycle period of 30 swings of a pendulum.  I've managed to put together something I'm fairly happy with, but I thought I might try to get some help to smooth out some of the rough edges a bit, and hopefully learn a little more about the program in the process.
 
The ultimate idea is to use a photo-sensor that sends +5V when shorted by the swinging pendulum.  Right now, I'm simulating this using a pushbutton.
 
Here's what I would like to change about the code:
 - I'd like the X-scale on the graph to reflect the elapsed time, rather than just counting measurements
 - I'd like the graph to clear its data every time the program is run (instead of having to close the VI and re-open it).  Alternatively, it might be nice to have a reset button for the graph instead
 - I like giving the end-user control over the number of swings to measure, but I would like if the DEFAULT was 30 instead of 0 whenever you open the VI.
 - Finally, I'm convinced that there is an easier way to do the same things I've got the code doing, and I would like to find ways to simplify the code so that the teacher can possibly explain to "normal people" (i.e. - people who take Gen. Physics I at a tech school) what's going in the code.  We've BEEN doing this lab just using a stopwatch, so of course part of the point of all this is to be able to measure more accurately.  However, the Physics department head tells me that, if possible, he'd also like to start integrating Labview programming into the Physics classes as well, so I've also been tasked with trying to make this simpler.
 
Any help is greatly appreciated.  About 3 weeks ago, I had never even heard of Labview before.  This code represents everything I was able to learn on my own in those three weeks.  I use Labview 8.2.
0 Kudos
Message 1 of 8
(3,561 Views)
A graph is re-drawn with each update, a chart is not, I suspect you are using a chart due to the trime value part of your question, here is how I clear a chart:
First of all create a property node for your chart, to do this right click the chart icon on the block diagram and select "Create/ Property Node" right click the resultant property node and select "History Data" from the list, right click a second time and select "Change to Write"
 
Wire an array with a zero valuer to the History Property Node of the chart, put this into a True/ False case loop in the True mode. Create a boolean switch named "Clear Chart" and wire that to the True/ False case selector, when you press the clear chart button the loop will execute the code thus clearing the chart, as a tip right click the Switch on the front panel and make the mechanical action of the switch momentary.
 
If the above is too difficult right click the chart on the front panel and select "Data Operations/ Clear Graph" or Clear Chart as applicable.
 
I assume you have a numeric control which you set to 30 for the number of cycles to measure? - if so set this to 30 right click the control on the front panel and select "Data Operations/ Make Current Value Default" save the vi, now each time you open the vi the panel object will be set to 30 by default. Also consider right clicking the control and selecting "Format and Precision" select the "Data Range Tab" and make the increment value 1 and "Coerce to nearest " to prevent selection of partial swings. I don't have 8,2 on this PC so I am unable to open the vi - Mike
0 Kudos
Message 2 of 8
(3,542 Views)
Hey, thanks for the help Mike.  That helped out quite a bit!
 
I was doing OK until the part about arrays.  I found an array constant, but that didn't seem to like being wired to the history node.  I know WHAT arrays are from having coded in C before, but I'm not sure how they're being used here (or any variable for that matter).  I guess I'll just have them clear the graph manually for now.
 
I've had other people look at the code and tell me that I'm doing it about as simply as it's possible to do.
 
However, it occurs to me that if what this guy really wants is to be able to just have students wire something simple together to create this program, I should be able to make that possible if I condense it into subVIs.
 
Thanks again for the help!
0 Kudos
Message 3 of 8
(3,511 Views)

I'm not sure what you are doing wrong to have issues with wiring the array to the chart history property node.  You'd have to post a copy of the VI with the problem so we could see that.

But the easiest way to do it is before you run your VI, right click the chart terminal on the block diagram, Create Property Node, Chart History. If necessary, right click and change it to Write.  Now right click on the connector going into the Chart History, and select create constant.  It will connect an empty array of double type to that property node.  That will clear the chart history when it executes.

Right clicking connectors and wires and selecting Create Constant is a good way to get constants of the proper data types, particular for more complicated data types such as clusters.

0 Kudos
Message 4 of 8
(3,493 Views)
If you want to recreate it, the problem I was having was when I was going to Arrays--->Array Constant and trying to wire that into the clear history node.

But your advice worked right as rain!  That's really cool!  I have to admit that I feel I'm cheating somewhat though, since this allows me to put off legitimately learning how arrays and such operate in Labview.  But this is great for right now.  Thanks!

I went ahead and got it to clear all the data values, not just the chart.  I then put all of that in a case structure, and wired a button to all that called "Clear values at start".  I think that's probably the best way to do that.

I WAS trying to use a momentary switch as was suggested (I figured that out.  That's cool!), but the way it's coded, I could only get that switch to trigger either before the first voltage event occurs, or during the triggering, but not both.  I tried to get it to work from a single button in both situations using a reference to the button, but for some reason, it returned an error when I tried that.  Honestly, in my mind's eye, the absolutely ideal situation would be a momentary button that clears all the values and charts, and works no matter what part of the code is executing AND even while it's not executing (while the VI is stopped).  I don't know if that's possible.

I also went ahead and added a pulse chart that will give a nice visual cue with a scrollbar for the action of the pendulum.  I thought it was a nice touch and will give students something visual to look at.  My only complaint with it is that the way it's coded right now, the chart quits updating when it hits the part of the code that makes it wait after the pendulum shorts the light sensor but before the light is unshorted.  Again, I tried a reference to keep it going, but that didn't seem to work.  There must be something I don't get about references...
0 Kudos
Message 5 of 8
(3,484 Views)
Sorry for the double post.  I had meant to upload the latest version of the VI.  Here it is.

Thanks again for all your help.  I'm learning a ton, and this VI is getting better all the time.

EDIT: Heh heh...so this forum DOES have an edit feature for posts.  It was hidden under options.  Sorry again for the double post.

EDIT2: Just thought of something else.  Is there a way to change the X-axis on the Average Period chart to reflect something besides the number of events?  Right now I've given it the half-hearted label "half-swings", but that's a cop-out, and it also ends on an odd number which is annoying.  I was thinking it would be cool to have the X axis reflect the same calculated value I'm using for "total swings" instead.  In fact, maybe I could even set up something where at the beginning of the code's execution, it autosizes the chart to reflect the user-inputted "swings to record" as the X-axis maximum, instead of autoscaling.


Message Edited by JustusJohnston on 03-27-2008 11:37 PM
0 Kudos
Message 6 of 8
(3,483 Views)
If you right click and go into chart properties, then the scales tab, you'll see there are fields for offset and multiplier.  So you could set the multiplier to 0.5 and thus have full swings for your X-axis.
 
I am going to take a guess at what was going wrong with creating the array constant.  Tell me if I'm wrong.  If you drop in an array constant from the array palette, it is just an empty container and will appear in black.  You won't be able to wire it to anything because it has no real definition.  You need to place another constant on the block diagram, such as a double precision numeric.  Then you drag and drop that into the array container.  Then everything snaps together and you have a double precision 1-D array defined.  It will be empty to start with.  You can also add dimensions to make it 2-D, 3-D, .... by right clicking on it.  (That's another key tip.  Don't forget about right clicking objects, you'll be amazed at the things you can do by way of that menu.)  Creating clusters is similar.  You drop in a cluster container which will have no real definition.  Once you start dragging in numeric constants, arrays, booleans, enums, .... pretty much any combination of things including other clusters, then the cluster takes on a defined structure.
 
Is sounds like you are really new to LabVIEW.  The Basics 1 and 2 courses are great.  But also look at the online tutorials:
0 Kudos
Message 7 of 8
(3,456 Views)
That did the trick for the chart.  And arrays make some more sense now.

I've also figured out a bunch of other stuff to do using the reference nodes.  For instance, I finally got the pulse chart to update during the TRUE state, and that makes me happy.

At any rate, I think I'm ready to call this VI finished and move on to something new.  Thanks everyone for all your help.  It's greatly appreciated, and I learned alot. 

Yes, I am extremely new to Labview, and while not necessarily new to computer programming, I've only dealt with text-based structured programming in the past.  These tasks were just kind of thrust on me out of nowhere so I've had to just jump in with both feet, sink or swim, especially since nobody else on campus really knows anything about Labview.  In fact, they appear to be using me as a guinea pig for developing what's going to be a Labview curriculum.  I guess that's the hazard of being part of a small tech school in a small city.  I'll be sure to at least go through those tutorials before I'm given anything else new to do.

Here's the final version of the VI (barring any complaints the Physics guy has), and thanks again for all your help.
0 Kudos
Message 8 of 8
(3,439 Views)