02-18-2007 09:01 AM
Hi,
I have some questions concerning the design of my
application. I have the following setup: a tensile machine equipped with a load
cell, a CCD camera and a temperature sensor. The motor of the tensile machine
can move in discrete steps or can drive continuously with a given speed. The load
cell measures the force on the sample mounted on the tensile machine and the
CCD camera measures the length of the sample using image recognition software.
All communication between the instrument and the Labview application is done
over RS232 serial connection (using a serial-to-USB device).
For the moment I have the following design (see attached image ‘Block diagram.jpg’). My master vi is a modified standard state machine (see attached ‘StandardStateMachine 1.vi’ for a simplified version). First I initialize the serial connections. Then I open a vi in the background that continuously reads the motor position, motor velocity, motor status, force, length and temperature, and write the values into global variables (no race problems because I have only one producer ‘ReadVariables.vi’ and some consumers in ‘StandardStateMachine 1.vi’). For this I use several independent while loops (see attachted vi ‘ReadVariables.vi’). The reason I do this is that e.g. the temperature can only be read out 500ms (very slow connection/response) whereas the sample length is updated every 20ms. It is very important to have good timing on some parameters such as force and length measurements and I want to avoid that the readout speed is determined by the slowest process.
Then the master vi goes into the ‘idle’ state which contains
an event structure. During the timeout of the event structure (e.g. every
100ms) it reads the global variables and shows the values on the front panel.
Possible events are e.g. set velocity, move motor x mm and many more … (this is
the manual control used e.g. for sample positioning). The more important events start up a tensile experiment (e.g. continuously drive the motor to a given
force and then keep the force constant (using a PID loop) there until the user
aborts the test). During this test all the variables are shown in graphs on the
screen and also written in a file. Furthermore the user can interact with the program during the test. For these tests I could use again an event structure (to handle the interaction of the user with the program) or I could use a timed loop (because timing a rather important here).
Error handling doesn’t seem straight
forward because of not using simple ‘left-to-right’ programming and
because of
using two independent vi’s. How should one communicate errors between
the StandardStateMachine 1.vi and ReadVariables.vi? Also with global
variables? The application will be used by several people so I should
build in some decent error handling.
I like the idea of behind this standard state machine and I think that having the data acquisition in a separate vi is also not a bad idea. But I am not sure whether this is ‘good programming practice’ and the most efficient way to program my application. All suggestions (except stuff about OOP) on this point would be very welcome (I hope there are enough details for you to make suggestions).
Thanks!02-21-2007 02:14 AM