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

Last updated 25 May 2011 21:17:00