From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Motor control logic using a state-machine

Solved!
Go to solution

Hi,

 

I am trying to implement motor control using state-machine logic. My requirement is simple. I have a voltage value coming from DAQ which corresponds to torque (Starting value = 5). I need to feed my motor a positive (clockwise rotation) and negative (counterclockwise rotation) velocity based on whether this voltage value is between upper (7 V)and lower (3 V) thresholds. 

 

In other words,  The motor starts rotating clockwise initially; the voltage goes on decreasing, as soon as it hits <= 3 V, it changes direction and moves counterclockwise till it hits >= 7 V, then changes direction again and this repeats for, say user-defined number of cycles. I tried to write this logic, and when I run the program it starts well, it is seeing the first time the input is going below low threshold, changes direction but oscillates at the same position. It doesn't go till >= 7 V. 

 

I am attaching the code for your reference. Can Queued state machine logic be of any help? Also, can I introduce a state wherein after the user-defined cycles are over the motor returns to a position where voltage is 5 V.

 

Thanks a lot.

 

 

Download All
0 Kudos
Message 1 of 7
(3,508 Views)

You say 3-7 volts, but I see comparisons with 4 and 6 in your DAQmx comparisons case. 

I would double check your boolean logic within that case.  It is complicated enough that you could have easily gotten something wrong.

 

I can't see if you have anything stored in a shift register that tells whether you are increasing or decreasing (it might be there, but the boolean wires aren't labelled clearly as to what they mean). 

0 Kudos
Message 2 of 7
(3,496 Views)
Solution
Accepted by topic author Sasidhar
Ravens Fan is correct.  You need to know what direction you are moving before deciding which comparison to make.  Look at this simple diagram that shows how to use a shift register to keep track of which direct you are using.
Message Edited by Wayne.C on 05-21-2009 04:43 PM
0 Kudos
Message 3 of 7
(3,488 Views)

I tried inserting this code in to the existing program,did not work. Maybe I am doing something wrong again. The problem now is that the while loop within the state is executing indefinitely. The program continuously runs in the same state, doesn't go to run at all. Where am I going wrong?

 

Thanks.

0 Kudos
Message 4 of 7
(3,478 Views)

Basic dataflow problems.  That inner while loop will either run once, or it will run forever depending on the value of the boolean that is being passed from outside to the stop terminal.

 

Why do you have the while loop at all?  It just performs the same comparisons over and over at the full speed of the processor.  None of the data inside ever changes.

No inner while loop.  The images that were posted should be applied to the main while loop. 
Message Edited by Ravens Fan on 05-21-2009 09:48 PM
0 Kudos
Message 5 of 7
(3,470 Views)

Sasidhar,

 

Code was meant to be a simple example that demonstrated how to keep track of current direction of travel.  Your code already has a while loop.  Add a shift register to your while loop to keep track of direction of travel.  Modify the comparison part of your state machine to use value stored in shift register to determine which setpoint you are looking for and to update the shift register if a change in direction needs to happen.  You can then use value in same shift register to determine what voltage to output.

0 Kudos
Message 6 of 7
(3,451 Views)
Thanks guys. It worked. I can now go ahead with adding other states to my machine like signal processing, write files, etc. Thanks, u r inputs really helped.
0 Kudos
Message 7 of 7
(3,436 Views)