Quote:
Originally Posted by rod@3711
Just having one call to StartAutomaticCapture with the correct name (ie cam2) got things going. We will give up on getting 2 cameras going.
|
You could modify the Intermediate Vision example to allow you to switch between cameras.
Code:
#include "WPILib.h"
/**
* Uses IMAQdx to manually acquire a new image each frame, and annotate the image by drawing
* a circle on it, and show it on the FRC Dashboard.
*/
class IntermediateVisionRobot : public SampleRobot
{
IMAQdxSession camera1;
IMAQdxSession camera2;
Image *frame;
IMAQdxError imaqError;
public:
void RobotInit() override {
SmartDashboard::PutBoolean("Camera Select", true);
// create an image
frame = imaqCreateImage(IMAQ_IMAGE_RGB, 0);
//the camera name (ex "cam0") can be found through the roborio web interface
imaqError = IMAQdxOpenCamera("cam0", IMAQdxCameraControlModeController, &camera1);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxOpenCamera error: " + std::to_string((long)imaqError) + "\n");
}
imaqError = IMAQdxConfigureGrab(camera1);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxConfigureGrab error: " + std::to_string((long)imaqError) + "\n");
}
//the camera name (ex "cam1") can be found through the roborio web interface
imaqError = IMAQdxOpenCamera("cam1", IMAQdxCameraControlModeController, &camera2);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxOpenCamera error: " + std::to_string((long)imaqError) + "\n");
}
imaqError = IMAQdxConfigureGrab(camera2);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxConfigureGrab error: " + std::to_string((long)imaqError) + "\n");
}
}
void OperatorControl() override {
// acquire images
IMAQdxStartAcquisition(camera1);
IMAQdxStartAcquisition(camera2);
// grab an image, draw the circle, and provide it for the camera server which will
// in turn send it to the dashboard.
while(IsOperatorControl() && IsEnabled()) {
bool which = SmartDashboard::GetBoolean("Camera Select");
IMAQdxSession& capture_cam = which ? camera1 : camera2;
IMAQdxGrab(capture_cam, frame, true, NULL);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxGrab error: " + std::to_string((long)imaqError) + "\n");
} else {
CameraServer::GetInstance()->SetImage(frame);
}
Wait(0.005); // wait for a motor update time
}
// stop image acquisition
IMAQdxStopAcquisition(camera1);
IMAQdxStopAcquisition(camera2);
}
};
START_ROBOT_CLASS(IntermediateVisionRobot);
If you want to stream cameras simultaneously, the easiest way would probably be to do some small modifications to the CameraServer class and the dashboard widget to configure different ports for the streams. Be careful about saturating the field bandwidth if you do that, though.
Quote:
Originally Posted by rod@3711
Now the image is seems overexposed. If I use change speed slider bar on dashboard, the image is good for one or 2 update, then back to overexposed. Any ideas?
|
I'm not sure what the 'speed' slider adjusts, but try changing the exposure on the camera. You may be able to do it through the RoboRIO's web interface (don't have one in front of me to check), but here's how you could do it in code:
Code:
CameraServer::GetInstance()->SetQuality(50);
std::shared_ptr<USBCamera> camera(new USBCamera("cam1", true));
camera->SetExposureManual(50); // change this value
camera->SetBrightness(50); // change this value
CameraServer::GetInstance()->StartAutomaticCapture(camera);
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor