Go to Post Comments and Documentation: Use them! You would never believe how fast you will forget how something works, especially when things are flying at you so fast. Other/future programmers will understand what you did and why you did it. - BigJ [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-01-2016, 01:59
jojoguy10's Avatar
jojoguy10 jojoguy10 is offline
Programming/Controls Mentor
AKA: Joe Kelly
FRC #0997 (Spartan Robotics) and FRC #2990 (Hotwire Robotics)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Stayton, OR
Posts: 283
jojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of light
Switching between two webcams on the dashboard

I know I know! There are already a LOT of these type of threads! Just hear me out :-)

We are working on trying to have a front and rear webcam for our robot. We want the view on the dashboard (the default LabVIEW dashboard) to switch cameras by either a press of a button or autonomously.

We have tried the various methods here on CD, but nothing worked yet.

One thing we noticed was that the RoboRIO is showing both webcams in the Configuration page (roborio-2990-frc.local/) as "cam0" and "cam1", but they're both enumerated as "USB0" (see attachment)

We're wondering if this might be our problem. Is this supposed to happen? If so, does anyone have a WORKING LabVIEW example of switching webcams?

Thanks!

(Again, sorry for ANOTHER post about dual webcams, but I feel like this is a bit of a different issue then the rest)
Attached Thumbnails
Click image for larger version

Name:	RoboRIO Dual Cameras.png
Views:	155
Size:	221.4 KB
ID:	19914  
__________________


Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2016, 07:51
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,748
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: Switching between two webcams on the dashboard

The USB0::0x... are the fully-qualified addresses that VISA and some other drivers will call the camera when they enumerate. The OS HID drivers use the same or a similar technique. This includes which USB controller, which hub, and which port on the hub the device is plugged into. It is unrelated to the USB 0 and USB 1 addresses that the WPILib camera stuff uses.

One way to get what you are asking for is for me to describe a bit more about the camera server that is inside of Send2PC. It is written to use only one port and one camera. But with a few small tweaks, you can make ones that will serve two cameras. Then you can decide which is paused and which is streaming.

If you start with the Vision Processing block diagram, there is a string of initialization functions to ensure the camera is in a predictable state, then this refnum forks and goes into the loop and goes to the Background Loop subVI. Open the Background subVI.

As the comment states, this subVI does one thing for IP cameras and another for USB cams. They were combined into one abstract background subVI, but have little interaction. The left-most camera function determines whether this is a USB camera or not. If it is USB, the only thing that executes is the Send2PC Loop. So lets open that one next.

Send2PC listens for a connection on port 1180. That is not a parameter, but a constant. So if you want two cameras, you probably want two ports. Once it has a dashboard connection, it sets up the camera, starts it, and loops acquiring and sending them to the port. This implements both the SW compression and HW compression options and has code for a two-port cRIO that requires the data be forwarded. But the important thing to notice is that this code uses an image named WPILib_SendtoPCImage to get the image from the camera. It wouldn't be good to use the same image name for different cameras.

So. If you clone the Send2PC VI and make the image name and port be unique, you now have two camera servers. If you are using USB for both, don't bother with the background loop, you can just drop your Send2PCA and B versions and wire up the parameters.

Some teams want two small simultaneous streams, and the customizations I've described should work for them. You wanted a switch. So I'd recommend you then add some pause/run code to the loops to leave both cameras open and on a unique port and control which is working and which is paused.

On the dashboard, you have a few edits to make as well. The vision loop listens on one port, stores to one AVI file, displays to one image display, etc. If you dig down inside the code, the important work happens in Get on PC. It opens and communicates on port 1180 and decodes transmitted data into your image. If you have two of these connected to the appropriate port, hint, make the port be a parameter, then you can leave both running and display the one the driver is interested in.

So, with a few edits, you can make variations of the Send and Get PC camera servers to do what you want. I believe some teams have made these changes in years past, so you may not need to make them yourself, but they aren't that hard or risky.

