From 04f9ca4febf01d63ace7cfbe71236f3694d99f27 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 12 Dec 2014 15:08:07 -0500 Subject: [PATCH] Change vision defaults from "cam1" to cam0". Add some error reporting to Intermediate Vision example Change-Id: If0bb60611c6c5e6f2411ad5d0432c712b24efb24 --- .../examples/IntermediateVision/src/Robot.cpp | 21 +++++++++++++------ .../wpilibC++Devices/include/CameraServer.h | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp index a6037ed36a..b6f101264f 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp @@ -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); diff --git a/wpilibc/wpilibC++Devices/include/CameraServer.h b/wpilibc/wpilibC++Devices/include/CameraServer.h index 53b3135ea5..67b78ccc25 100644 --- a/wpilibc/wpilibC++Devices/include/CameraServer.h +++ b/wpilibc/wpilibC++Devices/include/CameraServer.h @@ -25,7 +25,7 @@ class CameraServer : public ErrorBase { static constexpr uint32_t kSize320x240 = 1; static constexpr uint32_t kSize160x120 = 2; static constexpr int32_t kHardwareCompression = -1; - static constexpr char const *kDefaultCameraName = "cam1"; + static constexpr char const *kDefaultCameraName = "cam0"; public: static CameraServer *GetInstance();