07-05-2017 03:19 PM
Hi there,
I'm writing a code that will eventually be used to control a servo motor controller. My objective is to output a steady voltage regardless of whether I want the voltage to be ramping or not. An issue I'm encountering right now is that the voltage cannot properly ramp up or down to the specified final voltage if the specified ramp rate is not a multiple of the final desired voltage. In other words, if I have a step size of 0.3 and a final desired voltage of 2.0V, it will instead ramp to 2.1V. I have also tried this with LabVIEW's own "Ramp Pattern.vi" and I encounter the same issue. This is a major issue for me because the equipment I'll be implementing this software with needs to be very precise for scientific purposes.
Below are my block and front diagrams. In the lower left of my while loop I created a case structure that is supposed to look at the current loop iteration's voltage and see if it is within 50% of the target ramping voltage. If it is, I want it to coerce the voltage to be exactly the final target voltage. I didn't finish building it because I wasn't sure how to proceed. I also included my code if that helps.
The dog on the front panel is there simply to keep me sane. He's a good boy.
Thanks very much, I appreciate any help.
07-05-2017 03:47 PM
Sounds a bit like you may be trying to implement a PID.
Do you have access to the PID and Fuzzy Logic Toolkit? Might save you some work.
Otherwise, you should be using your coerced value as the input to your analog write. I didn't check the math but I think the principle is correct.
A loop rate of 100 ms seems like it may be kind of slow for motor control but that probably depends a lot on what your actual application is.
07-05-2017 03:50 PM
What I would do is run this in a for loop, and create an array of voltages with your setpoints. When you build that array, check that the last element of the array is equal to your final setpoint, if not, tack it on at the end.
Example: 0 to 1 in 0.3 steps.
array = [0, 0.3, 0.6, 0.9, 1.0]
07-05-2017 04:00 PM
Don't forget that checking for equality with floating point numbers that use decimals is bad. Because in the lovely world of floating point math, 0.3 + 0.3 + 0.3 DOES NOT equal 0.9, it equals 0.899999999999999911.
I would recommend you run the new set point each loop through the "In range and coerce" primitive, with a 0 as min and 2 as max, use the coerced(x) value as the set point, and stop the loop as soon as the "In range?" output goes False.
07-05-2017 04:28 PM
Hi guys,
Thank you for all your suggestions. Taki1999, I investigated the PID and fuzzy logic toolkit, which I do in fact have. I think I will try some other methods first as I fear I might have to restructure my whole code to implement the VIs. gregoryj and Kyle, I will investigate your methods starting with Kyle's. I'll report back with any successes or failures! Thanks again for your time!