p2os_ptz.hpp
Go to the documentation of this file.
00001 /*
00002  *  P2OS for ROS
00003  *  Copyright (C) 2004, 2005  ActivMedia Robotics LLC
00004  *  Copyright (C) 2006, 2007, 2008, 2009  MobileRobots Inc.
00005  *  Copyright (C) 2010  Tucker Hermans, David Feil-Seifer, Brian Gerkey, Kasper Stoy,
00006  *     Richard Vaughan, & Andrew Howard
00007  *  Copyright (C) 2018  Hunter L. Allen
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_DRIVER__P2OS_PTZ_HPP_
00025 #define P2OS_DRIVER__P2OS_PTZ_HPP_
00026 
00027 #include <p2os_msgs/PTZState.h>
00028 #include <p2os_driver/packet.hpp>
00029 #include <p2os_driver/robot_params.hpp>
00030 
00031 class P2OSNode;
00032 
00033 // Circular Buffer Used by PTZ camera
00034 class circbuf
00035 {
00036 public:
00037   explicit 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   {
00061     DELIM = 0x00,  // Delimeter character
00062     DEVICEID = 0x30,  // Default device ID
00063     PANSLEW = 0x50,  // Sets the pan slew
00064     TILTSLEW = 0x51,  // Sets the tilt slew
00065     STOP = 0x53,  // Stops current pan/tilt motion
00066     INIT = 0x58,  // Initializes the camera
00067     SLEWREQ = 0x59,  // Request pan/tilt min/max slew
00068     ANGLEREQ = 0x5c,  // Request pan/tilt min/max angle
00069     PANTILT = 0x62,  // Pan/tilt command
00070     SETRANGE = 0x64,  // Pan/tilt min/max range assignment
00071     PANTILTREQ = 0x63,  // Request pan/tilt position
00072     INFRARED = 0x76,  // Controls operation of IR lighting
00073     PRODUCTNAME = 0x87,  // Requests the product name
00074     LEDCONTROL = 0x8E,  // Controls LED status
00075     CONTROL = 0x90,  // Puts camera in Control mode
00076     POWER = 0xA0,  // Turns on/off power
00077     AUTOFOCUS = 0xA1,  // Controls auto-focusing functions
00078     ZOOMSTOP = 0xA2,  // Stops zoom motion
00079     GAIN = 0xA5,  // Sets gain adjustment on camera
00080     FOCUS = 0xB0,  // Manual focus adjustment
00081     ZOOM = 0xB3,  // Zooms camera lens
00082     ZOOMREQ = 0xB4,  // Requests max zoom position
00083     IRCUTFILTER = 0xB5,  // Controls the IR cut filter
00084     DIGITALZOOM = 0xB7,  // Controls the digital zoom amount
00085     FOOTER = 0xEF,  // Packet Footer
00086     RESPONSE = 0xFE,  // Packet header for response
00087     HEADER = 0xFF  // Packet Header
00088   };
00089 
00090   // the states for communication
00091   enum CommState
00092   {
00093     COMM_UNKNOWN,
00094     COMM_BIDIRECTIONAL,
00095     COMM_UNIDIRECTIONAL
00096   };
00097 
00098   enum CameraType
00099   {
00100     CAMERA_VCC4,
00101     CAMERA_C50I
00102   };
00103 
00104 protected:
00105   // preset limits on movements.  Based on empirical data
00106   enum Param
00107   {
00108     MAX_PAN = 98,               // 875 units is max pan assignment
00109     MIN_PAN = -98,              // -875 units is min pan assignment
00110     MAX_TILT = 88,              // 790 units is max tilt assignment
00111     MIN_TILT = -30,             // -267 units is min tilt assignment
00112     MAX_PAN_SLEW = 90,          // 800 positions per sec (PPS)
00113     MIN_PAN_SLEW = 1,           // 8 positions per sec (PPS)
00114     MAX_TILT_SLEW = 69,         // 662 positions per sec (PPS)
00115     MIN_TILT_SLEW = 1,          // 8 positions per sec (PPS)
00116     MAX_ZOOM_OPTIC = 1960,
00117     MIN_ZOOM = 0
00118   };
00119 
00120   // the various error states that the camera can return
00121   enum Error
00122   {
00123     CAM_ERROR_NONE = 0x30,  // No error
00124     CAM_ERROR_BUSY = 0x31,  // Camera busy, will not execute the command
00125     CAM_ERROR_PARAM = 0x35,  // Illegal parameters to function call
00126     CAM_ERROR_MODE = 0x39,  // Not in host control mode
00127     CAM_ERROR_UNKNOWN = 0xFF  // Unknown error condition.  Should never happen
00128   };
00129 
00130   // Types for turning on and off the camera
00131   enum Power
00132   {
00133     POWER_OFF = 0,
00134     POWER_ON = 1
00135   };
00136 
00137 public:
00138   // Constructor
00139   explicit P2OSPtz(P2OSNode * p2os, bool bidirectional_com = false);
00140 
00141   // Core Functions
00142   int setup();
00143   void shutdown();
00144   void callback(const p2os_msgs::PTZStateConstPtr & msg);
00145 
00146   // Communication Functions
00147   int sendCommand(unsigned char * str, int len);
00148   int sendRequest(unsigned char * str, int len, unsigned char * reply);
00149   int receiveCommandAnswer(int asize);
00150   int receiveRequestAnswer(unsigned char * data, int s1, int s2);
00151   void getPtzPacket(int s1, int s2 = 0);
00152 
00153   // Device Command Functions
00154   int setPower(Power on);
00155   int setControlMode();
00156   int sendInit();
00157 
00158   int getMaxZoom(int * max_zoom);
00159   int getAbsZoom(int * zoom);
00160   int sendAbsZoom(int zoom);
00161 
00162   int setDefaultTiltRange();
00163   int getAbsPanTilt(int * pan, int * tilt);
00164   int sendAbsPanTilt(int pan, int tilt);
00165 
00166   // Simple getters and setters
00167   bool isOn() const {return is_on_;}
00168   p2os_msgs::PTZState getCurrentState() {return current_state_;}
00169 
00170   // Class members
00171 
00172 protected:
00173   P2OSNode * p2os_;
00174 
00175 public:
00176   circbuf cb_;
00177 
00178 protected:
00179   int max_zoom_;
00180   int pan_, tilt_, zoom_;
00181   bool is_on_;
00182   int error_code_;
00183   bool bidirectional_com_;
00184   p2os_msgs::PTZState current_state_;
00185 
00186   // Class constants
00187   static const int MAX_COMMAND_LENGTH;
00188   static const int MAX_REQUEST_LENGTH;
00189   static const int COMMAND_RESPONSE_BYTES;
00190   static const int PACKET_TIMEOUT;
00191   static const int SLEEP_TIME_USEC;
00192   static const int PAN_THRESH;
00193   static const int TILT_THRESH;
00194   static const int ZOOM_THRESH;
00195 };
00196 
00197 #endif  //  P2OS_DRIVER__P2OS_PTZ_HPP_


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 Wed Mar 27 2019 02:34:57