Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

PlayerConnect.h

Go to the documentation of this file.
00001 /* Copyright (C) 2002 Dominic Letourneau (dominic.letourneau@courrier.usherb.ca)
00002 
00003    This library is free software; you can redistribute it and/or
00004    modify it under the terms of the GNU Lesser General Public
00005    License as published by the Free Software Foundation; either
00006    version 2.1 of the License, or (at your option) any later version.
00007    
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Lesser General Public License for more details.
00012    
00013    You should have received a copy of the GNU Lesser General Public
00014    License along with this library; if not, write to the Free Software
00015    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 */
00017 #ifndef _PLAYERCONNECT_H_
00018 #define _PLAYERCONNECT_H_
00019 
00020 #include "playerclient.h"
00021 #include "Object.h"
00022 #include "BufferedNode.h"
00023 
00024 namespace RobotFlow {
00025 
00026 class PlayerClientWrap : public FD::Object {
00027 
00028  private:
00029 
00030   PlayerClient m_client;
00031   PositionProxy *m_positionProxy;
00032   GripperProxy *m_gripperProxy;
00033   LaserProxy *m_laserProxy;
00034   LaserProxy *m_laser2Proxy;
00035   PtzProxy *m_ptzProxy;
00036   SonarProxy *m_sonarProxy;
00037   BlobfinderProxy *m_blobFinderProxy;
00038   GpsProxy *m_gpsProxy;
00039 
00040 
00041   void createProxies(bool startPositionProxy, bool startGripperProxy,
00042                      bool startLaserProxy, bool startPTZProxy,
00043                      bool startSonarProxy, bool startBlobFinderProxy,
00044                      bool startGPSProxy, bool startLaser2Proxy)
00045   {
00046 
00047     //create all proxies
00048     if(startPositionProxy)
00049     {
00050        m_positionProxy = new PositionProxy(&m_client,0,'a');
00051     }
00052     if(startGripperProxy)
00053     {
00054        m_gripperProxy =  new GripperProxy(&m_client,0,'a');
00055     }
00056     if(startLaserProxy)
00057     {
00058        m_laserProxy = new LaserProxy(&m_client,0,'a');
00059     }
00060     if(startPTZProxy)
00061     {
00062        m_ptzProxy =  new PtzProxy(&m_client,0,'a');
00063     }
00064     if(startSonarProxy)
00065     {
00066        m_sonarProxy =  new SonarProxy(&m_client,0,'a');
00067     }
00068     if(startBlobFinderProxy)
00069     {
00070        m_blobFinderProxy =  new BlobfinderProxy(&m_client,0,'a');
00071     }
00072     if(startGPSProxy)
00073     {
00074        m_gpsProxy =  new GpsProxy(&m_client,0,'a');
00075     }
00076     if(startLaser2Proxy)
00077     {
00078        m_laser2Proxy = new LaserProxy(&m_client,1,'a');
00079     }
00080   }
00081 
00082   void destroyProxies() 
00083   {
00084     // delete all proxies
00085     if (m_positionProxy) 
00086     {
00087        delete m_positionProxy;
00088        m_positionProxy = NULL;
00089     }
00090     
00091     if (m_gripperProxy) 
00092     {
00093        delete m_gripperProxy;
00094        m_gripperProxy = NULL;
00095     }
00096 
00097     if (m_laserProxy)
00098     {
00099        delete m_laserProxy;
00100        m_laserProxy = NULL;
00101     }
00102 
00103     if (m_ptzProxy)
00104     {
00105        delete m_ptzProxy;
00106        m_ptzProxy = NULL;
00107     }
00108 
00109     if (m_sonarProxy)
00110     {
00111        delete m_sonarProxy;
00112        m_sonarProxy = NULL;
00113     }
00114 
00115     if (m_blobFinderProxy)
00116     {
00117        delete m_blobFinderProxy;
00118        m_blobFinderProxy = NULL;
00119     }
00120 
00121     if (m_gpsProxy)
00122     {
00123        delete m_gpsProxy;
00124        m_gpsProxy = NULL;
00125     }
00126 
00127     if (m_laser2Proxy)
00128     {
00129        delete m_laser2Proxy;
00130        m_laser2Proxy = NULL;
00131     }
00132   }
00133 
00134  public:
00135 
00136   PlayerClientWrap(const char* hostname=NULL, int port=PLAYER_PORTNUM, 
00137                    bool startPositionProxy = true, bool startGripperProxy = true,
00138                    bool startLaserProxy = true, bool startPTZProxy = true,
00139                    bool startSonarProxy = true, bool startBlobFinderProxy = true,
00140                    bool startGPSProxy = true, bool startLaser2Proxy = true)
00141     : m_client(hostname,port), m_positionProxy(NULL),
00142     m_gripperProxy(NULL), m_laserProxy(NULL), m_ptzProxy(NULL),
00143     m_sonarProxy (NULL), m_blobFinderProxy(NULL), m_gpsProxy(NULL), m_laser2Proxy(NULL)
00144   {
00145 
00146     createProxies(startPositionProxy, startGripperProxy, startLaserProxy,
00147                   startPTZProxy,startSonarProxy, startBlobFinderProxy,
00148                   startGPSProxy, startLaser2Proxy);
00149 
00150   }
00151 
00152   ~PlayerClientWrap() {
00153     destroyProxies();
00154   }
00155   
00156   PositionProxy * getPositionProxy() {return m_positionProxy;}
00157 
00158   GripperProxy * getGripperProxy() {return m_gripperProxy;}
00159 
00160   LaserProxy * getLaserProxy() {return m_laserProxy;}
00161 
00162   PtzProxy * getPtzProxy() {return m_ptzProxy;}
00163 
00164   SonarProxy *getSonarProxy() {return m_sonarProxy;}
00165 
00166   BlobfinderProxy * getBlobFinderProxy() {return m_blobFinderProxy;}
00167 
00168   GpsProxy * getGpsProxy() {return m_gpsProxy;}
00169 
00170   LaserProxy * getLaser2Proxy() {return m_laser2Proxy;}
00171 
00172   // check if we are connected
00173   bool Connected() { return (m_client.Connected());}
00174 
00175   int Connect(const char* hostname, int port) {
00176     return (m_client.Connect(hostname,port));
00177   }
00178 
00179   int Connect(const char* hostname) { 
00180     return (m_client.Connect(hostname,PLAYER_PORTNUM)); 
00181   }
00182 
00183   int Connect() { 
00184     return(m_client.Connect("localhost",PLAYER_PORTNUM)); 
00185   }
00186 
00187   int Disconnect() {
00188     return (m_client.Disconnect());
00189   }
00190 
00191   
00192   PlayerClient & get_player_client() {return m_client;}
00193 
00194   void printOn(std::ostream &out = std::cout) const {
00195     out<<"<PlayerClientWrap>\n";
00196   }
00197 };
00198 
00199 
00200 class PlayerConnect : public FD::BufferedNode {
00201   
00202   FD::ObjectRef m_client;
00203 
00204   bool m_isInit;
00205 
00206   int m_port;
00207   std::string m_host;
00208   int  m_frequency;
00209   bool m_startPositionProxy;
00210   bool m_startGripperProxy;
00211   bool m_startLaserProxy;
00212   bool m_startLaser2Proxy;
00213   bool m_startPTZProxy;
00214   bool m_startSonarProxy;
00215   bool m_startBlobFinderProxy;
00216   bool m_startGPSProxy;
00217   int m_outputID;
00218   PositionProxy *m_positionProxy;
00219 
00220 public:
00221 
00222   PlayerConnect(std::string nodeName, FD::ParameterSet params);
00223 
00224   virtual ~PlayerConnect();
00225      
00226   void calculate(int output_id, int count, FD::Buffer &out);
00227 
00228 };
00229 
00230 }//namespace RobotFlow
00231 #endif

Generated on Wed Oct 5 14:36:12 2005 for RobotFlow by  doxygen 1.4.4