I'm happy to answer questions.
Greg McKaskle
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2016, 11:33
jojoguy10's Avatar
jojoguy10 jojoguy10 is offline
Programming/Controls Mentor
AKA: Joe Kelly
FRC #0997 (Spartan Robotics) and FRC #2990 (Hotwire Robotics)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Stayton, OR
Posts: 283
jojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of light
Re: Switching between two webcams on the dashboard

Greg sir, you are amazing! VERY detailed instructions! Thanks! We will be testing out this code today at the shop and I'll post back with our findings.
__________________


Reply With Quote
  #4   Spotlight this post!  
Unread 31-01-2016, 18:14
teku14's Avatar
teku14 teku14 is offline
http:
FRC #2614 (MARS)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2013
Location: Morgantown, WV
Posts: 64
teku14 is a jewel in the roughteku14 is a jewel in the roughteku14 is a jewel in the roughteku14 is a jewel in the rough
Re: Switching between two webcams on the dashboard

So I followed the instructions and didn't have success although its most probably because I didn't follow the instructions correctly. I'm posting the changes I made below and maybe you could point out where I went wrong.

Starting with the robot code, If I understand this correctly, the Camera Background VI just houses the Send 2 PC VI and you can ignore everything else if the camera is run over USB. So the first thing I did was make a modified version of the Send 2PC VI or as its called WPI_CameraSend Images to PC VI.
https://drive.google.com/open?id=0Bw...ngwNDJrd1pHM2M
In it, I the changed the port number constant wired into the TCP Listen VI to a control named "port". This was originally just set to 1180. Then I changed the Image Name Constant going into IMAQ create VI into a string control as well whereas it was originally the WPILib_SendtoPCImage you were referring to.

