01-09-2013 12:45 AM
I made a vi that controls a stepper motor with controls such as relative angle, maximum frequency, and acceleration. I use an event structure to update the values after new ones are entered by the user. However, recently I was given the task of integrating this with a larger vi that controlled other parts for an experiment (I will refer to this as the motor control vi).
Would event structures in both vi's be necessary? If I want to have the controls and update button in the motor control vi, does this mean that the event structure should be completely eliminated from the stepper motor vi? I was advised to use local variables to store the values for relative angle, max freq, and acceleration and then pass all of it when the update button is triggered and creates an event. I have found this to be faulty. Would it be possible to have event structures in both vi's then?
Basically, now everything will be updated and passed from the main vi to a stepper motor vi that originally depended on an event structure. Does this require the event structure to be present in only one or both vi's? Thanks.
01-09-2013 04:26 AM
01-09-2013 05:59 PM
Hey, sorry for not including it before, I'll try my best to explain all the parts because I didn't want to overcomplicate things.
For the Stepper Motor vi, I have none of the DAQ drivers on my laptop at home so I excluded it in the file attached and simply put a text box in there place. The program starts after the run button is pressed, and then the acceleration, f max, and relative angle is entered. Afterwards, pressing update displays the appropriate waveform graph. Pressing "next task" (depending on the state of the use task button) will allow the user to input other values. The use task button simply indicates whether anything will be passed to the drivers or not.
The main Motor Control vi was done by another person. For my part (all on the right side), acceleration could be set to 3 different speeds and pressing the button triggers the event that sets a certain value to the local variable acceleration. When the update button is pressed on this vi, the new values for max speed, angle, and acceleration are sent to the Motor Client vi. The state of the run, stop, use task, and next task are also passed, and my current problem is how do I use the update button in this vi? Would passing its value create an event in the stepper motor vi? Or would it be much better to just send the controls without placing them in an event structure?
01-09-2013
06:37 PM
- last edited on
04-27-2025
12:41 PM
by
Content Cleaner
Where to start? Putting it bluntly this code is a mess. When I see code like this the first thought that comes to mind is it needs to be rewritten. First, it you need a wall to display the entire block diagram you really need to think about making your code more module. If you can't see all of the code at one time it is extremely difficult to understand it. When block diagrams are this large I don't spend a ton of time trying to figure out exactly what they are doing.
You use way too many sequence structures and local variables. Take some time to learn about state machines and data flow. Both will help you immensely at cleaning up your code.
Your motor code has multiple event structures in it. This can be problematic. Generally speaking a single VI should use one event structure.
Try to be a bit neater with your wiring. Clean code is much easier to understand, manitain and enhance. Take a look at the style guide for some recommendations.
With respect to your specific questions there are far too many chances for race conditions in this code due to the abuse of local variables. If you need to synchronize your code you should consider using queues, notifiers or user events. They are the prefered methods.