LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Matching oscillation to reference sine signal

Hi, 

 

I am trying to control an oscillating system (displacement sensor and a motor connected to a rod that pushes a plate where the sensor is measuring the distance) to match a reference sinus signal (with its frequency and magnitude as manipulative variables). I have tried many (simple) ways but I am still not able to get the sensor signal to match the frequency and amplitude of my reference sine signal. The frequency and amplitude of my oscillation (data from the sensor) do not match that of my reference signal.

 

Please find attached my latest version, where I changed my signals into speed (via a derivative block) before putting them through a PID controller (P: 0.01; I: 0; D:0) as my motor has an RPM input/output. Really appreciate it if anyone has an idea how I could match my oscillation to the reference sine wave (its okay if theres a phase shift). It's important for me to be able to change the amplitude and frequency of my reference signal and have the oscillating system follow suit. 

0 Kudos
Message 1 of 6
(778 Views)

Without even looking at your code, it seems highly likely that "you did something wrong".  I'm not exactly sure how your mechanical system is hooked up, but I'm assuming that (to a first approximation) it is a linear (or "near-linear") system -- if you drive it at 1 Hz, it will oscillate at 1 Hz (with the same being true at 0.1 and 10 Hz, assuming it can respond that fast), and if you increase the amplitude of the driving signal, you'll get a similar increase in the amplitude of the response.

 

One "feature" of linear systems is that if you put in a sinusoid of frequency "f", the system will respond at the same frequency.  So either your system is highly non-linear, or you are not doing what you think you are doing.

 

So I looked at your code.  You are using Express VIs, particularly the Dreaded DAQ Assistant (that's my name for it, abbreviated DDA), which are great for NI Sales to show "how easy LabVIEW is to use", but have hidden flaws and foibles.

 

There are some strange things there.  You seem to be working at fairly low frequencies (Frequency = 0.5, which I assume is 0.5 Hz), yet you are sampling at 10 kHz, four orders of magnitude higher!  You are also doing "strange things" (strange, to me) with PID.  I'm not sure how you are stimulating, but you should be able to make a low frequency stimulus and simply have your system "follow" it.

 

I'm sorry, I don't understand how you translate your (low-frequency) sinusoid into a drive signal to your system.  I also don't understand how the drive gets applied -- is there some "interesting" transformation that changes the sinusoidal "drive" (is that supposed to be a position drive, a velocity drive, or something else?) into a signal to move the object attached to the displacement center.  Maybe a sketch (or picture, with labels) of the physical system would be useful ...

 

Bob Schor

0 Kudos
Message 2 of 6
(743 Views)

You have a few issues. First, your dt is hardwired to 3, and I don't think you're sampling every 3 seconds.

 

You're also measuring something (labeled "sensor data", is that position or what?) then passing that array through a filter, then a derivative. That will give you a derivative plot.

 

Here's your big issue- you're passing an array of data into the PID function. That will auto-configure it to be running multiple loops.

 

You're trying to control the RPM, but you're passing it in an array of position data. You need to convert that position data to RPM, then pass a scalar (a single number- NOT array) into the PID function. Right now, it's trying to run a separate PID control for each point in the array.

0 Kudos
Message 3 of 6
(735 Views)

Hello, thank you for the response. Here are more details to my system to see if I could get some idea from you before I attempt to fix my terribly done loop. Kindly find attached a picture of my hardware setup. The motor and the displacement sensor is connected to the NI. 

 

The stimulus would be my reference sinus wave where an offset is added to match my calibrated displacement sensor (which is taking in distance/displacement). I used a derivative block to convert it to RPM to feed into the motor. My motor should move the rod and thus the plate back and forth (oscillate) about the centre of the rail (centre: the offset added to my ref sine wave). The idea is that my plate should oscillate to match my reference signal. 

 

I also have tried another approach to make my loop work (or at least to try to do what I think I need to do), which is to first get the difference between the actual displacement and the reference before passing it through a derivative block to obtain its angular velocity, and then through a 'P controller' before feeding it to the motor. Here, the frequency does follow my reference freq but the amplitude does not follow exactly (it changes but the amplitude doesnt correspond to the amplitude of the stimulus). The problem I faced using this loop is that my physical system does not oscillate at the center (rather, it bangs to one side of the rail). 

Download All
0 Kudos
Message 4 of 6
(722 Views)

I haven't had a chance to take a look at your code, but just so you know- taking the derivative of position gets you velocity. Not RPM. You'll need to do a frequency measurement on your position signal to get RPM. Until you do that you won't get anywhere. You don't need a derivative here at all.

Message 5 of 6
(709 Views)

(I can't edit my previous post anymore but I'd like to elaborate some...)

 

You said you have a displacement sensor, right? Generally when people say "displacement sensor" they're talking in linear terms, which is what I'm assuming. Your position signal would therefore be a sinusoid, which means you'll need to do frequency analysis to get your RPM.

 

If your sensor is a rotational one, like an encoder or potentiometer, then your position signal will be a straight slanted line. If that's the case, then you're correct in doing a derivative to get rotational velocity. Your units won't be in RPM (unless your displacement sensor measures in rotations, which I personally haven't ever seen) so you'll need to scale from degrees to rotations or whatever. You'll also need to get your timing signal right.

 

In the second case, you'll have a velocity signal that's a constant array. Your control signal needs just one discrete point per loop, so you should just take an average of the rotational velocity and use that as an input to your PID loop.

 

Here's my suggestion: Get rid of the PID loop and outputs altogether. Focus on getting your input right and having your signals show up on the screen accurately.

 

Next, get the subtraction right to show you the error between your target signal and your actual signal- again, just show up a number on screen. Add plots for input position and target position signals, then add single value indicators for your "current RPM" and your "target RPM".

 

At this point you can verify all of your sampled data is correct. Once you get there, you can add the PID back in, but I wouldn't touch anything PID until you get all of the above correct. I cannot emphasize this enough- get your input signals correct on screen before you mess with PID. Bad inputs guarantee bad outputs, and I can guarantee you have bad inputs and analysis right now.

 

Also again, just FYI- your derivative function isn't wired correctly. You have a constant of "3" hardwired to the "dt" input. Do you know what the dt input means? (It's the acquisition period of your DAQ, and should match the simulated signal, and your DAQ Assistant input is configured for a 1 kHz sample rate- meaning your dt should be 0.001, not 3).

 

I'd also suggest getting rid of your DAQ assistants but it's not the end of the world for your setup.

Message 6 of 6
(694 Views)