I'm having a problem programmatically creating Custom Scales for Analog Input with DAQmx. Here's the background. We're trying to develop a small triaxial sensor for monitoring muscle twitches (it's a Student Project, I'm an "advisor"). We have a Triaxial Accelerometer that puts out voltages proportional to the X, Y, and Z components of acceleration. The Accelerometer runs off a 5v supply, with each channel having a bias (offset) of 1.5v and a gain of 0.3v/g, with about a 10% variability in these parameters (i.e. gain ranges from 0.27 to 0.33 v/g).
We can easily read the three channels of acceleration with an NI USB-6009. In the original "Proof of Concept", we were easily able to measure muscle twitches, but noted that the channels were definitely uncalibrated.
I devised a Calibration Procedure that was quick, robust, and reproducible, requiring measuring the X, Y, Z voltages when the accelerometer was held in six orientation without moving -- the entire process takes 15 seconds. But then, I decided to "get clever" (always a bad sign).
I've never used Custom Scales in DAQmx, but thought "Why not use the Calibration values for the X, Y, and Z axes to programmatically set Custom Scales for the three Axes so everything is in units of "g" and centered around 0g". I had defined a "Triax" Task in my Project -- if I manually entered the Scale Factors deduced from my Calibration, the axes all read between +1g and -1g (depending on orientation) when the sensor was motionless.
But I cannot figure out how to take the Calibration data and programmatically assign each channel its own Custom Scale.
Here's some code. This first Routine finds the Triax Task stored in the Project, and makes sure the the correct USB-6009 is connected. Within the Project Task, I've named the three Physical Channels ai0, ai1, and ai2 to X, Y, and Z, and set the voltage range from 0 to 5 v -- this code basically resets the scaling for these three channels. It seems to work fine.
![Setup Triax Task.png Setup Triax Task.png]()
The reason that I do this is that I want to record these three channels using the standard Volts scaling, as I'll use these voltages to run the Calibration procedure I developed to get the three Bias and Gain settings needed for the Custom Scale.
Here is what I tried to do to create a Custom Scale for the X, Y, and Z channels (the Scales are named X_Scale, Y_Scale, and Z_Scale). I tried a number of things, this is just one of them, but I've not had success getting anything to work (to say nothing of avoiding DAQmx errors). Incidentally, if I enter the Scale Factors "manually", my Accelerometer readings are, indeed, properly scaled between -1g and +1g.
Some of this code may look overly complicated -- trust me, I tried to make it simpler, but there are all kinds of "hidden gotcha's" in some of these functions that "made me do it" this way. But, of course, it doesn't work.
Insights and suggestions are most welcome! I'll continue to work on it, of course (but, fortunately, I didn't bring the device home with me, so I get a little break ...).
Bob "Puzzled" Schor