p2os_ptz.hpp
Go to the documentation of this file.
1 /*
2  * P2OS for ROS
3  * Copyright (C) 2004, 2005 ActivMedia Robotics LLC
4  * Copyright (C) 2006, 2007, 2008, 2009 MobileRobots Inc.
5  * Copyright (C) 2010 Tucker Hermans, David Feil-Seifer, Brian Gerkey, Kasper Stoy,
6  * Richard Vaughan, & Andrew Howard
7  * Copyright (C) 2018 Hunter L. Allen
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *
23  */
24 #ifndef P2OS_DRIVER__P2OS_PTZ_HPP_
25 #define P2OS_DRIVER__P2OS_PTZ_HPP_
26 
27 #include <p2os_msgs/PTZState.h>
28 #include <p2os_driver/packet.hpp>
30 
31 class P2OSNode;
32 
33 // Circular Buffer Used by PTZ camera
34 class circbuf
35 {
36 public:
37  explicit circbuf(int size = 512);
38 
39  void putOnBuf(unsigned char c);
40  int getFromBuf();
41  bool haveData();
42  int size();
43  void printBuf();
44 
45  bool gotPacket();
46  void reset();
47 
48 private:
49  unsigned char * buf;
50  int start;
51  int end;
52  int mysize;
53  bool gotPack;
54 };
55 
56 class P2OSPtz
57 {
58 public:
59  enum Command
60  {
61  DELIM = 0x00, // Delimeter character
62  DEVICEID = 0x30, // Default device ID
63  PANSLEW = 0x50, // Sets the pan slew
64  TILTSLEW = 0x51, // Sets the tilt slew
65  STOP = 0x53, // Stops current pan/tilt motion
66  INIT = 0x58, // Initializes the camera
67  SLEWREQ = 0x59, // Request pan/tilt min/max slew
68  ANGLEREQ = 0x5c, // Request pan/tilt min/max angle
69  PANTILT = 0x62, // Pan/tilt command
70  SETRANGE = 0x64, // Pan/tilt min/max range assignment
71  PANTILTREQ = 0x63, // Request pan/tilt position
72  INFRARED = 0x76, // Controls operation of IR lighting
73  PRODUCTNAME = 0x87, // Requests the product name
74  LEDCONTROL = 0x8E, // Controls LED status
75  CONTROL = 0x90, // Puts camera in Control mode
76  POWER = 0xA0, // Turns on/off power
77  AUTOFOCUS = 0xA1, // Controls auto-focusing functions
78  ZOOMSTOP = 0xA2, // Stops zoom motion
79  GAIN = 0xA5, // Sets gain adjustment on camera
80  FOCUS = 0xB0, // Manual focus adjustment
81  ZOOM = 0xB3, // Zooms camera lens
82  ZOOMREQ = 0xB4, // Requests max zoom position
83  IRCUTFILTER = 0xB5, // Controls the IR cut filter
84  DIGITALZOOM = 0xB7, // Controls the digital zoom amount
85  FOOTER = 0xEF, // Packet Footer
86  RESPONSE = 0xFE, // Packet header for response
87  HEADER = 0xFF // Packet Header
88  };
89 
90  // the states for communication
91  enum CommState
92  {
95  COMM_UNIDIRECTIONAL
96  };
97 
99  {
101  CAMERA_C50I
102  };
103 
104 protected:
105  // preset limits on movements. Based on empirical data
106  enum Param
107  {
108  MAX_PAN = 98, // 875 units is max pan assignment
109  MIN_PAN = -98, // -875 units is min pan assignment
110  MAX_TILT = 88, // 790 units is max tilt assignment
111  MIN_TILT = -30, // -267 units is min tilt assignment
112  MAX_PAN_SLEW = 90, // 800 positions per sec (PPS)
113  MIN_PAN_SLEW = 1, // 8 positions per sec (PPS)
114  MAX_TILT_SLEW = 69, // 662 positions per sec (PPS)
115  MIN_TILT_SLEW = 1, // 8 positions per sec (PPS)
116  MAX_ZOOM_OPTIC = 1960,
117  MIN_ZOOM = 0
118  };
119 
120  // the various error states that the camera can return
121  enum Error
122  {
123  CAM_ERROR_NONE = 0x30, // No error
124  CAM_ERROR_BUSY = 0x31, // Camera busy, will not execute the command
125  CAM_ERROR_PARAM = 0x35, // Illegal parameters to function call
126  CAM_ERROR_MODE = 0x39, // Not in host control mode
127  CAM_ERROR_UNKNOWN = 0xFF // Unknown error condition. Should never happen
128  };
129 
130  // Types for turning on and off the camera
131  enum Power
132  {
133  POWER_OFF = 0,
134  POWER_ON = 1
135  };
136 
137 public:
138  // Constructor
139  explicit P2OSPtz(P2OSNode * p2os, bool bidirectional_com = false);
140 
141  // Core Functions
142  int setup();
143  void shutdown();
144  void callback(const p2os_msgs::PTZStateConstPtr & msg);
145 
146  // Communication Functions
147  int sendCommand(unsigned char * str, int len);
148  int sendRequest(unsigned char * str, int len, unsigned char * reply);
149  int receiveCommandAnswer(int asize);
150  int receiveRequestAnswer(unsigned char * data, int s1, int s2);
151  void getPtzPacket(int s1, int s2 = 0);
152 
153  // Device Command Functions
154  int setPower(Power on);
155  int setControlMode();
156  int sendInit();
157 
158  int getMaxZoom(int * max_zoom);
159  int getAbsZoom(int * zoom);
160  int sendAbsZoom(int zoom);
161 
162  int setDefaultTiltRange();
163  int getAbsPanTilt(int * pan, int * tilt);
164  int sendAbsPanTilt(int pan, int tilt);
165 
166  // Simple getters and setters
167  bool isOn() const {return is_on_;}
168  p2os_msgs::PTZState getCurrentState() {return current_state_;}
169 
170  // Class members
171 
172 protected:
174 
175 public:
177 
178 protected:
180  int pan_, tilt_, zoom_;
181  bool is_on_;
184  p2os_msgs::PTZState current_state_;
185 
186  // Class constants
187  static const int MAX_COMMAND_LENGTH;
188  static const int MAX_REQUEST_LENGTH;
189  static const int COMMAND_RESPONSE_BYTES;
190  static const int PACKET_TIMEOUT;
191  static const int SLEEP_TIME_USEC;
192  static const int PAN_THRESH;
193  static const int TILT_THRESH;
194  static const int ZOOM_THRESH;
195 };
196 
197 #endif // P2OS_DRIVER__P2OS_PTZ_HPP_
int getFromBuf()
Definition: p2os_ptz.cpp:944
int end
Definition: p2os_ptz.hpp:51
int max_zoom_
Definition: p2os_ptz.hpp:179
int size()
Definition: p2os_ptz.cpp:955
static const int MAX_COMMAND_LENGTH
Definition: p2os_ptz.hpp:187
p2os_msgs::PTZState getCurrentState()
Definition: p2os_ptz.hpp:168
bool gotPack
Definition: p2os_ptz.hpp:53
bool isOn() const
Definition: p2os_ptz.hpp:167
P2OSNode * p2os_
Definition: p2os_ptz.hpp:173
bool gotPacket()
Definition: p2os_ptz.cpp:966
int error_code_
Definition: p2os_ptz.hpp:182
static const int PACKET_TIMEOUT
Definition: p2os_ptz.hpp:190
bool bidirectional_com_
Definition: p2os_ptz.hpp:183
int mysize
Definition: p2os_ptz.hpp:52
void putOnBuf(unsigned char c)
Definition: p2os_ptz.cpp:924
circbuf cb_
Definition: p2os_ptz.hpp:176
static const int TILT_THRESH
Definition: p2os_ptz.hpp:193
int zoom_
Definition: p2os_ptz.hpp:180
static const int SLEEP_TIME_USEC
Definition: p2os_ptz.hpp:191
static const int COMMAND_RESPONSE_BYTES
Definition: p2os_ptz.hpp:189
static const int PAN_THRESH
Definition: p2os_ptz.hpp:192
int start
Definition: p2os_ptz.hpp:50
bool is_on_
Definition: p2os_ptz.hpp:181
static const int MAX_REQUEST_LENGTH
Definition: p2os_ptz.hpp:188
unsigned char * buf
Definition: p2os_ptz.hpp:49
bool haveData()
Definition: p2os_ptz.cpp:939
static const int ZOOM_THRESH
Definition: p2os_ptz.hpp:194
void printBuf()
Definition: p2os_ptz.cpp:912
void reset()
Definition: p2os_ptz.cpp:971
p2os_msgs::PTZState current_state_
Definition: p2os_ptz.hpp:184
circbuf(int size=512)
Definition: p2os_ptz.cpp:906


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 Jun 20 2020 03:29:42