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