Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArSonyPTZ.cpp

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArSonyPTZ.h"
00030 #include "ArRobot.h"
00031 #include "ArCommands.h"
00032 
00033 ArSonyPacket::ArSonyPacket(ArTypes::UByte2 bufferSize) :
00034   ArBasePacket(bufferSize)
00035 {
00036   
00037 }
00038 
00039 ArSonyPacket::~ArSonyPacket()
00040 {
00041 
00042 }
00043 
00044 void ArSonyPacket::uByteToBuf(ArTypes::UByte val)
00045 {
00046   if (myLength + 1 > myMaxLength)
00047   {
00048     ArLog::log(ArLog::Terse, "ArSonyPacket::uByteToBuf: Trying to add beyond length of buffer.");
00049     return;
00050   }
00051   myBuf[myLength] = val;
00052   ++myLength;
00053 }
00054 
00055 void ArSonyPacket::byte2ToBuf(ArTypes::Byte2 val)
00056 {
00057   if ((myLength + 4) > myMaxLength)
00058   {
00059     ArLog::log(ArLog::Terse, "ArSonyPacket::Byte2ToBuf: Trying to add beyond length of buffer.");
00060     return;
00061   }
00062   myBuf[myLength] = (val & 0xf000) >> 12;
00063   ++myLength;
00064   myBuf[myLength] = (val & 0x0f00) >> 8;
00065   ++myLength;
00066   myBuf[myLength] = (val & 0x00f0) >> 4;
00067   ++myLength;
00068   myBuf[myLength] = (val & 0x000f) >> 0;
00069   ++myLength;
00070 }
00071 
00082 void ArSonyPacket::byte2ToBufAtPos(ArTypes::Byte2 val,
00083                                             ArTypes::UByte2 pose)
00084 {
00085   ArTypes::Byte2 prevLength = myLength;
00086 
00087   if ((pose + 4) > myMaxLength)
00088   {
00089     ArLog::log(ArLog::Terse, "ArSonyPacket::Byte2ToBuf: Trying to add beyond length of buffer.");
00090     return;
00091   }
00092   myLength = pose;
00093   byte2ToBuf(val);
00094   myLength = prevLength;
00095 }
00096 
00097 
00098 ArSonyPTZ::ArSonyPTZ(ArRobot *robot) :
00099   ArPTZ(robot),
00100   myPacket(255), 
00101   myZoomPacket(9)
00102 {
00103   myRobot = robot;
00104   initializePackets();
00105   
00106   myDegToTilt = 0x12c / ((double) MAX_TILT);
00107   myDegToPan = 0x370 / ((double) MAX_PAN);
00108 }
00109 
00110 ArSonyPTZ::~ArSonyPTZ()
00111 {
00112 }
00113 
00114 void ArSonyPTZ::initializePackets(void)
00115 {
00116   myZoomPacket.empty();
00117   myZoomPacket.uByteToBuf(0x81);
00118   myZoomPacket.uByteToBuf(0x01);
00119   myZoomPacket.uByteToBuf(0x04);
00120   myZoomPacket.uByteToBuf(0x47);
00121   myZoomPacket.uByteToBuf(0x00);
00122   myZoomPacket.uByteToBuf(0x00);
00123   myZoomPacket.uByteToBuf(0x00);
00124   myZoomPacket.uByteToBuf(0x00);
00125   myZoomPacket.uByteToBuf(0xff);
00126 
00127   myPanTiltPacket.empty();
00128   myPanTiltPacket.uByteToBuf(0x81);
00129   myPanTiltPacket.uByteToBuf(0x01);
00130   myPanTiltPacket.uByteToBuf(0x06);
00131   myPanTiltPacket.uByteToBuf(0x02);
00132   myPanTiltPacket.uByteToBuf(0x18);
00133   myPanTiltPacket.uByteToBuf(0x14);
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(0x00);
00142   myPanTiltPacket.uByteToBuf(0xff);
00143 }
00144 
00145 
00146 bool ArSonyPTZ::init(void)
00147 {
00148   myPacket.empty();
00149   myPacket.uByteToBuf(0x88);
00150   myPacket.uByteToBuf(0x01);
00151   myPacket.uByteToBuf(0x00);
00152   myPacket.uByteToBuf(0x01);
00153   myPacket.uByteToBuf(0xff);
00154   myPacket.uByteToBuf(0x88);
00155   myPacket.uByteToBuf(0x30);
00156   myPacket.uByteToBuf(0x01);
00157   myPacket.uByteToBuf(0xff);
00158 
00159   if (!sendPacket(&myPacket))
00160     return false;
00161   if (!panTilt(0, 0))
00162     return false;
00163   if (!zoom(0))
00164     return false;
00165   return true;
00166 }
00167 
00168 bool ArSonyPTZ::backLightingOn(void)
00169 {
00170   myPacket.empty();
00171   myPacket.uByteToBuf(0x81);
00172   myPacket.uByteToBuf(0x01);
00173   myPacket.uByteToBuf(0x04);
00174   myPacket.uByteToBuf(0x33);
00175   myPacket.uByteToBuf(0x02);
00176   myPacket.uByteToBuf(0xff);
00177 
00178   return sendPacket(&myPacket);
00179 }
00180 
00181 bool ArSonyPTZ::backLightingOff(void)
00182 {
00183   myPacket.empty();
00184   myPacket.uByteToBuf(0x81);
00185   myPacket.uByteToBuf(0x01);
00186   myPacket.uByteToBuf(0x04);
00187   myPacket.uByteToBuf(0x33);
00188   myPacket.uByteToBuf(0x03);
00189   myPacket.uByteToBuf(0xff);
00190 
00191   return sendPacket(&myPacket);
00192 }
00193 
00194 bool ArSonyPTZ::panTilt(int degreesPan, int degreesTilt)
00195 {
00196   if (degreesPan > MAX_PAN)
00197     degreesPan = MAX_PAN;
00198   if (degreesPan < -MAX_PAN)
00199     degreesPan = -MAX_PAN;
00200   myPan = degreesPan;
00201 
00202   if (degreesTilt > MAX_TILT)
00203     degreesTilt = MAX_TILT;
00204   if (degreesTilt < -MAX_TILT)
00205     degreesTilt = -MAX_TILT;
00206   myTilt = degreesTilt;
00207 
00208   myPanTiltPacket.byte2ToBufAtPos(ArMath::roundInt(myPan * myDegToPan), 6);
00209   myPanTiltPacket.byte2ToBufAtPos(ArMath::roundInt(myTilt * myDegToTilt), 10);
00210   return sendPacket(&myPanTiltPacket);
00211 }
00212 
00213 bool ArSonyPTZ::panTiltRel(int degreesPan, int degreesTilt)
00214 {
00215   return panTilt(myPan + degreesPan, myTilt + degreesTilt);
00216 }
00217 
00218 bool ArSonyPTZ::pan(int degrees)
00219 {
00220   return panTilt(degrees, myTilt);
00221 }
00222 
00223 bool ArSonyPTZ::panRel(int degrees)
00224 {
00225   return panTiltRel(degrees, 0);
00226 }
00227 
00228 bool ArSonyPTZ::tilt(int degrees)
00229 {
00230   return panTilt(myPan, degrees);
00231 }
00232 
00233 bool ArSonyPTZ::tiltRel(int degrees)
00234 {
00235   return panTiltRel(0, degrees);
00236 }
00237 
00238 bool ArSonyPTZ::zoom(int zoomValue)
00239 {
00240   if (zoomValue > MAX_ZOOM)
00241     zoomValue = MAX_ZOOM;
00242   if (zoomValue < MIN_ZOOM)
00243     zoomValue = MIN_ZOOM;
00244   myZoom = zoomValue;
00245     
00246   myZoomPacket.byte2ToBufAtPos(myZoom, 4);
00247   return sendPacket(&myZoomPacket);
00248 }
00249 
00250 bool ArSonyPTZ::zoomRel(int zoomValue)
00251 {
00252   return zoom(myZoom + zoomValue);
00253 }
00254 
00255 
00256 /*
00257 bool ArSonyPTZ::packetHandler(ArRobotPacket *packet)
00258 {
00259   if (packet->getID() != 0xE0)
00260     return false;
00261 
00262   return true;
00263 }
00264 */

Generated on Wed Oct 19 12:56:37 2005 for Aria by  doxygen 1.4.0