00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ARVCC4_H
00028 #define ARVCC4_H
00029
00030 #include "ariaTypedefs.h"
00031 #include "ArBasePacket.h"
00032 #include "ArPTZ.h"
00033 #include "ariaUtil.h"
00034 #include "ArCommands.h"
00035 #include "ArSerialConnection.h"
00036
00037
00038 #define MAX_RESPONSE_BYTES 14
00039
00040
00041
00042
00043 #define BIDIRECTIONAL_TIMEOUT 5000
00044
00045
00046
00047
00048 #define UNIDIRECTIONAL_TIMEOUT 300
00049
00050
00051
00052 #define AUTO_UPDATE_TIME 2000
00053
00054
00055
00056
00057 #define TOLERANCE 1
00058
00074
00075 class ArVCC4Commands
00076 {
00077 public:
00078 enum Command {
00079 DELIM = 0x00,
00080 DEVICEID = 0x30,
00081 PANSLEW = 0x50,
00082 TILTSLEW = 0x51,
00083 STOP = 0x53,
00084 INIT = 0x58,
00085 SLEWREQ = 0x59,
00086 ANGLEREQ = 0x5c,
00087 PANTILT = 0x62,
00088 SETRANGE = 0x64,
00089 PANTILTREQ = 0x63,
00090 INFRARED = 0x76,
00091 PRODUCTNAME = 0x87,
00092 LEDCONTROL = 0x8E,
00093 CONTROL = 0x90,
00094 POWER = 0xA0,
00095 AUTOFOCUS = 0xA1,
00096 ZOOMSTOP = 0xA2,
00097 GAIN = 0xA5,
00098 FOCUS = 0xB0,
00099 ZOOM = 0xB3,
00100 ZOOMREQ = 0xB4,
00101 IRCUTFILTER = 0xB5,
00102 DIGITALZOOM = 0xB7,
00103 FOOTER = 0xEF,
00104 RESPONSE = 0xFE,
00105 HEADER = 0xFF
00106 };
00107
00108 };
00109
00111
00116 class ArVCC4Packet: public ArBasePacket
00117 {
00118 public:
00120 ArVCC4Packet(ArTypes::UByte2 bufferSize = 30);
00122 virtual ~ArVCC4Packet();
00123
00124 virtual void byte2ToBuf(ArTypes::Byte4 val);
00125
00126 virtual void finalizePacket(void);
00127
00128 protected:
00129 };
00130
00132 class ArVCC4 : public ArPTZ
00133 {
00134 public:
00135
00136 enum CommState {
00137 COMM_UNKNOWN,
00138 COMM_BIDIRECTIONAL,
00139 COMM_UNIDIRECTIONAL
00140 };
00141
00142 enum CameraType {
00143 CAMERA_VCC4,
00144 CAMERA_C50I
00145 };
00146
00148 ArVCC4(ArRobot *robot, bool inverted = false, CommState commDirection = COMM_UNKNOWN, bool autoUpdate = true, bool disableLED = false, CameraType cameraType = CAMERA_VCC4);
00150 virtual ~ArVCC4();
00151
00152 virtual bool power(bool state) { myPowerStateDesired = state; return true; }
00153 bool getPower(void) { return myPowerState; }
00154 virtual bool init(void) { myInitRequested = true; return true; }
00155
00157 bool isInitted(void) { return myCameraIsInitted; }
00158 virtual void connectHandler(void);
00159 virtual bool packetHandler(ArBasePacket *packet);
00160
00161 virtual bool pan(int deg) { return panTilt(deg, myTiltDesired); }
00162 virtual bool panRel(int deg) { return panTilt(myPanDesired + deg, myTiltDesired); }
00163 virtual bool tilt(int deg) { return panTilt(myPanDesired, deg); }
00164 virtual bool tiltRel(int deg) { return panTilt(myPanDesired, myTiltDesired + deg); }
00165 virtual bool panTiltRel(int pdeg, int tdeg) { return panTilt(myPanDesired + pdeg, myTiltDesired + tdeg); }
00166
00167 virtual int getMaxPosPan(void) const
00168 { if (myInverted) return invert(MIN_PAN); else return MAX_PAN; }
00169 virtual int getMaxNegPan(void) const
00170 { if (myInverted) return invert(MAX_PAN); else return MIN_PAN; }
00171 virtual int getMaxPosTilt(void) const
00172 { if (myInverted) return invert(MIN_TILT); else return MAX_TILT; }
00173 virtual int getMaxNegTilt(void) const
00174 { if (myInverted) return invert(MAX_TILT); else return MIN_TILT; }
00175
00178 void getRealPanTilt(void) { myRealPanTiltRequested = true; }
00179
00182 void getRealZoomPos(void) { myRealZoomRequested = true; }
00183
00184 virtual bool canZoom(void) const { return true; }
00185
00186 virtual bool panTilt(int pdeg, int tdeg);
00187 virtual bool zoom(int deg);
00190 bool digitalZoom(int deg);
00191
00195 void addErrorCB(ArFunctor *functor, ArListPos::Pos position);
00196
00198 void remErrorCB(ArFunctor *functor);
00199
00201 bool haltPanTilt(void) { myHaltPanTiltRequested = true; return true; }
00203 bool haltZoom(void) { myHaltZoomRequested = true; return true; }
00204
00206 bool panSlew(int deg) { myPanSlewDesired = deg; return true; }
00208 bool tiltSlew(int deg) { myTiltSlewDesired = deg; return true; }
00209
00211 void preparePacket(ArVCC4Packet *packet);
00212
00213 virtual int getPan(void) const { return myPanDesired; }
00214 virtual int getTilt(void) const { return myTiltDesired; }
00215 virtual int getZoom(void) const { return myZoomDesired; }
00216 int getDigitalZoom(void) const { return myDigitalZoomDesired; }
00217
00218 virtual bool canGetRealPanTilt(void) const { return true; }
00219 virtual bool canGetRealZoom(void) const { return true; }
00220 virtual bool canSetFocus(void) const { return false; }
00223 virtual bool autoFocus(void) { myFocusModeDesired = 0; return true;}
00225 virtual bool focusNear(void) { myFocusModeDesired = 2; return true;}
00227 virtual bool focusFar(void) { myFocusModeDesired = 3; return true; }
00228
00230 int getPanSlew(void) { return myPanSlewDesired; }
00232 int getMaxPanSlew(void) { return MAX_PAN_SLEW; }
00234 int getMinPanSlew(void) { return MIN_PAN_SLEW; }
00235
00237 int getTiltSlew(void) { return myTiltSlewDesired; }
00239 int getMaxTiltSlew(void) { return MAX_TILT_SLEW; }
00241 int getMinTiltSlew(void) { return MIN_TILT_SLEW; }
00242
00243 virtual int getMaxZoom(void) const;
00244 virtual int getMinZoom(void) const { return MIN_ZOOM; }
00245
00247 bool wasError(void) { return myWasError; }
00248
00250 void enableAutoUpdate(void) { myAutoUpdate = true; }
00251 void disableAutoUpdate(void) { myAutoUpdate = false; }
00252 bool getAutoUpdate(void) { return myAutoUpdate; }
00253
00256 void setLEDControlMode(int controlMode) { myDesiredLEDControlMode = controlMode; }
00258 void enableIRLEDs(void) { myDesiredIRLEDsMode = true; }
00260 void disableIRLEDs(void) { myDesiredIRLEDsMode = false; }
00262 bool getIRLEDsEnabled(void) { return myIRLEDsEnabled; }
00264 void enableIRFilterMode(void) { myDesiredIRFilterMode = true; }
00266 void disableIRFilterMode(void) { myDesiredIRFilterMode = false; }
00268 bool getIRFilterModeEnabled (void) { return myIRFilterModeEnabled; }
00269 protected:
00270
00271
00272 enum Param {
00273 MAX_PAN = 98,
00274 MIN_PAN = -98,
00275 MAX_TILT = 88,
00276 MIN_TILT = -30,
00277 MAX_PAN_SLEW = 90,
00278 MIN_PAN_SLEW = 1,
00279 MAX_TILT_SLEW = 69,
00280 MIN_TILT_SLEW = 1,
00281 MAX_ZOOM_OPTIC = 1960,
00282 MIN_ZOOM = 0
00283 };
00284
00285
00286 enum Error {
00287 CAM_ERROR_NONE = 0x30,
00288 CAM_ERROR_BUSY = 0x31,
00289 CAM_ERROR_PARAM = 0x35,
00290 CAM_ERROR_MODE = 0x39,
00291 CAM_ERROR_UNKNOWN = 0xFF
00292 };
00293
00294
00295 enum State {
00296 UNINITIALIZED,
00297 STATE_UNKNOWN,
00298 INITIALIZING,
00299 SETTING_CONTROL_MODE,
00300 SETTING_INIT_TILT_RATE,
00301 SETTING_INIT_PAN_RATE,
00302 SETTING_INIT_RANGE,
00303 POWERING_ON,
00304 POWERING_OFF,
00305 POWERED_OFF,
00306 POWERED_ON,
00307 AWAITING_INITIAL_POWERON,
00308 AWAITING_INITIAL_INIT,
00309 AWAITING_ZOOM_RESPONSE,
00310 AWAITING_PAN_TILT_RESPONSE,
00311 AWAITING_STOP_PAN_TILT_RESPONSE,
00312 AWAITING_STOP_ZOOM_RESPONSE,
00313 AWAITING_PAN_SLEW_RESPONSE,
00314 AWAITING_TILT_SLEW_RESPONSE,
00315 AWAITING_POS_REQUEST,
00316 AWAITING_ZOOM_REQUEST,
00317 AWAITING_LED_CONTROL_RESPONSE,
00318 AWAITING_IRLEDS_RESPONSE,
00319 AWAITING_IRFILTER_RESPONSE,
00320 AWAITING_PRODUCTNAME_REQUEST,
00321 AWAITING_DIGITAL_ZOOM_RESPONSE,
00322 AWAITING_FOCUS_RESPONSE,
00323 STATE_DELAYED_SWITCH,
00324 STATE_ERROR
00325 };
00326
00327
00328 int invert(int before) const
00329 { if (myInverted) return -before; else return before; }
00330 bool myInverted;
00331
00332
00333 bool myWasError;
00334
00335
00336 std::string myProductName;
00337
00338 ArRobot *myRobot;
00339 ArDeviceConnection *myConn;
00340 ArBasePacket *newPacket;
00341 ArVCC4Packet myPacket;
00342
00343
00344 ArTime myStateTime;
00345 ArTime myPacketTime;
00346 ArTime myIdleTime;
00347
00348
00349 bool myUsingAuxPort;
00350
00351
00352 int myStateDelayTime;
00353
00354
00355 CommState myCommType;
00356
00357
00358 virtual ArBasePacket* readPacket(void);
00359
00360
00361 ArFunctorC<ArVCC4> myTaskCB;
00362
00363
00364 void camTask(void);
00365
00366
00367
00368 bool myResponseReceived;
00369
00370 bool myWaitingOnStop;
00371 bool myWaitingOnPacket;
00372
00373
00374 State myState;
00375 State myPreviousState;
00376 State myNextState;
00377
00378
00379 void switchState(State state, int delayTime = 0);
00380
00381
00382
00383
00384
00385 int myStateTimeout;
00386 int myPacketTimeout;
00387
00388
00389
00390 void requestBytes(int num = 6);
00391
00392
00393 unsigned char myPacketBuf[50];
00394 int myPacketBufLen;
00395
00396
00397 int myBytesLeft;
00398
00399
00400 bool sendPanTilt(void);
00401 bool sendZoom(void);
00402 bool sendPanSlew(void);
00403 bool sendTiltSlew(void);
00404 bool sendPower(void);
00405 bool sendHaltPanTilt(void);
00406 bool sendHaltZoom(void);
00407 bool sendRealPanTiltRequest(void);
00408 bool sendRealZoomRequest(void);
00409 bool sendDigitalZoom(void);
00410 bool sendFocus(void);
00411
00412
00413 bool sendProductNameRequest(void);
00414
00415
00416 CameraType myCameraType;
00417 bool myRequestProductName;
00418
00419 bool sendLEDControlMode(void);
00420 bool sendCameraNameRequest(void);
00421 int myDesiredLEDControlMode;
00422
00423 bool sendIRFilterControl(void);
00424 bool sendIRLEDControl(void);
00425 bool myIRLEDsEnabled;
00426 bool myDesiredIRLEDsMode;
00427 bool myIRFilterModeEnabled;
00428 bool myDesiredIRFilterMode;
00429
00430
00431
00432 bool setDefaultRange(void);
00433 bool setControlMode(void);
00434 bool sendInit(void);
00435
00436
00437
00438 void processGetPanTiltResponse(void);
00439 void processGetZoomResponse(void);
00440 void processGetProductNameResponse(void);
00441
00442
00443 bool myAutoUpdate;
00444
00445
00446 int myAutoUpdateCycle;
00447
00448
00449
00450
00451 bool timeout(int mSec = 0);
00452
00453
00454 int myPan;
00455 int myTilt;
00456 int myZoom;
00457 int myDigitalZoom;
00458 int myFocusMode;
00459
00460
00461
00462 int myPanResponse;
00463 int myTiltResponse;
00464 int myZoomResponse;
00465
00466
00467 char myProductNameResponse[4];
00468
00469
00470
00471
00472 int myPanSent;
00473 int myTiltSent;
00474 int myZoomSent;
00475 int myPanSlewSent;
00476 int myTiltSlewSent;
00477
00478
00479 int myPanSlew;
00480 int myTiltSlew;
00481
00482
00483 int myPanDesired;
00484 int myTiltDesired;
00485 int myZoomDesired;
00486 int myDigitalZoomDesired;
00487 int myFocusModeDesired;
00488
00489
00490 int myPanSlewDesired;
00491 int myTiltSlewDesired;
00492
00493
00494 bool myPowerState;
00495 bool myCameraIsInitted;
00496
00497
00498 bool myPowerStateDesired;
00499 bool myInitRequested;
00500
00501
00502 bool myHaltZoomRequested;
00503 bool myHaltPanTiltRequested;
00504
00505
00506 bool myCameraHasBeenInitted;
00507
00508
00509
00510 bool myRealPanTiltRequested;
00511 bool myRealZoomRequested;
00512
00513
00514 unsigned int myError;
00515
00516
00517 void throwError();
00518
00519
00520 std::list<ArFunctor *> myErrorCBList;
00521 };
00522
00523 #endif
00524