41 : p2os_(p2os), max_zoom_(MAX_ZOOM_OPTIC), pan_(0), tilt_(0), zoom_(0),
42 is_on_(false), error_code_(CAM_ERROR_NONE),
43 bidirectional_com_(bidirectional_com)
60 for (
int i = 1; i < num_inits; i++) {
71 ROS_DEBUG(
"Waiting for camera to power on.");
77 ROS_DEBUG(
"Waiting for camera mode to set");
83 ROS_DEBUG(
"Waiting for camera to initialize");
89 for (
int i = 0; i < 3; i++) {
90 ROS_DEBUG(
"Waiting for camera to set default tilt");
97 ROS_DEBUG(
"Waiting for camera to set initial pan and tilt");
103 ROS_DEBUG(
"Waiting for camera to set initial zoom");
114 ROS_ERROR(
"Error initiliazing PTZ at stage %i", i);
126 ROS_ERROR(
"Error: Unknown error response from camera.");
131 ROS_DEBUG(
"Passed stage %i of PTZ initialization.", i);
134 ROS_DEBUG(
"Finished initialization of the PTZ.");
146 ROS_INFO(
"PTZ camera has been shutdown");
151 p2os_msgs::PTZState to_send;
152 bool change_pan_tilt =
false;
153 bool change_zoom =
false;
155 to_send.tilt =
tilt_;
156 to_send.zoom =
zoom_;
161 to_send.pan = cmd->pan +
pan_;
162 change_pan_tilt =
true;
165 to_send.tilt = cmd->tilt +
tilt_;
166 change_pan_tilt =
true;
169 to_send.zoom = cmd->zoom +
zoom_;
174 to_send.pan = cmd->pan;
175 change_pan_tilt =
true;
178 to_send.tilt = cmd->tilt;
179 change_pan_tilt =
true;
182 to_send.zoom = cmd->zoom;
187 if (change_pan_tilt) {
206 unsigned char request[4];
213 request_pkt.
Build(request, 4);
217 ROS_ERROR(
"Command message is too large to send");
228 memcpy(&mybuf[3], str, len);
229 ptz_packet.
Build(mybuf, len + 3);
239 static_cast<void>(reply);
242 unsigned char request[4];
249 request_pkt.
Build(request, 4);
253 ROS_ERROR(
"Request message is too large to send.");
264 memcpy(&mybuf[3], str, len);
265 ptz_packet.
Build(mybuf, len + 3);
294 byte = (
unsigned char)t;
296 if (byte == (
unsigned char)
RESPONSE) {
304 ROS_ERROR(
"Length is 0 on received packet.");
313 if (reply[len - 1] != (
unsigned char)
FOOTER) {
314 ROS_ERROR(
"canonvcc4::receiveCommandAnswer: Discarding bad packet.");
321 reply[len] = (
unsigned char)t;
328 ROS_ERROR(
"Answer does not equal command response bytes");
333 if (reply[0] != (
unsigned char)
RESPONSE || reply[5] != (
unsigned char)
FOOTER) {
334 ROS_ERROR(
"Header or Footer is wrong on received packet");
355 ROS_ERROR(
"Error: Unknown error response from camera.");
391 byte = (
unsigned char)t;
393 if (byte == (
unsigned char)
RESPONSE) {
400 ROS_ERROR(
"Received Request Answer has length 0");
408 if (reply[len - 1] != (
unsigned char)
FOOTER) {
409 ROS_ERROR(
"Last Byte was not the footer!");
416 reply[len] = (
unsigned char)t;
422 ROS_ERROR(
"Response Length was incorrect at %i.", len);
426 if (reply[0] != (
unsigned char)
RESPONSE ||
427 reply[len - 1] != (
unsigned char)
FOOTER)
429 ROS_ERROR(
"Header or Footer is wrong on received packet");
437 memcpy(data, reply, len);
451 ROS_ERROR(
"Error: Unknown error response from camera.");
460 unsigned char request[4];
462 bool secondSent =
false;
473 request_pkt.
Build(request, 4);
479 ROS_ERROR(
"Waiting for packet timed out.");
482 if (
cb_.
size() == s1 && !secondSent) {
485 int newsize = s2 - s1;
486 ROS_ERROR(
"Requesting Second Packet of size %i.", newsize);
487 request[2] = newsize;
488 request_pkt.
Build(request, 4);
493 ROS_ERROR(
"Got reply from AUX1 But don't have a full packet.");
585 unsigned char buf[4];
612 for (i = 0; i < 4; i++) {
617 byte = byte -
'A' + 10;
624 for (i = 0; i < 4; i++) {
625 u_zoom += buf[i] *
static_cast<unsigned int>(
pow(16.0, static_cast<double>(3 - i)));
637 unsigned char buf[4];
663 for (i = 0; i < 4; i++) {
668 byte = byte -
'A' + 10;
675 for (i = 0; i < 4; i++) {
676 u_zoom += buf[i] *
static_cast<unsigned int>(
pow(16.0, static_cast<double>(3 - i)));
685 unsigned char buf[5];
700 snprintf(reinterpret_cast<char *>(buf),
sizeof(buf),
"%4X", zoom);
702 for (i = 0; i < 3; i++) {
732 unsigned char buf[5];
733 int maxtilt, mintilt;
742 mintilt =
static_cast<int>(floor(
MIN_TILT / .1125) + 0x8000);
743 snprintf(reinterpret_cast<char *>(buf),
sizeof(buf),
"%X", mintilt);
748 maxtilt =
static_cast<int>(floor(
MAX_TILT / .1125) + 0x8000);
749 snprintf(reinterpret_cast<char *>(buf),
sizeof(buf),
"%X", maxtilt);
751 command[10] = buf[0];
752 command[11] = buf[1];
753 command[12] = buf[2];
754 command[13] = buf[3];
775 unsigned char buf[4];
797 if (reply_len != 14) {
798 ROS_ERROR(
"Reply Len = %i; should equal 14", reply_len);
803 for (i = 0; i < 4; i++) {
808 byte = byte -
'A' + 10;
814 u_val = buf[0] * 0x1000 + buf[1] * 0x100 + buf[2] * 0x10 + buf[3];
817 val =
static_cast<int>((
static_cast<int>(u_val) - 0x8000) * 0.1125);
823 for (i = 0; i < 4; i++) {
828 byte = byte -
'A' + 10;
832 u_val = buf[0] * 0x1000 + buf[1] * 0x100 + buf[2] * 0x10 + buf[3];
833 val =
static_cast<int>((
static_cast<int>(u_val) - 0x8000) * 0.1125);
842 int convpan, convtilt;
843 unsigned char buf[5];
846 ppan = pan; ttilt = tilt;
848 ppan =
static_cast<int>(
MIN_PAN);
850 ppan =
static_cast<int>(
MAX_PAN);
862 convpan =
static_cast<int>(floor(ppan / .1125)) + 0x8000;
863 convtilt =
static_cast<int>(floor(ttilt / .1125)) + 0x8000;
873 snprintf(reinterpret_cast<char *>(buf),
sizeof(buf),
"%X", convpan);
880 snprintf(reinterpret_cast<char *>(buf),
sizeof(buf),
"%X", convtilt);
882 command[10] = buf[1];
883 command[11] = buf[2];
884 command[12] = buf[3];
885 command[13] = (
unsigned char)
FOOTER;
907 : start(0), end(0), mysize(size), gotPack(false)
909 this->
buf =
new unsigned char[
size];
917 printf(
"0x%x ",
buf[i]);
949 return static_cast<int>(ret);
static const int MAX_COMMAND_LENGTH
int SendReceive(P2OSPacket *pkt, bool publish_data=true)
P2OSPtz(P2OSNode *p2os, bool bidirectional_com=false)
int setDefaultTiltRange()
int sendCommand(unsigned char *str, int len)
int getAbsPanTilt(int *pan, int *tilt)
static const int PACKET_TIMEOUT
int receiveCommandAnswer(int asize)
void putOnBuf(unsigned char c)
int sendAbsZoom(int zoom)
ROSLIB_DECL std::string command(const std::string &cmd)
int Build(unsigned char *data, unsigned char datasize)
static const int TILT_THRESH
void getPtzPacket(int s1, int s2=0)
static const int SLEEP_TIME_USEC
void callback(const p2os_msgs::PTZStateConstPtr &msg)
static const int COMMAND_RESPONSE_BYTES
int sendAbsPanTilt(int pan, int tilt)
static const int PAN_THRESH
int receiveRequestAnswer(unsigned char *data, int s1, int s2)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
static const int MAX_REQUEST_LENGTH
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
static const int ZOOM_THRESH
int getAbsZoom(int *zoom)
int sendRequest(unsigned char *str, int len, unsigned char *reply)
int getMaxZoom(int *max_zoom)
p2os_msgs::PTZState current_state_