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

ArSonyPTZ.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
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 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
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 AREXPORT bool ArSonyPTZ::packetHandler(ArRobotPacket *packet)
00257 {
00258   if (packet->getID() != 0xE0)
00259     return false;
00260 
00261   return true;
00262 }
00263 */

Generated on Tue Feb 20 10:51:41 2007 for Aria by  doxygen 1.4.0