- Main Page
- Classes
- Files

- File List
- File Members

# device/Camera.h

    00001 //
    00002 // Camera.h
    00003 //
    00004 // Copyright 2009 by Takashi Chikamasa, Jon C. Martin and Robert W. Kramer
    00005 //
    00006
    00007 #ifndef CAMERA_H_
    00008 #define CAMERA_H_
    00009
    00010 #include "I2c.h"
    00011
    00012 namespace ecrobot
    00013 {
    00052 class Camera
    00053 {
    00054 public:
    00056         typedef struct {
    00057                 SINT upperLeftX;
    00058                 SINT upperLeftY;
    00059                 SINT lowerRightX;
    00060                 SINT lowerRightY;
    00061                 SINT width;
    00062                 SINT height;
    00063         } Rectangle_T;
    00064
    00065         // Camera commands according to NXTCam-v2-User-Guide.pdf provided from Mindsensors
    00067         static const U8 SORT_OBJ_BY_SIZE = 0x41;
    00069         static const U8 OBJECT_TRACKING = 0x42;
    00077         static const U8 WRITE_CAM_REG = 0x43;
    00079         static const U8 DISABLE_TRACKING = 0x44;
    00081         static const U8 ENABLE_TRACKING = 0x45;
    00083         static const U8 GET_COLOR_MAP = 0x47;
    00085         static const U8 READ_CAM_REG = 0x48;
    00087         static const U8 ILLUMINATION_ON = 0x49;
    00089         static const U8 LINE_TRACKING = 0x4C;
    00091         static const U8 SET_ADPA_ON = 0x4E;
    00093         static const U8 SET_ADPA_OFF = 0x4F;
    00095         static const U8 PING_CAMERA_ENGINE = 0x50;
    00097         static const U8 RESET_CAMERA_ENGINE = 0x52;
    00099         static const U8 SET_COLOR_MAP = 0x53;
    00101         static const U8 ILLUMINATION_OFF = 0x54;
    00103         static const U8 SORT_OBJ_BY_COLOR = 0x55;
    00105         static const U8 GET_VERSION = 0x56;
    00107         static const U8 NO_SORTING_OBJ = 0x58;
    00108
    00112         enum eTrackingType
    00113         {
    00114                 OBJECT = OBJECT_TRACKING,
    00115                 LINE   = LINE_TRACKING
    00116         };
    00117
    00121         enum eSortType
    00122         {
    00123                 SIZE            = SORT_OBJ_BY_SIZE,
    00124                 COLOR           = SORT_OBJ_BY_COLOR,
    00125                 NO_SORTING      = NO_SORTING_OBJ
    00126         };
    00127
    00137         explicit Camera(ePortS port);
    00138
    00144         void enableTracking(boolean enable);
    00145
    00151         inline void setTrackingType(eTrackingType mode) { this->sendCommand(static_cast<U8>(mode)); }
    00152
    00159         inline void sortBy(eSortType sortType) { this->sendCommand(static_cast<U8>(sortType)); }
    00160
    00166         inline SINT getNumberOfObjects(void) const { return static_cast<SINT>(mBuffer[0]); }
    00167
    00173         inline SINT getObjectColor(SINT id) const { return static_cast<SINT>(mBuffer[1 + id * 5]); }
    00174
    00180         void getRectangle(SINT id, Rectangle_T* rect);
    00181
    00187         bool update(void);
    00188
    00194         inline bool sendCommand(U8 command) { return mI2c.send(0x41, &command, 1); }
    00195
    00203         inline bool receive(U32 address, U8* data, U32 length) { return mI2c.receive(address, data, length); }
    00204
    00205 private:
    00206         static const U8 DATA_BUFFER_BYTE_SIZE = 41;
    00207         I2c mI2c; // composite
    00208         U8  mBuffer[DATA_BUFFER_BYTE_SIZE]; // buffer to receive all data
    00209 };
    00210 }
    00211 #endif