p2os_ptz.h
Go to the documentation of this file.
1 /*
2  * P2OS for ROS
3  * Copyright (C) 2010
4  * Tucker Hermans, David Feil-Seifer, Brian Gerkey, Kasper Stoy,
5  * Richard Vaughan, & Andrew Howard
6  * Copyright (C) 2004, 2005 ActivMedia Robotics LLC
7  * Copyright (C) 2006, 2007, 2008, 2009 MobileRobots Inc.
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_PTZ_H
25 #define _P2OS_PTZ_H
26 
27 #include <p2os_msgs/PTZState.h>
28 #include <p2os_driver/packet.h>
30 
31 class P2OSNode;
32 
33 // Circular Buffer Used by PTZ camera
34 class circbuf
35 {
36  public:
37  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  DELIM = 0x00,
61  DEVICEID = 0x30,
62  PANSLEW = 0x50,
63  TILTSLEW = 0x51,
64  STOP = 0x53,
65  INIT = 0x58,
66  SLEWREQ = 0x59,
67  ANGLEREQ = 0x5c,
68  PANTILT = 0x62,
69  SETRANGE = 0x64,
70  PANTILTREQ = 0x63,
71  INFRARED = 0x76,
72  PRODUCTNAME = 0x87,
73  LEDCONTROL = 0x8E,
74  CONTROL = 0x90,
75  POWER = 0xA0,
76  AUTOFOCUS = 0xA1,
77  ZOOMSTOP = 0xA2,
78  GAIN = 0xA5,
79  FOCUS = 0xB0,
80  ZOOM = 0xB3,
81  ZOOMREQ = 0xB4,
82  IRCUTFILTER = 0xB5,
83  DIGITALZOOM = 0xB7,
84  FOOTER = 0xEF,
85  RESPONSE = 0xFE,
86  HEADER = 0xFF
87  };
88 
89  // the states for communication
90  enum CommState {
94  };
95 
96  enum CameraType {
99  };
100 
101  protected:
102  // preset limits on movements. Based on empirical data
103  enum Param {
104  MAX_PAN = 98, // 875 units is max pan assignment
105  MIN_PAN = -98, // -875 units is min pan assignment
106  MAX_TILT = 88, // 790 units is max tilt assignment
107  MIN_TILT = -30, // -267 units is min tilt assignment
108  MAX_PAN_SLEW = 90, // 800 positions per sec (PPS)
109  MIN_PAN_SLEW = 1, // 8 positions per sec (PPS)
110  MAX_TILT_SLEW = 69, // 662 positions per sec (PPS)
111  MIN_TILT_SLEW = 1, // 8 positions per sec (PPS)
114  };
115 
116  // the various error states that the camera can return
117  enum Error {
118  CAM_ERROR_NONE = 0x30,
119  CAM_ERROR_BUSY = 0x31,
121  CAM_ERROR_MODE = 0x39,
123  };
124 
125  // Types for turning on and off the camera
126  enum Power {
129  };
130 
131  public:
132  // Constructor
133  P2OSPtz (P2OSNode* p2os, bool bidirectional_com = false);
134 
135  // Core Functions
136  int setup();
137  void shutdown();
138  void callback(const p2os_msgs::PTZStateConstPtr &msg);
139 
140  // Communication Functions
141  int sendCommand(unsigned char *str, int len);
142  int sendRequest(unsigned char *str, int len, unsigned char* reply);
143  int receiveCommandAnswer(int asize);
144  int receiveRequestAnswer(unsigned char *data, int s1, int s2);
145  void getPtzPacket(int s1, int s2=0);
146 
147  // Device Command Functions
148  int setPower(Power on);
149  int setControlMode();
150  int sendInit();
151 
152  int getMaxZoom(int * max_zoom);
153  int getAbsZoom(int* zoom);
154  int sendAbsZoom(int zoom);
155 
156  int setDefaultTiltRange();
157  int getAbsPanTilt(int* pan, int* tilt);
158  int sendAbsPanTilt(int pan, int tilt);
159 
160  // Simple getters and setters
161  bool isOn() const { return is_on_; }
162  p2os_msgs::PTZState getCurrentState() { return current_state_; }
163 
164  // Class members
165  protected:
167  public:
169  protected:
171  int pan_, tilt_, zoom_;
172  bool is_on_;
175  p2os_msgs::PTZState current_state_;
176 
177  // Class constants
178  static const int MAX_COMMAND_LENGTH;
179  static const int MAX_REQUEST_LENGTH;
180  static const int COMMAND_RESPONSE_BYTES;
181  static const int PACKET_TIMEOUT;
182  static const int SLEEP_TIME_USEC;
183  static const int PAN_THRESH;
184  static const int TILT_THRESH;
185  static const int ZOOM_THRESH;
186 };
187 
188 #endif
int getFromBuf()
Definition: p2os_ptz.cpp:1023
Controls operation of IR lighting.
Definition: p2os_ptz.h:71
int end
Definition: p2os_ptz.h:51
Initializes the camera.
Definition: p2os_ptz.h:65
int max_zoom_
Definition: p2os_ptz.h:170
int size()
Definition: p2os_ptz.cpp:1036
Pan/tilt command.
Definition: p2os_ptz.h:68
Stops zoom motion.
Definition: p2os_ptz.h:77
Illegal parameters to function call.
Definition: p2os_ptz.h:120
static const int MAX_COMMAND_LENGTH
Definition: p2os_ptz.h:178
Stops current pan/tilt motion.
Definition: p2os_ptz.h:64
p2os_msgs::PTZState getCurrentState()
Definition: p2os_ptz.h:162
bool gotPack
Definition: p2os_ptz.h:53
Requests max zoom position.
Definition: p2os_ptz.h:81
int setControlMode()
Definition: p2os_ptz.cpp:591
P2OSPtz(P2OSNode *p2os, bool bidirectional_com=false)
Definition: p2os_ptz.cpp:41
Sets the tilt slew.
Definition: p2os_ptz.h:63
void shutdown()
Definition: p2os_ptz.cpp:151
Controls the IR cut filter.
Definition: p2os_ptz.h:82
CameraType
Definition: p2os_ptz.h:96
Request pan/tilt position.
Definition: p2os_ptz.h:70
int setDefaultTiltRange()
Definition: p2os_ptz.cpp:794
bool isOn() const
Definition: p2os_ptz.h:161
Request pan/tilt min/max slew.
Definition: p2os_ptz.h:66
P2OSNode * p2os_
Definition: p2os_ptz.h:166
Pan/tilt min/max range assignment.
Definition: p2os_ptz.h:69
Packet Footer.
Definition: p2os_ptz.h:84
bool gotPacket()
Definition: p2os_ptz.cpp:1052
int error_code_
Definition: p2os_ptz.h:173
int sendCommand(unsigned char *str, int len)
Definition: p2os_ptz.cpp:226
Manual focus adjustment.
Definition: p2os_ptz.h:79
Sets gain adjustment on camera.
Definition: p2os_ptz.h:78
Puts camera in Control mode.
Definition: p2os_ptz.h:74
int getAbsPanTilt(int *pan, int *tilt)
Definition: p2os_ptz.cpp:838
static const int PACKET_TIMEOUT
Definition: p2os_ptz.h:181
int receiveCommandAnswer(int asize)
Definition: p2os_ptz.cpp:299
Controls LED status.
Definition: p2os_ptz.h:73
Not in host control mode.
Definition: p2os_ptz.h:121
bool bidirectional_com_
Definition: p2os_ptz.h:174
int mysize
Definition: p2os_ptz.h:52
void putOnBuf(unsigned char c)
Definition: p2os_ptz.cpp:1001
circbuf cb_
Definition: p2os_ptz.h:168
Packet header for response.
Definition: p2os_ptz.h:85
int sendAbsZoom(int zoom)
Definition: p2os_ptz.cpp:745
Controls the digital zoom amount.
Definition: p2os_ptz.h:83
Requests the product name.
Definition: p2os_ptz.h:72
int setPower(Power on)
Definition: p2os_ptz.cpp:563
static const int TILT_THRESH
Definition: p2os_ptz.h:184
int zoom_
Definition: p2os_ptz.h:171
Default device ID.
Definition: p2os_ptz.h:61
void getPtzPacket(int s1, int s2=0)
Definition: p2os_ptz.cpp:509
static const int SLEEP_TIME_USEC
Definition: p2os_ptz.h:182
void callback(const p2os_msgs::PTZStateConstPtr &msg)
Definition: p2os_ptz.cpp:162
static const int COMMAND_RESPONSE_BYTES
Definition: p2os_ptz.h:180
int tilt_
Definition: p2os_ptz.h:171
Delimeter character.
Definition: p2os_ptz.h:60
int sendInit()
Definition: p2os_ptz.cpp:616
int sendAbsPanTilt(int pan, int tilt)
Definition: p2os_ptz.cpp:909
Controls auto-focusing functions.
Definition: p2os_ptz.h:76
Packet Header.
Definition: p2os_ptz.h:86
static const int PAN_THRESH
Definition: p2os_ptz.h:183
Turns on/off power.
Definition: p2os_ptz.h:75
int receiveRequestAnswer(unsigned char *data, int s1, int s2)
Definition: p2os_ptz.cpp:412
int start
Definition: p2os_ptz.h:50
bool is_on_
Definition: p2os_ptz.h:172
Zooms camera lens.
Definition: p2os_ptz.h:80
static const int MAX_REQUEST_LENGTH
Definition: p2os_ptz.h:179
unsigned char * buf
Definition: p2os_ptz.h:49
bool haveData()
Definition: p2os_ptz.cpp:1018
Request pan/tilt min/max angle.
Definition: p2os_ptz.h:67
static const int ZOOM_THRESH
Definition: p2os_ptz.h:185
int getAbsZoom(int *zoom)
Definition: p2os_ptz.cpp:694
Unknown error condition. Should never happen.
Definition: p2os_ptz.h:122
int setup()
Definition: p2os_ptz.cpp:56
Sets the pan slew.
Definition: p2os_ptz.h:62
int sendRequest(unsigned char *str, int len, unsigned char *reply)
Definition: p2os_ptz.cpp:262
void printBuf()
Definition: p2os_ptz.cpp:990
Definition: p2os.h:86
CommState
Definition: p2os_ptz.h:90
Camera busy, will not execute the command.
Definition: p2os_ptz.h:119
void reset()
Definition: p2os_ptz.cpp:1057
int pan_
Definition: p2os_ptz.h:171
int getMaxZoom(int *max_zoom)
Definition: p2os_ptz.cpp:641
p2os_msgs::PTZState current_state_
Definition: p2os_ptz.h:175
circbuf(int size=512)
Definition: p2os_ptz.cpp:984


p2os_driver
Author(s): Hunter Allen , David Feil-Seifer , Aris Synodinos , Brian Gerkey, Kasper Stoy, Richard Vaughan, Andrew Howard, Tucker Hermans, ActivMedia Robotics LLC, MobileRobots Inc.
autogenerated on Wed Jun 25 2014 09:37:15