camera.h

00001 #ifndef CAMERA_H_
00002 #define CAMERA_H_
00003 
00004 #ifdef __cplusplus
00005 extern "C"
00006 {
00007 #endif
00008 
00009 #include <fcntl.h>
00010 #include <termios.h>
00011 #include <stdio.h>
00012 #include <time.h>
00013 #include <string.h>
00014 #include <stdlib.h>
00015 #include <unistd.h>
00016 
00017 /* These should NOT be redefined. */
00018 //typedef unsigned int     uint32_t;
00019 //typedef unsigned short   uint16_t;
00020 //typedef unsigned char    uint8_t;
00021 
00022 /* Instead #include playerconfig.h, which gets them in a portable way */
00023 #include "playerconfig.h"
00024 
00025 
00026 /**************************************************************************
00027                             *** CONSTANST ***
00028 **************************************************************************/
00029 #define IMAGE_WIDTH      174    // the width of the frame camera sends
00030 #define IMAGE_HEIGHT     143    // the height of the frame camera sends
00031 #define CONTRAST         5      // camera's contrast register #
00032 #define BRIGHTNESS       6      // camera's brightness register #
00033 #define COLORMODE        18     // camera's colormode register #
00034 #define RGB_AWT_ON       44     // camera's RGB auto white balance on
00035 #define RGB_AWT_OFF      40     // camera'sRGB auto white balance off
00036 #define YCRCB_AWT_ON     36     // camera'sYCrCb auto white balance on
00037 #define YCRCB_AWT_OFF    32     // camera'sYCrCb auto white balance off
00038 #define AUTOGAIN         19     // camera's autogain register #
00039 #define AUTOGAIN_ON      33     // camera's autogain on
00040 #define AUTOGAIN_OFF     32     // camera's autogain off
00041 #define ZERO_POSITION    128    // servos' middle position as defiend by camera
00042 #define MIN_RGB          16     // camera's min rgb value
00043 #define MAX_RGB          240    // camera's max rgb value
00044 #define T_PACKET_LENGTH  50     // max length of T packet that camera returns
00045 #define F_PACKET_LENGTH  37474  // max length of F packet that camera returns
00046 
00047 
00048 /**************************************************************************
00049                                               *** T PACKET ***
00050 **************************************************************************/
00051 typedef struct                      // camera's output packet for tracking blobs
00052 {
00053         int middle_x, middle_y;         // the blob entroid (image coords)
00054         int left_x;                     // the left most corner's x value
00055         int left_y;                     // the left msot corner's y value
00056         int right_x;                    // the right most corner's x vlaue
00057         int right_y;                    // the right most corner's y value
00058         int blob_area;                  // number of pixles int he tracked regtion,
00059                                     // scaled and capped at 255:(pixles+4)/8
00060         int confidence;                 // the (# of pixles/area)*256 of the bounded
00061                                     // rectangle and capped at 255
00062 }packet_t; 
00063 
00064 /**************************************************************************
00065                                               *** F PACKET ***
00066 **************************************************************************/
00067 typedef struct
00068 {
00069         int r, g, b;
00070 } rgb_type;
00071 
00072 typedef struct
00073 {
00074         int rowbyte;
00075         rgb_type rgb[IMAGE_WIDTH];
00076 } row_type;
00077 
00078 typedef struct
00079 {
00080         int first;
00081         int xsize, ysize;
00082         row_type rows[IMAGE_HEIGHT];
00083         int last;
00084 } packet_f; 
00085 
00086 /**************************************************************************
00087                                             *** IMAGER CONFIG ***
00088 **************************************************************************/
00089 typedef struct           // camera's internal register controlling image quality
00090 { 
00091         uint8_t subtype;     // must be PLAYER_BLOBFINDER_REQ_SET_IMAGER_PARAMS.
00092         int16_t brightness;  // contrast:      -1 = no change.  (0-255)
00093         int16_t contrast;    // brightness:    -1 = no change.  (0-255)
00094         int8_t  colormode;   // color mode:    -1 = no change.
00095                          //                0  = RGB/auto white balance Off,
00096                          //                1  = RGB/AutoWhiteBalance On,
00097                          //                2  = YCrCB/AutoWhiteBalance Off,
00098                          //                3  = YCrCb/AWB On)
00099         int8_t  autogain;    // auto gain:     -1 = no change.
00100                                  //                0  = off, o
00101                          //                1  = on.
00102 } imager_config;
00103 
00104 /**************************************************************************
00105                                             *** CONFIG CONFIG ***
00106 **************************************************************************/
00107 typedef struct
00108 { 
00109         uint8_t subtype;                 // must be PLAYER_BLOBFINDER_REQ_SET_COLOR.
00110         int16_t rmin, rmax;              // RGB minimum and max values (0-255)
00111         int16_t gmin, gmax;
00112         int16_t bmin, bmax;
00113 } color_config;
00114 
00115 /**************************************************************************
00116                                                 *** RGB ***
00117 **************************************************************************/
00118 typedef struct                          // RGB values
00119 {
00120         int red;
00121         int green;
00122         int blue;
00123 } rgb;
00124 
00125 /**************************************************************************
00126                                             *** CONFIG CONFIG ***
00127 **************************************************************************/
00128 typedef struct                          // camera's image
00129 {
00130         int width;
00131         int height;
00132         rgb **pixel;
00133 } image;
00134 
00135 
00136 /**************************************************************************
00137                                               *** FUNCTION PROTOTYPES ***
00138 **************************************************************************/
00139 int  get_t_packet(int fd, packet_t *tpacket);
00140 int  set_imager_config(int fd, imager_config ic);
00141 int  get_bytes(int fd, char *buf, size_t len);
00142 int  open_port(char *devicepath);
00143 void close_port(int fd);
00144 void read_t_packet(int fd, char *tpackChars);
00145 int  read_f_packet (int fd, char *fpackChars);
00146 int  set_t_packet( packet_t *tpacket, char tpack_chars[] );
00147 int  set_f_packet (packet_f *fpacket, char fpack_chars[], int chan_num);
00148 int  set_servo_position(int fd, int servo_num, int angle);
00149 int  get_servo_position(int fd, int servo_num);
00150 void stop_tracking(int fd);
00151 int  write_check(int fd, char *msg, int  respond_size);
00152 int  poll_mode(int fd, int on);
00153 void make_command(char *cmd, int *n, size_t size, char *fullCommand);
00154 int  auto_servoing(int fd, int on);
00155 void track_blob(int fd, color_config cc);
00156 int  read_image (int fd, int chan_num, packet_f *fpacket);
00157 
00158 #ifdef __cplusplus
00159 }
00160 #endif
00161 
00162 #endif

Last updated 12 September 2005 21:38:45