View Full Version : Refreshing SmartDashboard Simple Camera Feed
MHSrobotics2853
20-01-2015, 00:59
We want to run two cameras this year (for alignment purposes). Right now we're using the Axis M1011 and 206. We would like to turn off a camera when it's not needed to conserve bandwith. We couldn't find a function to turn it off and on. Is there anyway to do that?
We then tried to set the camera that's not in use to a terrible resolution (compression -> 100) after pressing a button on the joystick. However, the SmartDashboard doesn't automatically refresh the feed. We have to disconnect and reconnect for the new settings to take effect or close/reopen SmartDashboard.
Does anyone have a workaround for this? We program in C++ & use Windows.
I don't know if there is a function to turn off a camera but you can choose which image gets sent to the dashboard/smartdashboard (whichever you're using, doesn't really matter).
MHSrobotics2853
20-01-2015, 02:28
I don't know if there is a function to turn off a camera but you can choose which image gets sent to the dashboard/smartdashboard (whichever you're using, doesn't really matter).
How would we be able to do that through code? Is it a function of the SmartDashboard class?
We know how to delete and add widgets on SmartDashboard, but during competition, that would eat up a lot of time, especially if we need to switch angles quickly.
Greg McKaskle
20-01-2015, 07:06
The connection to the camera is an http session. In LV, if you close the TCP handle, the camera will stop sending images. I'm not sure how to do the equivalent in SD.
Greg McKaskle
The "Intermediate Vision" example project contains an example of getting an image from usb camera, modifying it, and then sending it to the dashboard. To have a system where you have multiple cameras and want to choose which img from which camera gets sent to the dashboard you'll need to do several things. The following code examples are in java but it should be similar in c++.
1) You need to create ids for each camera by supplying the camera name, the camera name shows up on the roborio interface ("roborio-TEAM.local/" where TEAM is your team number, "roborio-2853.local/" in your case)
// Get camera ids by supplying camera name ex 'cam0', found on roborio web interface
camCenter = NIVision.IMAQdxOpenCamera("cam0", NIVision.IMAQdxCameraControlMode.CameraControlMode Controller);
camRight = NIVision.IMAQdxOpenCamera("cam1", NIVision.IMAQdxCameraControlMode.CameraControlMode Controller);
2) You need to create an img variable where the img from the camera will be stored to and create a CameraServer that will send it to the dashboard
// Img that will contain camera img
frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_ RGB, 0);
// Server that we'll give the img to
server = CameraServer.getInstance();
3) Before getting imgs from a camera and sending it to the CameraServer you need to setup the camera for streaming and close the streaming of the previous camera
NIVision.IMAQdxStopAcquisition(prevCamId);
NIVision.IMAQdxConfigureGrab(newCamId);
NIVision.IMAQdxStartAcquisition(newCamId);
4) Now for the imgs from the camera to actually show up you need to get imgs from the camera and give them to the CameraServer
NIVision.IMAQdxGrab(curCamId, frame, 1);
server.setImage(frame);
Link to example java project: https://github.com/Merfoo/MultiCamera
If you have any questions feel free to ask :)
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.