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: 

on button hold continually push enque

Solved!
Go to solution

hey guys,

im working on a robotics project where I use front pannel buttons to control servos and motors. The design pattern is a producer consumer with a queue to pass front pannel events to the hardware loop.

 

I have the basic functionality working fine but the way I handle holding the button and continually incrimenting the servo is by locking the hardware loop in a while loop testing the front pannel button to exit the extra while loop. I now need to begin testing the wheel encoders and updating a second servo to approach the first servos position at set intervals, the processing for this happens in a data loop so is working up till it queues a hardware command to actually incriment the second servo. my current issue is I cant set a second servo to update while the hardware loop is locked on the first servo.

 

is there a way I can set the event structure to continually place the event in the queue as I hold the button so as the interrupt for the second servo is working the commands to the second servo get interleaved in with the first servo updating. ( I hope that makes sense)

 

is there a better way to do the whole thing? I was playing with an idea to use an update all command for the servos and always push the current position value to every servo connnected everytime I update any servo position. is that a better way to go about this?

 

thanks for the help guys

 

0 Kudos
Message 1 of 5
(2,751 Views)

There's a little too much in there for me to picture easily.  If you could post some example code, it would be illuminating.

______________________________________________________________________
The avatar is for the best weapon in any game ever. But nobody goes there anymore.

CLAD, LV2013, LV2015
0 Kudos
Message 2 of 5
(2,743 Views)

sorry heres something quick I threw together that I hope helps

0 Kudos
Message 3 of 5
(2,734 Views)
Solution
Accepted by topic author pathare535

If you want the Servo2 commands interleaved with Servo1, then the first step is to get rid of that while loop.  A queued state machine (what you have here) should avoid states which run for a long duration.  Instead, change the "update servo1" to a State which also gets added to the Queue.  It can then add itself to the Queue to occur again and again.  Any steps which need to interrupt this may be enqueued to the front of the queue.

 

Finally, to stop updating servo1 (a replacement for your current "end loop" condition) will be a user event that enqueues to the front a "stop update" state (so it interrupts) and have it flush the queue... add an idle state after the flush if you have an idle state in your state machine.

 

 

The goal here is not to "perform A while holding the button", but to "Start A on button press and perform A until the button value is false"  

Message 4 of 5
(2,708 Views)

As I saw this posted I had found another method that was similar using the timeout in the event structure, I got that working but I liked your idea more, I hadnt thought to just requeue the same event from inside the event. I didnt use the flush queue part though I just placed the requeue inside a case structure using the button boolean as the control.

 

thanks for the advise

0 Kudos
Message 5 of 5
(2,696 Views)