diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/IntermediateVisionRobot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/IntermediateVisionRobot.cpp new file mode 100644 index 0000000000..a6037ed36a --- /dev/null +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/IntermediateVisionRobot.cpp @@ -0,0 +1,40 @@ +#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 session; + Image *frame; + +public: + void RobotInit() override { + // create an image + frame = imaqCreateImage(IMAQ_IMAGE_RGB, 0); + // open the camera + IMAQdxOpenCamera("cam1", IMAQdxCameraControlModeController, &session); + IMAQdxConfigureGrab(session); + } + + void OperatorControl() override { + // acquire images + IMAQdxStartAcquisition(session); + + // 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()) { + 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); + } + // stop image acquisition + IMAQdxStopAcquisition(session); + } +}; + +START_ROBOT_CLASS(IntermediateVisionRobot); + diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/QuickVision/src/QuickVisionRobot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/QuickVision/src/QuickVisionRobot.cpp new file mode 100644 index 0000000000..00fdffd3bb --- /dev/null +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/QuickVision/src/QuickVisionRobot.cpp @@ -0,0 +1,22 @@ +#include "WPILib.h" + +/** + * Uses the CameraServer class to automatically capture video from a USB webcam + * and send it to the FRC dashboard without doing any vision processing. This + * is the easiest way to get camera images to the dashboard. Just add this to the + * RobotInit() method in your program. + */ +class QuickVisionRobot : public SampleRobot +{ +public: + void RobotInit() override { + CameraServer::GetInstance()->SetQuality(75); + CameraServer::GetInstance()->StartAutomaticCapture(); + } + + void OperatorControl() override { + } +}; + +START_ROBOT_CLASS(QuickVisionRobot); + diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml index d8c7751f07..84261e94df 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml @@ -87,7 +87,12 @@ Example programs that demonstrate the use of the various commonly used sensors on FRC robots - + + Vision + Example programs that demonstrate the use of a camera for image acquisition and processing + + + Motor Controller Demonstrate controlling a single motor with a Joystick. @@ -240,8 +245,45 @@ destination="src/Robot.cpp"> - - + + + Simple vision program + The minimal program to acquire images from an attached USB camera on the robot + and send them to the dashboard. + + Vision + Complete List + + + src + + + + + + + + Getting Started + An example program that acquires images from an attached USB camera and adds some + annotation to the image as you might do for showing operators the result of some image + recognition, and sends it to the dashboard for display. + + + Vision + Complete List + + + src + + + + + + + + GearsBot A fully functional example CommandBased program for WPIs GearsBot robot. This code can run on your computer if it