I named this VI as "Sketchy Send 2 PC" just to keep track of changes but you can see that I placed this directly onto the vision processing VI.
https://drive.google.com/open?id=0Bw...G1VUVZNWFJVODg
Originally the set of set up VIs associated with "USB 1" was not there as shown below. I just branched the single original camera reference into to two separate "Sketchy Send 2 PC" VIs while maintaining the same parameters that you see in this image being 2 different port numbers 1180 and 1179 (I'm not very familiar with so I just used 1 number less thinking it to be legitimate) and then "WPILib_SendtoPCImage A" and "WPILib_SendtoPCImage B" for the two VIs Respectively. When this, along with the other changes didn't work, I made the change that you see in the image where I'm opening two separate Camera References.

Next in the Dashboard, I made the following changes:

Starting from the Camera Loop (Loop #2) and going further in

Essentially, Just modifying each concentric VI to change the 1180 TCP port constant at the bottom most level, to something that I can change on the dashboard while its running.

https://drive.google.com/open?id=0Bw...lctRkJ4QVF0R2s
https://drive.google.com/open?id=0Bw...nRrd2hhRTg2aG8
https://drive.google.com/open?id=0Bw...jhMNE5fSTkxdVE

At the end of this, I the code is still able to recognize and display one USB camera but cannot change the display to the second one whenever I bump the port number on the dashboard (while its running) between 1180 and 1179. It just stays on the same original camera. I cannot tell which camera I have assigned port 1180 or 1179.
Reply With Quote
  #5   Spotlight this post!  
Unread 31-01-2016, 19:53
jojoguy10's Avatar
jojoguy10 jojoguy10 is offline
Programming/Controls Mentor
AKA: Joe Kelly
FRC #0997 (Spartan Robotics) and FRC #2990 (Hotwire Robotics)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Stayton, OR
Posts: 283
jojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of light
Re: Switching between two webcams on the dashboard

Hey Teku14,

We successfully (after 5 hours!) managed to switch webcams. I will post the relevant VI snapshots and try to explain them the best I can. Here is a link to the code we tried and some annotated screenshots.
https://drive.google.com/folderview?...&usp=sha ring

Vision Processing:
We created two cameras (notice the different RefNum names ) and wired them into our new Background Loop VI.

CameraBackground Loop:
We had to create a second RefNum input for the second webcam and run two (2) Send2PC loops (one for each camera).

Send2PC:
It looks like you did the Send2PC perfectly. Just create controls for the port and the image name, and set them as inputs for the VI.

DASHBOARD:
DashboardMain:
We had to do a bit of trial and error to get this to work correctly. We have a bit of code (highlighted in the orange box) that would "refresh" the feed and the port. Without that code, we would flip the camera switcher, but the image wouldn't update with the new camera unless we switch from Camera HW to Camera SW (or vice versa). So, this little block of code automatically switches from HW to SW (or vice versa) if the port changes.

CameraRead_MJPG:
This was a tricky VI because it was a clone and you can't edit a clone. The trick I found to edit a VI is:
  • In the DashboardMain VI, do a CTRL+F (find)
  • Next, under "Select Object", click the "Add" button and go to: Objects in vi.lib and if you scroll all the way down, you will see the Camera VIs
  • Find the Dashbd MJPG VI and left-click on it
  • Next, in the "search Scope", choose the "<All VIs in Application Instance>" and make sure the "Hierarchy Window" checkbox is checked
  • Flick Find
  • Double-click on "VI Hierarchy"
  • You should be able to click and drag the VI (Dashbg MJPG) into the Dashboard Main VI so you can edit it
Now that you have that VI, you can open it up and continue on. Yay!

Inside that VI, there is a "Get On PC" VI inside the "1, 2" case in the middle case-structure. We had to edit that too :-)

Get on PC:
Since this VI is also a clone, do the same steps as above with the MJPG VI, (but, obviously, look for the Get On PC instead )

Moving on...

All we had to add was a control for the camera port and make it an input for the VI.


That's what we did. Let me know if you have any further questions at all.

Thanks again Greg for getting us on the right foot
__________________


Reply With Quote
  #6   Spotlight this post!  
Unread 31-01-2016, 21:08
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,748
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: Switching between two webcams on the dashboard

You are welcome. Glad you got it working and are willing to share the results.

Also, if you have a reentrant clone VI and need to edit it, press ctl-m, which is a shortcut for Operate >> Change to ... Mode. This lets you go between run and edit mode for any VI. Clones default to Run Mode.

Greg McKaskle
Reply With Quote
  #7   Spotlight this post!  
Unread 01-02-2016, 01:43
jojoguy10's Avatar
jojoguy10 jojoguy10 is offline
Programming/Controls Mentor
AKA: Joe Kelly
FRC #0997 (Spartan Robotics) and FRC #2990 (Hotwire Robotics)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Stayton, OR
Posts: 283
jojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of light
Re: Switching between two webcams on the dashboard

Quote:
Originally Posted by Greg McKaskle View Post
You are welcome. Glad you got it working and are willing to share the results.

Also, if you have a reentrant clone VI and need to edit it, press ctl-m, which is a shortcut for Operate >> Change to ... Mode. This lets you go between run and edit mode for any VI. Clones default to Run Mode.

Greg McKaskle
Glad to help out other FRC'ers :-)

And thanks for that tip. That's MUCH easier than what we had to do
__________________


Reply With Quote
  #8   Spotlight this post!  
Unread 01-02-2016, 22:02
teku14's Avatar
teku14 teku14 is offline
http:
FRC #2614 (MARS)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2013
Location: Morgantown, WV
Posts: 64
teku14 is a jewel in the roughteku14 is a jewel in the roughteku14 is a jewel in the roughteku14 is a jewel in the rough
Re: Switching between two webcams on the dashboard

Thank you all for the response! Extremely helpful. I will try this out and post how it turns out.
Reply With Quote
  #9   Spotlight this post!  
Unread 03-02-2016, 18:54
teku14's Avatar
teku14 teku14 is offline
http:
FRC #2614 (MARS)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2013
Location: Morgantown, WV
Posts: 64
teku14 is a jewel in the roughteku14 is a jewel in the roughteku14 is a jewel in the roughteku14 is a jewel in the rough
Re: Switching between two webcams on the dashboard

I'm sorry but even after following your instructions and pictures to the dot it doesn't seem to be working. Also the code you attached is trying to access the default WPI VIs that are on my computer. Can you save the modifications you made to the WPI Camera VIs into the project as new VIs and repost it?
Reply With Quote
  #10   Spotlight this post!  
Unread 03-02-2016, 19:24
bvisness's Avatar
bvisness bvisness is offline
Programming Mentor, Former Driver
FRC #2175 (The Fighting Calculators)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Woodbury, MN
Posts: 181
bvisness is a glorious beacon of lightbvisness is a glorious beacon of lightbvisness is a glorious beacon of lightbvisness is a glorious beacon of lightbvisness is a glorious beacon of lightbvisness is a glorious beacon of light
Re: Switching between two webcams on the dashboard

Glad you guys got it all working! Just a piece of advice from a former driver, though – you will probably not be looking at your driver station laptop nearly as much as you think you will. Driving is stressful and dangerous and it's hard to tear your eyes away from the field and down to your computer.

That's my experience anyway. Just something to keep in mind!
__________________
2014 IRI Quarterfinalists (Thanks 368, 1477, 233)
2014 Minnesota State Championship Winners (Thanks 2052, 4778)
2014 Archimedes Quaterfinalists (Thanks 399, 2056, 2834)
2013 Minnesota State Championship Winners (Thanks 2052, 4607)
2013 Galileo Division-Finalists (Thanks 2169, 3284)
Reply With Quote
  #11   Spotlight this post!  
Unread 03-02-2016, 19:45
jojoguy10's Avatar
jojoguy10 jojoguy10 is offline
Programming/Controls Mentor
AKA: Joe Kelly
FRC #0997 (Spartan Robotics) and FRC #2990 (Hotwire Robotics)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Stayton, OR
Posts: 283
jojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of light
Re: Switching between two webcams on the dashboard

Quote:
Originally Posted by bvisness View Post
Glad you guys got it all working! Just a piece of advice from a former driver, though – you will probably not be looking at your driver station laptop nearly as much as you think you will. Driving is stressful and dangerous and it's hard to tear your eyes away from the field and down to your computer.

That's my experience anyway. Just something to keep in mind!
Thanks for the advice! I was the driver for our team for 2 years, and I can concur, however , with how little visibility there is on the field this year, it will be difficult to see what's in front of your robot at times (e.g. a boulder behind the drawbridge).

We have tested the latency on the camera over wifi from the robot (not through the FMS, so it might vary), and it isn't that bad. We calculated it to be only about 90-100ms lag. We had our driver drive it a bit ONLY looking at the webcam image, and he said he could drive it just fine.
__________________


Reply With Quote
  #12   Spotlight this post!  
Unread 07-02-2016, 09:36
jojoguy10's Avatar
jojoguy10 jojoguy10 is offline
Programming/Controls Mentor
AKA: Joe Kelly
FRC #0997 (Spartan Robotics) and FRC #2990 (Hotwire Robotics)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Stayton, OR
Posts: 283
jojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of lightjojoguy10 is a glorious beacon of light
Re: Switching between two webcams on the dashboard

Quote:
Originally Posted by teku14 View Post
I'm sorry but even after following your instructions and pictures to the dot it doesn't seem to be working. Also the code you attached is trying to access the default WPI VIs that are on my computer. Can you save the modifications you made to the WPI Camera VIs into the project as new VIs and repost it?
I will post the VIs. I will try to get them out before the end of the week (school, work, robotics, etc )

Also, I double-checked the rules, and we're not allowed to use port 1181. We have to use a port somewhere in between 5800 and 5810 (per R60)
__________________


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


All times are GMT -5. The time now is 04:18.

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