LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine, PWM, Stepper Motor, Position Sensor

Hi all, I am currently struggling with the attached VI, it was working perfect for a while but now I keep getting mixed results.

 

Basically, a valves position is sensed by 1 of 2 position sensors, which are magnetic/transistor based. Those positions are fed into a 9375 card. That signals the state machine to go to the correct case, which sends duty cycles to the signal simulators, which output a square wave to a 9264 card. Which then sends a 5V pulse to a stepper motor controller.

 

It was working perfect, the valve was stopping right where it should be every time. But now I will get 4 or 5 good valve cycles, then the positions will be slightly off, then accurate again. Any help would be greatly appreciated. Sorry if my VI is a complete mess.

0 Kudos
Message 1 of 3
(1,185 Views)

Hi AELCA,

 


@AELCA wrote:

Any help would be greatly appreciated. Sorry if my VI is a complete mess.


Yes, that VI is a mess. The first step to get a reliable VI is to cleanup that VI and to get rid of any Rube-Goldberg code!

 

Example:

All the code you create from comparisons to case structure to OR-Multiply is exactly the same as that simple ToI32 node above! (Well maybe not "exactly" the same, but that could be done with a simple test afterwards.)

(Why is there a local variable? Why is that value a DBL when it should be an integer? Why do you compare floats for equality?)

 

That part of code including the case structure called after the OR can be done like this:

I didn't spend the time to put all values for each of the 9 cases into those array constants, do the typing for yourself!

 

Other things to change:

  • Use primitives when possible, like "+1"…
  • Use select nodes instead of (simple) case structures to create self-documenting code…
  • Use appropriate datatypes in those shift registers at the top of the loop: no need for DBLs when you do some simple integer counting! Initialize the shift registers!
  • Use MinMax instead of comparison followed by select node to set a minimum value…
  • Don't close a DAQmx task in each iteration!
  • You can resize IndexArray, no need for two IndexArray nodes to index 2 elements from the same array. You can even omit the constants when you index starting from index 0…
  • Get rid of local variables, use wires instead. Why is "CO2 Out" a local variable of the unused indicator? Why don't you change "CO2 Out" to be a control?
  • The enum controlling the state machine needs to be typedef'd. Then use this typedef in all places!
  • Your ExpressVIs to create those AO signals aren't set to create waveforms of the same length!
  • Why is the DAQAssistent labelled "AI" when it is used to output analog data (aka "AO")? Why is it set to use a different sample rate as is used in the SignalGeneration ExpressVIs?

Example:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Download All
0 Kudos
Message 2 of 3
(1,121 Views)

Thank you for taking the time to write all of that out. I have learned quite a bit! The improvements you suggested have definitely streamlined my code greatly. I am getting better results now. The Local variable for C02 is actually coming from another loop. And the differences from the signal generations vi's to the daq assistant vi was a mistake.

0 Kudos
Message 3 of 3
(1,076 Views)