00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArSonyPTZ.h"
00029 #include "ArRobot.h"
00030 #include "ArCommands.h"
00031
00032 AREXPORT ArSonyPacket::ArSonyPacket(ArTypes::UByte2 bufferSize) :
00033 ArBasePacket(bufferSize)
00034 {
00035
00036 }
00037
00038 AREXPORT ArSonyPacket::~ArSonyPacket()
00039 {
00040
00041 }
00042
00043 AREXPORT void ArSonyPacket::uByteToBuf(ArTypes::UByte val)
00044 {
00045 if (myLength + 1 > myMaxLength)
00046 {
00047 ArLog::log(ArLog::Terse, "ArSonyPacket::uByteToBuf: Trying to add beyond length of buffer.");
00048 return;
00049 }
00050 myBuf[myLength] = val;
00051 ++myLength;
00052 }
00053
00054 AREXPORT void ArSonyPacket::byte2ToBuf(ArTypes::Byte2 val)
00055 {
00056 if ((myLength + 4) > myMaxLength)
00057 {
00058 ArLog::log(ArLog::Terse, "ArSonyPacket::Byte2ToBuf: Trying to add beyond length of buffer.");
00059 return;
00060 }
00061 myBuf[myLength] = (val & 0xf000) >> 12;
00062 ++myLength;
00063 myBuf[myLength] = (val & 0x0f00) >> 8;
00064 ++myLength;
00065 myBuf[myLength] = (val & 0x00f0) >> 4;
00066 ++myLength;
00067 myBuf[myLength] = (val & 0x000f) >> 0;
00068 ++myLength;
00069 }
00070
00081 AREXPORT void ArSonyPacket::byte2ToBufAtPos(ArTypes::Byte2 val,
00082 ArTypes::UByte2 pose)
00083 {
00084 ArTypes::Byte2 prevLength = myLength;
00085
00086 if ((pose + 4) > myMaxLength)
00087 {
00088 ArLog::log(ArLog::Terse, "ArSonyPacket::Byte2ToBuf: Trying to add beyond length of buffer.");
00089 return;
00090 }
00091 myLength = pose;
00092 byte2ToBuf(val);
00093 myLength = prevLength;
00094 }
00095
00096
00097 AREXPORT ArSonyPTZ::ArSonyPTZ(ArRobot *robot) :
00098 ArPTZ(robot),
00099 myPacket(255),
00100 myZoomPacket(9)
00101 {
00102 myRobot = robot;
00103 initializePackets();
00104
00105 myDegToTilt = 0x12c / ((double) MAX_TILT);
00106 myDegToPan = 0x370 / ((double) MAX_PAN);
00107 }
00108
00109 AREXPORT ArSonyPTZ::~ArSonyPTZ()
00110 {
00111 }
00112
00113 void ArSonyPTZ::initializePackets(void)
00114 {
00115 myZoomPacket.empty();
00116 myZoomPacket.uByteToBuf(0x81);
00117 myZoomPacket.uByteToBuf(0x01);
00118 myZoomPacket.uByteToBuf(0x04);
00119 myZoomPacket.uByteToBuf(0x47);
00120 myZoomPacket.uByteToBuf(0x00);
00121 myZoomPacket.uByteToBuf(0x00);
00122 myZoomPacket.uByteToBuf(0x00);
00123 myZoomPacket.uByteToBuf(0x00);
00124 myZoomPacket.uByteToBuf(0xff);
00125
00126 myPanTiltPacket.empty();
00127 myPanTiltPacket.uByteToBuf(0x81);
00128 myPanTiltPacket.uByteToBuf(0x01);
00129 myPanTiltPacket.uByteToBuf(0x06);
00130 myPanTiltPacket.uByteToBuf(0x02);
00131 myPanTiltPacket.uByteToBuf(0x18);
00132 myPanTiltPacket.uByteToBuf(0x14);
00133 myPanTiltPacket.uByteToBuf(0x00);
00134 myPanTiltPacket.uByteToBuf(0x00);
00135 myPanTiltPacket.uByteToBuf(0x00);
00136 myPanTiltPacket.uByteToBuf(0x00);
00137 myPanTiltPacket.uByteToBuf(0x00);
00138 myPanTiltPacket.uByteToBuf(0x00);
00139 myPanTiltPacket.uByteToBuf(0x00);
00140 myPanTiltPacket.uByteToBuf(0x00);
00141 myPanTiltPacket.uByteToBuf(0xff);
00142 }
00143
00144
00145 AREXPORT bool ArSonyPTZ::init(void)
00146 {
00147 myPacket.empty();
00148 myPacket.uByteToBuf(0x88);
00149 myPacket.uByteToBuf(0x01);
00150 myPacket.uByteToBuf(0x00);
00151 myPacket.uByteToBuf(0x01);
00152 myPacket.uByteToBuf(0xff);
00153 myPacket.uByteToBuf(0x88);
00154 myPacket.uByteToBuf(0x30);
00155 myPacket.uByteToBuf(0x01);
00156 myPacket.uByteToBuf(0xff);
00157
00158 if (!sendPacket(&myPacket))
00159 return false;
00160 if (!panTilt(0, 0))
00161 return false;
00162 if (!zoom(0))
00163 return false;
00164 return true;
00165 }
00166
00167 AREXPORT bool ArSonyPTZ::backLightingOn(void)
00168 {
00169 myPacket.empty();
00170 myPacket.uByteToBuf(0x81);
00171 myPacket.uByteToBuf(0x01);
00172 myPacket.uByteToBuf(0x04);
00173 myPacket.uByteToBuf(0x33);
00174 myPacket.uByteToBuf(0x02);
00175 myPacket.uByteToBuf(0xff);
00176
00177 return sendPacket(&myPacket);
00178 }
00179
00180 AREXPORT bool ArSonyPTZ::backLightingOff(void)
00181 {
00182 myPacket.empty();
00183 myPacket.uByteToBuf(0x81);
00184 myPacket.uByteToBuf(0x01);
00185 myPacket.uByteToBuf(0x04);
00186 myPacket.uByteToBuf(0x33);
00187 myPacket.uByteToBuf(0x03);
00188 myPacket.uByteToBuf(0xff);
00189
00190 return sendPacket(&myPacket);
00191 }
00192
00193 AREXPORT bool ArSonyPTZ::panTilt(double degreesPan, double degreesTilt)
00194 {
00195 if (degreesPan > MAX_PAN)
00196 degreesPan = MAX_PAN;
00197 if (degreesPan < -MAX_PAN)
00198 degreesPan = -MAX_PAN;
00199 myPan = degreesPan;
00200
00201 if (degreesTilt > MAX_TILT)
00202 degreesTilt = MAX_TILT;
00203 if (degreesTilt < -MAX_TILT)
00204 degreesTilt = -MAX_TILT;
00205 myTilt = degreesTilt;
00206
00207 myPanTiltPacket.byte2ToBufAtPos(ArMath::roundInt(myPan * myDegToPan), 6);
00208 myPanTiltPacket.byte2ToBufAtPos(ArMath::roundInt(myTilt * myDegToTilt), 10);
00209 return sendPacket(&myPanTiltPacket);
00210 }
00211
00212 AREXPORT bool ArSonyPTZ::panTiltRel(double degreesPan, double degreesTilt)
00213 {
00214 return panTilt(myPan + degreesPan, myTilt + degreesTilt);
00215 }
00216
00217 AREXPORT bool ArSonyPTZ::pan(double degrees)
00218 {
00219 return panTilt(degrees, myTilt);
00220 }
00221
00222 AREXPORT bool ArSonyPTZ::panRel(double degrees)
00223 {
00224 return panTiltRel(degrees, 0);
00225 }
00226
00227 AREXPORT bool ArSonyPTZ::tilt(double degrees)
00228 {
00229 return panTilt(myPan, degrees);
00230 }
00231
00232 AREXPORT bool ArSonyPTZ::tiltRel(double degrees)
00233 {
00234 return panTiltRel(0, degrees);
00235 }
00236
00237 AREXPORT bool ArSonyPTZ::zoom(int zoomValue)
00238 {
00239 if (zoomValue > MAX_ZOOM)
00240 zoomValue = MAX_ZOOM;
00241 if (zoomValue < MIN_ZOOM)
00242 zoomValue = MIN_ZOOM;
00243 myZoom = zoomValue;
00244
00245 myZoomPacket.byte2ToBufAtPos(ArMath::roundInt(myZoom), 4);
00246 return sendPacket(&myZoomPacket);
00247 }
00248
00249 AREXPORT bool ArSonyPTZ::zoomRel(int zoomValue)
00250 {
00251 return zoom(myZoom + zoomValue);
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263