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

ArServerHandlerCamera.h

Go to the documentation of this file.
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 #ifndef ARSERVERHANDLERCAMERA_H
00027 #define ARSERVERHANDLERCAMERA_H
00028 
00029 #include "Aria.h"
00030 
00031 #include "ArNetworking.h"
00032 
00075 class ArServerHandlerCamera : public ArCameraCollectionItem
00076 {
00077 private:
00078   static const char *CONTROL_COMMAND_GROUP;
00079   static const char *INFO_COMMAND_GROUP;
00080   static const char *NO_ARGS;
00081 public:
00082 
00084 
00093   AREXPORT ArServerHandlerCamera(const char *cameraName,
00094                                  ArServerBase *server,
00095                                  ArRobot *robot,
00096                                  ArPTZ *camera,
00097                                  ArCameraCollection *collection);
00098 
00100 
00108   AREXPORT ArServerHandlerCamera(ArServerBase *server, 
00109                                  ArRobot *robot, 
00110                                                          ArPTZ *camera);
00111 
00113   AREXPORT virtual ~ArServerHandlerCamera();
00114 
00115   // -----------------------------------------------------------------------------
00116   // ArCameraCollectionItem Interface:
00117   // -----------------------------------------------------------------------------
00118 
00120   AREXPORT void setCameraAbs(double pan, double tilt, double zoom, 
00121                                bool lockRobot = true);
00122 
00124   AREXPORT void setCameraRel(double pan, double tilt, double zoom, 
00125                              bool lockRobot = true);
00126 
00128   AREXPORT void setCameraPct(double panPct, double tiltPct, 
00129                              bool lockRobot = true);
00130 
00132   AREXPORT void resetCamera(bool lockRobot = true);
00133 
00135   AREXPORT void cameraModeLookAtGoal(void);
00136 
00138   AREXPORT void cameraModeLookAtPoint(ArPose pose);
00139 
00141   AREXPORT void cameraModeLookAtGoalSetGoal(ArPose pose);
00143   AREXPORT void cameraModeLookAtGoalClearGoal(void);
00144 
00146   AREXPORT void cameraModePosition(void);
00147 
00148 
00149 
00150 
00151 
00152 
00154 
00158   AREXPORT const char *getCameraName();
00159 
00161 
00164   AREXPORT virtual void addToCameraCollection(ArCameraCollection &collection);
00165 
00166 
00167   // -----------------------------------------------------------------------------
00168   // Packet Handlers:
00169   // -----------------------------------------------------------------------------
00170 
00171   // New methods that send/receive "double"s
00172 
00174 
00178   AREXPORT void handleGetCameraData(ArServerClient *client, ArNetPacket *packet);
00179 
00181 
00185   AREXPORT void handleGetCameraInfo(ArServerClient *client, ArNetPacket *packet);
00186 
00188 
00192   AREXPORT void handleSetCameraAbs(ArServerClient *client, ArNetPacket *packet);
00193 
00195 
00199   AREXPORT void handleSetCameraPct(ArServerClient *client, ArNetPacket *packet);
00200 
00202 
00206   AREXPORT void handleSetCameraRel(ArServerClient *client, ArNetPacket *packet);
00207 
00209 
00213   AREXPORT void handleGetCameraModeList(ArServerClient *client, ArNetPacket *packet);
00214 
00216 
00223   AREXPORT void handleCameraModeUpdated(ArServerClient *client, 
00224                                                                       ArNetPacket *packet);
00225 
00227 
00238   AREXPORT void handleSetCameraMode(ArServerClient *client, 
00239                                                             ArNetPacket *packet);
00240 
00242 
00246   AREXPORT void handleResetCamera(ArServerClient *client, 
00247                                                           ArNetPacket *packet);
00248   // Old methods that send/receive ints
00249 
00251   AREXPORT void camera(ArServerClient *client, ArNetPacket *packet);
00253   AREXPORT void cameraAbs(ArServerClient *client, ArNetPacket *packet);
00255   AREXPORT void cameraPct(ArServerClient *client, ArNetPacket *packet);
00257   AREXPORT void cameraUpdate(ArServerClient *client, ArNetPacket *packet);
00259   AREXPORT void cameraInfo(ArServerClient *client, ArNetPacket *packet);
00260 
00261 protected:
00262 
00263 
00264   // -----------------------------------------------------------------------------
00265   // Helper Methods:
00266   // -----------------------------------------------------------------------------
00267 
00268   enum {
00269     DOUBLE_FACTOR = 100 
00270   };
00271 
00273 
00276   AREXPORT void addDoubleToPacket(double val,
00277                                   ArNetPacket &packet)
00278   {
00279     // TODO: Does this need to be rounded? Any error/overflow checking?
00280     packet.byte2ToBuf((ArTypes::Byte2) (val * DOUBLE_FACTOR));
00281   }
00282   
00283 
00285 
00288   AREXPORT double getDoubleFromPacket(ArNetPacket &packet)
00289   {
00290     int tempVal = packet.bufToByte2();
00291     return ((double) tempVal / (double) DOUBLE_FACTOR);
00292   }
00293 
00295   AREXPORT double getCurrentZoomRatio()
00296   {
00297     if (myCamera->getMaxZoom() != myCamera->getMinZoom()) {
00298 
00299      return ((double)(myCamera->getZoom() -  myCamera->getMinZoom()))
00300              / ((double)(myCamera->getMaxZoom() - myCamera->getMinZoom()));
00301     }
00302     else {
00303       return 0;
00304     }
00305   } // end method getCurrentZoomRatio
00306  
00307 
00309   AREXPORT double getZoomRatio(double absZoom)
00310   {
00311     if (myCamera->getMaxZoom() != myCamera->getMinZoom()) {
00312 
00313       return ((double)(absZoom - myCamera->getMinZoom()))
00314               / ((double)(myCamera->getMaxZoom() - myCamera->getMinZoom()));
00315     }
00316     else {
00317       return 0;
00318     }
00319   } // end method getZoomRatio
00320 
00321 
00323   AREXPORT double getZoomRange()
00324   {
00325     return myCamera->getMaxZoom() - myCamera->getMinZoom();
00326 
00327   } // end method getZoomRange
00328 
00329 
00330 private:
00331   
00333   void init();
00334 
00336   void createCommandNames();
00337 
00339   void createCommandCBs();
00340 
00342   void addAllCommandsToServer();
00343   
00345   void addCommandToServer(const char *command, 
00346                           const char *description,
00347                                                   const char *argumentDescription,
00348                                                   const char *returnDescription,
00349                           const char *commandGroup);
00350 
00352   void removeCommand(const char *command);
00353 
00355   void doAddToCameraCollection(ArCameraCollection &collection);
00356 
00357 protected:
00358 
00360   ArRobot *myRobot;
00362   ArServerBase *myServer;
00364   ArPTZ *myCamera;
00365 
00367   std::string myCameraName;
00369   ArCameraCollection *myCameraCollection;
00370 
00372   std::map<std::string, std::string> myCommandToPacketNameMap;
00374   std::map<std::string, int> myCommandToIntervalMap;
00375 
00377   std::map<std::string, ArFunctor2<ArServerClient *, ArNetPacket *> *> myCommandToCBMap;
00378 
00379   enum CameraMode
00380   {
00381     CAMERA_MODE_POSITION,
00382     CAMERA_MODE_LOOK_AT_GOAL,
00383     CAMERA_MODE_LOOK_AT_POINT
00384   };
00385   
00386   ArMutex myModeMutex;
00387   CameraMode myCameraMode;
00388   std::map<CameraMode, std::string> myCameraModeNameMap;
00389   ArNetPacket myCameraModePacket;
00390   ArPose myLookAtPoint;
00391   bool myPointResetZoom;
00392   ArPose myGoal;
00393   bool myGoalAchieved;
00394   bool myGoalAchievedLast;
00395   bool myGoalResetZoom;
00396 
00397 
00398   void userTask(void);
00399   void buildModePacket(void);
00400 
00401   ArFunctorC<ArServerHandlerCamera> myUserTaskCB;
00402 
00403   // Leaving these just in case they are used by someone... 
00404 
00406 
00409   ArFunctor2C<ArServerHandlerCamera, 
00410       ArServerClient *, ArNetPacket *> myCameraCB;
00412 
00415   ArFunctor2C<ArServerHandlerCamera, 
00416       ArServerClient *, ArNetPacket *> myCameraAbsCB;
00418 
00421   ArFunctor2C<ArServerHandlerCamera, 
00422       ArServerClient *, ArNetPacket *> myCameraUpdateCB;
00424 
00427   ArFunctor2C<ArServerHandlerCamera, 
00428       ArServerClient *, ArNetPacket *> myCameraInfoCB;
00429 
00430 }; // end class ArServerHandlerCamera
00431 
00432 #endif 

Generated on Tue Feb 20 10:51:50 2007 for ArNetworking by  doxygen 1.4.0