help with turret code

right now im attempting to write some code for our turret to scan back and forth across the field between two limit switched until a large enough target is seen. I just had one failed attempted in which I created a state machine using some boolean operators to modify the direction of the motor based on which of the two limit switches was hit and which direction the motor was last commanded to go. The motor flickered back and forth. I think it had something to do with passing the last motor command to a shift register for evaluation the next cylce.

I’m wondering if anyone has any suggestions that are simple that I can use? Only got a day left and really want to get our turret working for testing tomorrow. I’m sure that this has been done before.

One suggestion was to just stop the motor however I want the turret to “scan” back and forth across the field.

Suggestions much appreciated! Mahalo!

your state machine approach is correct, though i dont exactly know what you hope to accomplish with the shift registers… youd hope that part of the code would be in the “main loop”.

id just store the state in a local variable. The only reason i can think of for the states “flickering” back and forth is you have inverse logic on the switches; your transition condition is satisfied immediately (true on release, false on press). its kinda hard to diagnose exactly without a vi and how its called.

okay got more and my batteries are recharged. This might be a dumb question, but how do you create a local variable exactly for storing the state variable? I redid the state diagram and realized that the state table is much simpler than I had thought.

I’d use a shift register for this. Maybe a feedback node, depending on how simple the state machine logic is.

Thanks Alan! I was able to get the code to work as you say using a shift register.