05-21-2009 02:11 PM
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.
Solved! Go to Solution.
05-21-2009 03:24 PM
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).
05-21-2009 03:42 PM - edited 05-21-2009 03:43 PM
05-21-2009 05:11 PM
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.
05-21-2009 08:43 PM - edited 05-21-2009 08:48 PM
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.
05-22-2009 07:14 AM
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.
05-22-2009 02:55 PM