Go to Post Being good people is as important as being the winners of some robotics competition! - ExTexan [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 10-06-2010, 13:53
Lisa Perez's Avatar
Lisa Perez Lisa Perez is offline
Registered User
FRC #0573 (Mech Warriors)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Bloomfield Hills, MI
Posts: 1,291
Lisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond repute
Multiple Dequeue Element VIs in loop

I'm fairly new to LabVIEW, so bear with me here...

I am working on a project that entails real-time command of 6 non-FRC robots over virtual COM ports. To send the commands, I have been utilizing a state-machine architecture.

I created one event handling loop, one state-machine loop, and 6 queues - one for each robot. I set these queues up with different names, and input a Dequeue Element VI for each queue in the state-machine loop. When I ran the program, only one Dequeue Element functioned, even though there were no error outs. As a result, only one robot received commands.

I scaled down to a 2-robot program to simplify things, only to get the same result. However, when I took one Dequeue Element out of the state-machine loop and put it into a new, additional state-machine loop, both robots received their commands (see attached figure).

Does anyone know why having multiple Dequeue Elements in one state-machine loop did not work out? The code attached works, but for future purposes, I would like to know and cannot seem to find any documentation that would explain my results.

Thanks!
Attached Thumbnails
Click image for larger version

Name:	Queue Screenshot.png
Views:	100
Size:	55.0 KB
ID:	9148  
__________________
Event Coordinator - Center Line District Event
Volunteer Coordinator - Michigan State Championship

Lead Mentor - Team 573, Mech Warriors
Former Mentor - Team 830, Rat Pack and Team 3182, Athena's Warriors
Proud Alumna - Team 573, Mech Warriors and Team 1, Juggernauts
Reply With Quote
  #2   Spotlight this post!  
Unread 10-06-2010, 15:06
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Multiple Dequeue Element VIs in loop

I'm far from a Labview expert (only experience has been with custom dashboard functionality) so forgive me if I'm off base, but I think I see the potential problem.

It looks like your command is getting bundled into a cluster in the case statement on the left ("Submit Turn...) and you're trying to pass the cluster to all 6 robots for processing by all N robots (I assume the dequeue block is the block at the top of the "Robot 2" case). Is that correct? If so, then your problem is that you're not processing all N robots since the case labeled "Robot 2" is only being processed for whatever the tab control is set to. You probably either want to either loop over your N robots or process them in parallel somehow.

Hopefully that helps

EDIT: Now that I look at it again, I might have been misinterpreting it slightly. Logically, it would make sense for the block in the "Robot 2" case to be the enqueue and the dequeue to be in the "Robot N" loops you have at the top and bottom, with the dequeue being the block on the left side of those. The issue of not processing all queues because of the case statement is still an issue though because you'll only enqueue for the selected robot. So it might not be a problem with the dequeues, but rather an issue of enqueuing for all the robots

Last edited by Dave Scheck : 10-06-2010 at 15:12. Reason: Took a second look
Reply With Quote
  #3   Spotlight this post!  
Unread 10-06-2010, 15:20
Lisa Perez's Avatar
Lisa Perez Lisa Perez is offline
Registered User
FRC #0573 (Mech Warriors)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Bloomfield Hills, MI
Posts: 1,291
Lisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond repute
Re: Multiple Dequeue Element VIs in loop

Actually, I only pass a cluster to one robot at a time. I have my GUI set up such that I select the robot I want to apply a command to and then enter values for velocity, distance, etc. All of that information is what gets clustered. With this structure, I can wait any amount of time before inputting another command for any of the robots, and have those commands process immediately.

The Dequeue Element VI is actually the block on the left of each state-machine, here. What I had before was one state-machine with two Dequeue Elements in parallel inside.

Thanks anyway!
__________________
Event Coordinator - Center Line District Event
Volunteer Coordinator - Michigan State Championship

Lead Mentor - Team 573, Mech Warriors
Former Mentor - Team 830, Rat Pack and Team 3182, Athena's Warriors
Proud Alumna - Team 573, Mech Warriors and Team 1, Juggernauts
Reply With Quote
  #4   Spotlight this post!  
Unread 10-06-2010, 16:50
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Multiple Dequeue Element VIs in loop

I went through the exercise of making a test program and got it to work. It's based around the same model that you have. The loop in the middle waits for the input and enqueues it to the necessary queue. The other two loops are waiting on their dequeue and will update the corresponding output when data is seen. This seems to work as expected. See the attached diagram

My example used just an integer as input, but I tried passing a cluster around to make sure there wasn't something different with that, but it worked just fine.

Have you tried to run with the execution highlighted to make sure your loops are running as expected? I had a bug when testing that caused only one loop to run (made the mistake of having a stop control from one loop tied to the end condition of the other while loops). Maybe you're hitting something silly like that?
Attached Thumbnails
Click image for larger version

Name:	queue.jpg
Views:	43
Size:	46.0 KB
ID:	9149  
Reply With Quote
  #5   Spotlight this post!  
Unread 10-06-2010, 17:38
Lisa Perez's Avatar
Lisa Perez Lisa Perez is offline
Registered User
FRC #0573 (Mech Warriors)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Bloomfield Hills, MI
Posts: 1,291
Lisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond repute
Re: Multiple Dequeue Element VIs in loop

I apologize for the confusion about what I'm actually asking - The picture I attached (one Dequeue per state-machine loop) is the code I got to work. I was curious as to why my previous code, the one that had two Dequeues in one state-machine loop, didn't.

Could I possibly be having race condition issues? I didn't think so because of the fact that I have separate clusters for separate queues going to separate robots, but am I wrong?

Thanks!
__________________
Event Coordinator - Center Line District Event
Volunteer Coordinator - Michigan State Championship

Lead Mentor - Team 573, Mech Warriors
Former Mentor - Team 830, Rat Pack and Team 3182, Athena's Warriors
Proud Alumna - Team 573, Mech Warriors and Team 1, Juggernauts
Reply With Quote
  #6   Spotlight this post!  
Unread 10-06-2010, 18:11
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Multiple Dequeue Element VIs in loop

Sorry for misinterpreting your question. Hopefully third time's the charm.

I changed my example to have a two loops instead of three like you're saying. In the "state machine" loop, I put two dequeue statements in parallel that update their corresponding outputs.

What I found was that when the iteration of the loop starts, both dequeue blocks are sitting waiting for data. When one queue gets its data, the second queue is still blocking. Unless that second queue data gets data, the first queue will never be dequeued again. This is because the loop iteration can't complete since everything inside the loop hasn't completed.

I was able to get this to work by doing the following
- On the timeout terminal of the dequeue block, add a constant of 1 (dequeue tries to get data for 1ms then gives up)
- Send the timed out terminal into a case structure. In the false case, put your processing of the data from the queue

What this will do is give each queue a chance (1ms) to process each loop of the iteration. If there is data waiting for it, it will be processed. If not, it wastes the amount of ms in the timeout. Chances are with the way Labview works, they will all happen in parallel since they're not dependent on each other, which means you shouldn't be wasting too much time in the timeout cases.

I can post a picture if you need me to.
Reply With Quote
  #7   Spotlight this post!  
Unread 10-06-2010, 21:49
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Multiple Dequeue Element VIs in loop

Correctly diagnosed.

As originally written, but not what was posted, the code was told to wait for all six queues to have something posted to them before running the next loop iteration and processing the second command in any of the queues. That would in fact be a pretty odd requirement for a state machine, but that was what was written.

Using the timeout to avoid the blocking of the dequeues will allow the original code to work, but it also makes it effectively a polled loop. Technically, the loop will run sooner if all queues have something in them, but if nothing is posted, the loop would run every 1ms. Probably not a big performance issue, but that would depend on what you expect.

Depending on what is being enqueued and how they are processed, there are two pretty common patterns.
1. Go with a loop per queue. Don't be afraid to put the loop into a subVI which may allow you to reuse code depending on the processing, and will make the code much more readable. Because LV execution is not stack based, the engine can efficiently sleep very large numbers of parallel code clumps such as the loops, and they will awaken and be scheduled with very little overhead.
2. If you are wanting to process the results more centrally because of combined effects, consider posting to a single queue, but put an array into the queue data and combine up to your six data items into the array.

Greg McKaskle
Reply With Quote
  #8   Spotlight this post!  
Unread 10-06-2010, 22:05
Lisa Perez's Avatar
Lisa Perez Lisa Perez is offline
Registered User
FRC #0573 (Mech Warriors)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Bloomfield Hills, MI
Posts: 1,291
Lisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond reputeLisa Perez has a reputation beyond repute
Re: Multiple Dequeue Element VIs in loop

Dave and Greg: Thank you for your suggestions! Looks like I've got the original program up and running now (although I will indeed be keeping the multiple state-machines as set up in my revised program as you both have suggested).
__________________
Event Coordinator - Center Line District Event
Volunteer Coordinator - Michigan State Championship

Lead Mentor - Team 573, Mech Warriors
Former Mentor - Team 830, Rat Pack and Team 3182, Athena's Warriors
Proud Alumna - Team 573, Mech Warriors and Team 1, Juggernauts
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
game element blackiceskier General Forum 11 23-10-2009 13:15
[FTC]: Multiple Programs or One Program with Multiple Auto Modes kevin51292 FIRST Tech Challenge 4 02-01-2009 20:37
07 Game element? bear24rw Rumor Mill 15 05-01-2007 18:38
pic: Division By Chicken Element Tim Delles Robot Showcase 2 12-04-2006 21:26


All times are GMT -5. The time now is 11:06.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi