//NOTE: Camera 1 is the default camera. Can toggle to 2 later.
LHSVision::LHSVision(RobotDrive* pRobot, Joystick* pXbox) //Constructor
{
	printf("File %18s Date %s Time %s Object %p\n",__FILE__,__DATE__, __TIME__, this);

	frame = imaqCreateImage(IMAQ_IMAGE_RGB, 0);
	IMAQdxOpenCamera(CAMERA::CAM_ONE, IMAQdxCameraControlModeController, &session);
	Wait(.5);
	IMAQdxConfigureGrab(session);
	Wait(.5);
	IMAQdxStartAcquisition(session);
	Wait(.5);

	frame2 = imaqCreateImage(IMAQ_IMAGE_RGB, 0);

	mRobot = pRobot;
	mXbox = pXbox;
}
void Robot::TeleopPeriodic() {
	Scheduler::GetInstance()->Run();
	SmartDashboard::PutNumber("Arm Pos:",Robot::intakeArm->GetPos());
	SmartDashboard::PutNumber("POV:",oi->getDriveStick()->GetPOV(0));
	SmartDashboard::PutBoolean("old:",oldCameraSel);
	SmartDashboard::PutBoolean("sel:",CameraSel);
	double time = 0;
	if (oldCameraSel != CameraSel)
	{
		time = Timer::GetFPGATimestamp();
		IMAQdxStopAcquisition(session);
		IMAQdxUnconfigureAcquisition(session);
		IMAQdxCloseCamera(session);
		if (CameraSel)
			imaqError = IMAQdxOpenCamera("cam2", IMAQdxCameraControlModeController, &session);
		else
			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");
		}
		IMAQdxStartAcquisition(session);
		oldCameraSel = CameraSel;
		time = time - Timer::GetFPGATimestamp();
		SmartDashboard::PutNumber("Switch:",time);
	}
//	if (CameraSel)
//		IMAQdxGrab(session2, frame, true, NULL);
//	else
	IMAQdxGrab(session, frame, true, NULL);
	if(imaqError != IMAQdxErrorSuccess) {
		DriverStation::ReportError("IMAQdxGrab error: " + std::to_string((long)imaqError) + "\n");
	} else {
		CameraServer::GetInstance()->SetImage(frame);
	}

}
Example #3
0
IMAQdxError Camera::Start() {
	// create an image
	printf("Opening camera %s\n", camInfo[camera].InterfaceName);
	imaqError = IMAQdxOpenCamera(camInfo[camera].InterfaceName,
			IMAQdxCameraControlModeController, &session);
	if (imaqError != IMAQdxErrorSuccess) {
		printf("IMAQdxOpenCamera error: %x\n", imaqError);
		session = ULONG_MAX;
		return imaqError;
	}
	// imaqError = Camera::SetMode();
	if (strstr(camInfo[camera].ModelName, "LifeCam") != nullptr)
		SetVideoMode(416, 240, 15, false);
	else if (strstr(camInfo[camera].ModelName, "Logitech Webcam") != nullptr)
		SetVideoMode(640, 360, 24, false);
	else {
		if (!SetVideoMode(800, 600, 10, false)) // Genuis wide angle camera, low frame rate
			SetVideoMode(320, 240, 15, false); // default to a widely supported mode
	}
	if (imaqError != IMAQdxErrorSuccess) {
		return imaqError;
	}
	imaqError = IMAQdxConfigureGrab(session);
	if (imaqError != IMAQdxErrorSuccess) {
		printf("IMAQdxOpenCamera error: %x\n", imaqError);
		return imaqError;
	}
	// start to acquire images
	IMAQdxStartAcquisition(session);
	if (imaqError != IMAQdxErrorSuccess) {
		printf("IMAQdxOpenCamera error: %x\n", imaqError);
		return imaqError;
	}

	frame = imaqCreateImage(IMAQ_IMAGE_RGB, 0);
	printf("Camera Opened for %s #: %lu, frame=%x\n",
			camInfo[camera].InterfaceName, session, (unsigned int) frame);
	return imaqError;
}
	void TeleopInit()
	{
		IMAQdxStartAcquisition(session);
	}