CameraROS.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00033 
00034 
00035 /* TODO:
00036  - subscribe /camera/camera_info for camera parameters (optional) 
00037  - subscribe /camera/image_raw for camera images (mandatory)
00038  - manage image acquisition "on demand"
00039  - ask Paolo about the new scheduler (camera may open a new thread to acquire images,
00040   it seems to be better than polling on camera for the last image)
00041  - convert images to opencv format
00042 */
00043 
00044 #ifndef CAMERAROS_H
00045 #define CAMERAROS_H
00046 
00047 #ifdef MIP_HOST_APPLE
00048  #include <applePatch.h>
00049 #endif
00050 
00051 #include <Camera.h>
00052 
00053 #include <includeROS.h>
00054 #include <SpacesArma.h>
00055 #include <CameraParameters.h>
00056 #include <ROSNode.h>
00057 //#include <sensor_msgs/Imu.h>
00058 
00059 // Algorithm to extract feature from camera view
00060 //#include <BearExtrCam.h>
00061 
00062 namespace MipResources{
00064  /* @{ */
00065  
00071  
00075  class CameraRosOptions : public Options {
00076   public:
00077    StringOption  *infoCamTopicName;
00078    StringOption  *imageTopicName;
00079    StringOption  *cameraNode;
00080    StringOption  *nodeName;
00081    BoolOption   *addId;
00082    
00084    StringOption *robotName;
00085    
00086    CameraRosOptions();
00087    
00088    string getObjectName() const{
00089     return "CameraROS";
00090    }
00091    OptionGroupsType getGroup() {
00092     return OPT_GRP_RESO;
00093    }
00094  };
00095  
00096  class CameraROSPar{
00097   private:
00098    CameraPar3DArma*  _infoCam;
00099    
00100   public:
00101    
00103    CameraROSPar();
00104    
00106    CameraROSPar(const CameraROSPar& A);
00107    
00109    CameraROSPar& operator=(const CameraROSPar& A);
00110    
00113    CameraPar3DArma* getCamPars();
00114    
00117    void setCamPars(CameraPar3DArma* cPar);
00118    
00127    void initCamPars(const Decimal &info1, const Decimal &info2, const Decimal &info3,int opt, const Position2DArma &pp=Position2DArma(), const Decimal sk = 0.0, const Roto3DHomoArma &rcfw=Roto3DHomoArma(IDENTITY_ARMA_MATRIX),CanonicalCameraArmaMatrix cc=PIXEL_CAMERA_ARMA_MATRIX);
00128  };
00129  
00133  class CameraROS : public Camera {
00134   protected:
00135    ros::NodeHandle*       handleImage_subscriber;
00136    ros::Subscriber*        _subscriberCam;
00137    ros::Subscriber*        _subscriberInfoCam;
00138    
00140    bool              _firstParsInit;
00141    
00142    uint             _step;
00143    
00144 //    CameraPar3DArma*       _pars;
00145    CameraROSPar*         _pars;
00146    
00147    CameraRosOptions*       _options;
00148    
00149    // CAMERA IMAGE
00150    vector<uint8_t>        _currImage;
00151    cv::Mat            _currCVImage;
00152    cv::Mat            _currCVModImage;
00153    ros::Time           _currImageTime;
00154    bool              _firstImageInit;
00155    
00156   public:
00158    CameraROS(int argc, const char** argv);
00159    
00161    CameraROS(int argc, char** argv,int opt);
00162    
00164    ~CameraROS();
00165    
00166    void cameraROSCallback(const sensor_msgs::Image::ConstPtr& msg);
00167    
00168    void cameraROSInfoCallback(const sensor_msgs::CameraInfo::ConstPtr& msg);
00169    
00171    void updateCallbacks();
00172    
00175    ResourcePlate getPlate() const {
00176     return CAM_ROS_RES;
00177    }
00178    
00181    cv::Mat getImage();
00182    
00185    ros::Time getImageTime();
00186    
00190    void getImage(cv::Mat &image, ros::Time &time);
00191  };
00192 
00193 }; // end of namespace
00194 
00195 #endif // CAMERAROS_H
00196 
00197 /* @} */
00198 
00199 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6