00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _P2OS_PTZ_H
00025 #define _P2OS_PTZ_H
00026
00027 #include <p2os_msgs/PTZState.h>
00028 #include <p2os_driver/packet.h>
00029 #include <p2os_driver/robot_params.h>
00030
00031 class P2OSNode;
00032
00033
00034 class circbuf
00035 {
00036 public:
00037 circbuf(int size=512);
00038
00039 void putOnBuf(unsigned char c);
00040 int getFromBuf();
00041 bool haveData();
00042 int size();
00043 void printBuf();
00044
00045 bool gotPacket();
00046 void reset();
00047
00048 private:
00049 unsigned char* buf;
00050 int start;
00051 int end;
00052 int mysize;
00053 bool gotPack;
00054 };
00055
00056 class P2OSPtz
00057 {
00058 public:
00059 enum Command {
00060 DELIM = 0x00,
00061 DEVICEID = 0x30,
00062 PANSLEW = 0x50,
00063 TILTSLEW = 0x51,
00064 STOP = 0x53,
00065 INIT = 0x58,
00066 SLEWREQ = 0x59,
00067 ANGLEREQ = 0x5c,
00068 PANTILT = 0x62,
00069 SETRANGE = 0x64,
00070 PANTILTREQ = 0x63,
00071 INFRARED = 0x76,
00072 PRODUCTNAME = 0x87,
00073 LEDCONTROL = 0x8E,
00074 CONTROL = 0x90,
00075 POWER = 0xA0,
00076 AUTOFOCUS = 0xA1,
00077 ZOOMSTOP = 0xA2,
00078 GAIN = 0xA5,
00079 FOCUS = 0xB0,
00080 ZOOM = 0xB3,
00081 ZOOMREQ = 0xB4,
00082 IRCUTFILTER = 0xB5,
00083 DIGITALZOOM = 0xB7,
00084 FOOTER = 0xEF,
00085 RESPONSE = 0xFE,
00086 HEADER = 0xFF
00087 };
00088
00089
00090 enum CommState {
00091 COMM_UNKNOWN,
00092 COMM_BIDIRECTIONAL,
00093 COMM_UNIDIRECTIONAL
00094 };
00095
00096 enum CameraType {
00097 CAMERA_VCC4,
00098 CAMERA_C50I
00099 };
00100
00101 protected:
00102
00103 enum Param {
00104 MAX_PAN = 98,
00105 MIN_PAN = -98,
00106 MAX_TILT = 88,
00107 MIN_TILT = -30,
00108 MAX_PAN_SLEW = 90,
00109 MIN_PAN_SLEW = 1,
00110 MAX_TILT_SLEW = 69,
00111 MIN_TILT_SLEW = 1,
00112 MAX_ZOOM_OPTIC = 1960,
00113 MIN_ZOOM = 0
00114 };
00115
00116
00117 enum Error {
00118 CAM_ERROR_NONE = 0x30,
00119 CAM_ERROR_BUSY = 0x31,
00120 CAM_ERROR_PARAM = 0x35,
00121 CAM_ERROR_MODE = 0x39,
00122 CAM_ERROR_UNKNOWN = 0xFF
00123 };
00124
00125
00126 enum Power {
00127 POWER_OFF = 0,
00128 POWER_ON = 1
00129 };
00130
00131 public:
00132
00133 P2OSPtz (P2OSNode* p2os, bool bidirectional_com = false);
00134
00135
00136 int setup();
00137 void shutdown();
00138 void callback(const p2os_msgs::PTZStateConstPtr &msg);
00139
00140
00141 int sendCommand(unsigned char *str, int len);
00142 int sendRequest(unsigned char *str, int len, unsigned char* reply);
00143 int receiveCommandAnswer(int asize);
00144 int receiveRequestAnswer(unsigned char *data, int s1, int s2);
00145 void getPtzPacket(int s1, int s2=0);
00146
00147
00148 int setPower(Power on);
00149 int setControlMode();
00150 int sendInit();
00151
00152 int getMaxZoom(int * max_zoom);
00153 int getAbsZoom(int* zoom);
00154 int sendAbsZoom(int zoom);
00155
00156 int setDefaultTiltRange();
00157 int getAbsPanTilt(int* pan, int* tilt);
00158 int sendAbsPanTilt(int pan, int tilt);
00159
00160
00161 bool isOn() const { return is_on_; }
00162 p2os_msgs::PTZState getCurrentState() { return current_state_; }
00163
00164
00165 protected:
00166 P2OSNode* p2os_;
00167 public:
00168 circbuf cb_;
00169 protected:
00170 int max_zoom_;
00171 int pan_, tilt_, zoom_;
00172 bool is_on_;
00173 int error_code_;
00174 bool bidirectional_com_;
00175 p2os_msgs::PTZState current_state_;
00176
00177
00178 static const int MAX_COMMAND_LENGTH;
00179 static const int MAX_REQUEST_LENGTH;
00180 static const int COMMAND_RESPONSE_BYTES;
00181 static const int PACKET_TIMEOUT;
00182 static const int SLEEP_TIME_USEC;
00183 static const int PAN_THRESH;
00184 static const int TILT_THRESH;
00185 static const int ZOOM_THRESH;
00186 };
00187
00188 #endif