04-02-2013 12:56 PM
Hello all,
Background:
I have a while loop which is set up to talk to two servos over ethernet where a a numeric control, which specifies the millisecond pulse width, controls them. Once a servo is set, there is a read from the device which gives me the servos millisecond pulse width (verification that everything is working). I want to be able to save and load these pulse widths on the fly by the end user (not me). Therefore, I created a Configure File which is told to save and load specific keys in different sections.
Problem:
I can not seem to get the control to respond how I want to. Originally, I thought the data wasn't being loaded correctly, so I probed the line and found that the data is in fact loading with the correct pulse width. The problem is that when I load the data from the Config file, I am only updating the servos and not the control. Therefore, the servo is set to the preset's value in 1 iteration and the next iteration it is set to the control. As an example, the control value is 1000 and the preset value is 2000, the servo is told to go to 2000 and then immediately told to go back to 1000.
Can someone please help me figure out to set the control from the preset?
I tried searching on the forums, but searching with terms "update control via preset" are extremely vague and I do not know how to word differently.
Thank you in advance,
Matt
04-02-2013 01:02 PM
To programmatically change the value of a control you need to use either a local variable or a property node. A local variable is the preferred method provided you do not need to change any properties on the control. You would write the values read from the config file to the local variables at the same place you update the servos. Also, it is generally easier to post your code so we can actually see what you have done. As they say, a picture is worth a 1000 words.
04-02-2013 01:47 PM
Ha, I knew I forgot something 🙂 Here's my code and I'm looking into local variables now. As a heads up, its mostly LIFA (Labview Interface For Arduino). I declare input and output pins in the arduino code. The Load/Save presets control the main loop and when none are true, it runs the set manual code. My question is in the "FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE" (load preset 1). With that case, I load the Keys from the Config file and update the servos
Any tips to make the code look nicer is gladly appreciated 😄 I can take constructive criticism.
Thanks,
Matt
04-02-2013 04:07 PM
Be careful comparing double precision numbers for equality. They may never be equal. Even numbers that look equal might not truly be.
I would consider building the booleans into an array. Then convert that array to a U8 number. Drive the case structure with that. You can turn on the binary display for the case structure titles so that instead of a text string of Trues and Falses, they would be 0's and 1's.
Some code seems to be repeated. I would consider making that code into a subVI, or combining the cases in a way to account for that.
04-03-2013 09:54 AM
I updated a lot of my code to make it run faster. I am looking into the making the case loop turn into 1's and 0's instead of TRUE and FALSE's.
However, I am still running into the problem with updating the servos. I can't think of a way to update the control from my preset value. I was thinking about having an xor gate to control the servo with either the preset value OR the control. The indicator (gauge) would point to the true value of the preset, but the control would remain unchanged. I would like to have the control be updated with the preset value. Therefore, my idea can work, but its not exactly what I'm looking for.
Matt
04-03-2013 10:27 AM
For your manual buttons, you have them set for a mechanical action of "Switch Until Released". Is that what you want? That means they may never even be read if you happen to click them and let go before the section of the code that reads them hasn't had a chance to execute. You don't have anything that maintains the existing state of those buttons.
You could use local variables to update those buttons to change them from true to false or vice versa.
You probably should be looking at an architecture that uses events to determine when buttons are pressed (Boolean value changed) and send messages to the controller accordingly.
04-03-2013 11:37 AM - edited 04-03-2013 11:38 AM
I do have my digital logic booleans (D0-D5) set to "switch until release". Those are connected to a T/F case structure which then tells the Arduino to set a pin high/low. All that is taken care of. The only big problem I have left is updating my servos to the correct value.
Attached is an image which I hope can explain my problem better. The top half is when I have my VI running normally (not loading a preset). I have my control (Green circle on the front panel and orange circle on the block diagram) updating the servo block (red square) with the desired value. From there, the servo is being read and that updates the gauge indicator with it's value. When I load a preset (bottom half), I load the data from a configure file (the value is being loaded from the black square) and update the servo with that value (brown square).
Now here's where I can use advice. I would like the green/orange circle to be updated to the black square's value. As soon as my preset loads (bottom half and black square) and starts running normally again, the servo is updated immediately from the control (green/orange circle). I want to be to update the green/orange circle with the value from the black square.
Thanks
Matt
04-03-2013 11:55 AM - edited 04-03-2013 11:57 AM
Write to a local variable of the control. We generally discourage using local variables because there misuse can lead to abuse, and people getting upset that their VI's are running the way they expect it to. (Search for terms "dataflow" and "race condition".) But this would be an appropriate use for local variables.
I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
04-05-2013 01:55 PM
I ended up using local variables to update the indicators which made my life a lot easier. I see where local variables can cause harm, but each is in it's case (I changed everything to case structures) and I made the indicators update at the very end.
Thanks to everyone that helped me!
Matt