p2os_ptz.h
Go to the documentation of this file.
00001 /*
00002  *  P2OS for ROS
00003  *  Copyright (C) 2010
00004  *     Tucker Hermans, David Feil-Seifer, Brian Gerkey, Kasper Stoy,
00005  *     Richard Vaughan, & Andrew Howard
00006  * Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00007  * Copyright (C) 2006, 2007, 2008, 2009 MobileRobots Inc.
00008  *
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Circular Buffer Used by PTZ camera
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   // the states for communication
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   // preset limits on movements.  Based on empirical data
00103   enum Param {
00104     MAX_PAN = 98,               // 875 units is max pan assignment
00105     MIN_PAN = -98,              // -875 units is min pan assignment
00106     MAX_TILT = 88,              // 790 units is max tilt assignment
00107     MIN_TILT = -30,             // -267 units is min tilt assignment
00108     MAX_PAN_SLEW = 90,          // 800 positions per sec (PPS)
00109     MIN_PAN_SLEW = 1,           // 8 positions per sec (PPS)
00110     MAX_TILT_SLEW = 69,         // 662 positions per sec (PPS)
00111     MIN_TILT_SLEW = 1,          // 8 positions per sec (PPS)
00112     MAX_ZOOM_OPTIC = 1960,
00113     MIN_ZOOM = 0
00114   };
00115 
00116   // the various error states that the camera can return
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   // Types for turning on and off the camera
00126   enum Power {
00127     POWER_OFF = 0,
00128     POWER_ON = 1
00129   };
00130 
00131  public:
00132   // Constructor
00133   P2OSPtz (P2OSNode* p2os, bool bidirectional_com = false);
00134 
00135   // Core Functions
00136   int setup();
00137   void shutdown();
00138   void callback(const p2os_msgs::PTZStateConstPtr &msg);
00139 
00140   // Communication Functions
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   // Device Command Functions
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   // Simple getters and setters
00161   bool isOn() const { return is_on_; }
00162   p2os_msgs::PTZState getCurrentState() { return current_state_; }
00163 
00164   // Class members
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   // Class constants
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


p2os_driver
Author(s): Hunter L. Allen , David Feil-Seifer , Aris Synodinos , Brian Gerkey, Kasper Stoy, Richard Vaughan, Andrew Howard, Tucker Hermans, ActivMedia Robotics LLC, MobileRobots Inc.
autogenerated on Sat Aug 5 2017 02:20:17