Merge "Change vision defaults from "cam1" to cam0". Add some error reporting to Intermediate Vision example"

This commit is contained in:
Brad Miller (WPI)
2014-12-12 14:01:26 -08:00
committed by Gerrit Code Review
2 changed files with 16 additions and 7 deletions

View File

@@ -8,14 +8,21 @@ class IntermediateVisionRobot : public SampleRobot
{
IMAQdxSession session;
Image *frame;
IMAQdxError imaqError;
public:
void RobotInit() override {
// create an image
frame = imaqCreateImage(IMAQ_IMAGE_RGB, 0);
// open the camera
IMAQdxOpenCamera("cam1", IMAQdxCameraControlModeController, &session);
IMAQdxConfigureGrab(session);
imaqError = IMAQdxOpenCamera("cam0", IMAQdxCameraControlModeController, &session);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxOpenCamera error: " + std::to_string((long)imaqError) + "\n");
}
imaqError = IMAQdxConfigureGrab(session);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxConfigureGrab error: " + std::to_string((long)imaqError) + "\n");
}
}
void OperatorControl() override {
@@ -26,10 +33,12 @@ public:
// in turn send it to the dashboard.
while(IsOperatorControl() && IsEnabled()) {
IMAQdxGrab(session, frame, true, NULL);
imaqDrawShapeOnImage(frame, frame, { 10, 10, 100, 100 }, DrawMode::IMAQ_DRAW_VALUE, ShapeMode::IMAQ_SHAPE_OVAL, 0.0f);
CameraServer::GetInstance()->SetImage(frame);
if(imaqError != IMAQdxErrorSuccess) {
DriverStation::ReportError("IMAQdxGrab error: " + std::to_string((long)imaqError) + "\n");
} else {
imaqDrawShapeOnImage(frame, frame, { 10, 10, 100, 100 }, DrawMode::IMAQ_DRAW_VALUE, ShapeMode::IMAQ_SHAPE_OVAL, 0.0f);
CameraServer::GetInstance()->SetImage(frame);
}
}
// stop image acquisition
IMAQdxStopAcquisition(session);