blob: 4a6063a020577710f1f60483e1aac6b47841ec72 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/********************************************************************************
2* Project : FIRST Motor Controller
3* File Name : AxisCamera.h
4* Contributors : ELF
5* Creation Date : August 12, 2008
6* Revision History : Source code & revision history maintained at sourceforge.WPI.edu
7* File Description : Globally defined values for the FRC Camera API
8*
9* API: Because nivision.h uses C++ style comments, any file including this
10* must be a .cpp instead of .c.
11*
12*/
13/*----------------------------------------------------------------------------*/
14/* Copyright (c) FIRST 2008. All Rights Reserved. */
15/* Open Source Software - may be modified and shared by FRC teams. The code */
16/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
17/*----------------------------------------------------------------------------*/
18
19#ifndef __AXISCAMERA_H__
20#define __AXISCAMERA_H__
21
22#include "nivision.h"
23
24/** port for communicating with camera */
25#define CAMERA_PORT 80
26/** how old an image is before it's discarded */
27#define CAMERA_IMAGE_STALE_TIME_SEC 2.0
28/** time to wait for a new image in blocking call */
29#define MAX_BLOCKING_TIME_SEC 0.5
30
31/* Enumerated Types */
32/** @brief Counters for camera metrics */
33enum FrcvCameraMetric {CAM_STARTS, CAM_STOPS,
34 CAM_NUM_IMAGE, CAM_BUFFERS_WRITTEN, CAM_BLOCKING_COUNT,
35
36 CAM_SOCKET_OPEN, CAM_SOCKET_INIT_ATTEMPTS, CAM_BLOCKING_TIMEOUT,
37 CAM_GETIMAGE_SUCCESS, CAM_GETIMAGE_FAILURE,
38
39 CAM_STALE_IMAGE, CAM_GETIMAGE_BEFORE_INIT, CAM_GETIMAGE_BEFORE_AVAILABLE,
40 CAM_READ_JPEG_FAILURE, CAM_PID_SIGNAL_ERR,
41
42 CAM_BAD_IMAGE_SIZE, CAM_HEADER_ERROR};
43
44#define CAM_NUM_METRICS 17
45
46/** Private NI function needed to write to the VxWorks target */
47IMAQ_FUNC int Priv_SetWriteFileAllowed(UINT32 enable);
48
49/**
50@brief Possible image sizes that you can set on the camera.
51*/
52enum ImageResolution { k640x480, k320x240, k160x120 };
53
54/**
55@brief Possible rotation values that you can set on the camera.
56*/
57enum ImageRotation { ROT_0 = 0, ROT_180 = 180 };
58
59
60
61int StartCameraTask();
62
63extern "C" {
64/* Image Acquisition functions */
65/* obtains an image from the camera server */
66int GetImage(Image* cameraImage, double *timestamp);
67int GetImageBlocking(Image* cameraImage, double *timestamp, double lastImageTimestamp);
68/* obtains raw image string to send to PC */
69int GetImageData(char** imageData, int* numBytes, double* currentImageTimestamp);
70int GetImageDataBlocking(char** imageData, int* numBytes, double* timestamp, double lastImageTimestamp);
71
72/* start the camera server */
73void StartImageAcquisition();
74void StopImageAcquisition();
75void StartImageSignal(int taskId);
76
77/* status & metrics */
78int frcCameraInitialized();
79int GetCameraMetric(FrcvCameraMetric metric);
80
81/* camera configuration */
82int ConfigureCamera(char *configString);
83int GetCameraSetting(char *configString, char *cameraResponse);
84int GetImageSetting(char *configString, char *cameraResponse);
85
86/* camera task control */
87
88int StartCameraTask(int frames, int compression, ImageResolution resolution, ImageRotation rotation);
89int StopCameraTask();
90}
91#endif
92