00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 00029 #ifndef CROVIO_H 00030 #define CROVIO_H 00031 00032 #include <mrpt/utils/utils_defs.h> 00033 #include <mrpt/utils/TCamera.h> 00034 #include <mrpt/hwdrivers/link_pragmas.h> 00035 #include <mrpt/synch/CCriticalSection.h> 00036 #include <mrpt/synch/CThreadSafeVariable.h> 00037 #include <mrpt/slam/CObservationImage.h> 00038 00039 #include <mrpt/hwdrivers/CGenericSensor.h> 00040 00041 00042 namespace mrpt 00043 { 00044 namespace hwdrivers 00045 { 00046 using namespace std; 00047 using namespace mrpt::slam; 00048 00049 /** A class to interface a Rovio robot (manufactured by WowWee). 00050 * Supports: Simple motion commands, video streaming. 00051 * \ingroup mrpt_hwdrivers_grp 00052 */ 00053 class HWDRIVERS_IMPEXP CRovio 00054 { 00055 private: 00056 mrpt::system::TThreadHandle m_videoThread; 00057 bool m_videothread_must_exit; 00058 bool m_videothread_initialized_done; 00059 bool m_videothread_initialized_error; 00060 bool m_videothread_finished; 00061 00062 mrpt::slam::CObservationImagePtr buffer_img; 00063 mrpt::synch::CCriticalSection buffer_img_cs; 00064 00065 00066 /** This function takes a frame and waits until getLastImage ask for it, and so on. 00067 */ 00068 void thread_video(); 00069 00070 bool send_cmd_action(int act, int speed); 00071 00072 bool path_management(int act); 00073 00074 bool path_management(int act, const string &path_name); 00075 00076 bool general_command(int act, string &response, string &errormsg); 00077 00078 00079 public: 00080 struct TOptions 00081 { 00082 string IP; 00083 string user; 00084 string password; 00085 00086 mrpt::utils::TCamera cameraParams; // Mat. cam. preguntar paco 00087 00088 TOptions(); 00089 } options; 00090 00091 enum status {idle, driving_home, docking, executing_path, recording_path}; 00092 00093 struct TRovioState{ 00094 status state; 00095 unsigned int nss; //Navigation Signal Strength 00096 unsigned int wss; //Wifi Signal Strength 00097 }; 00098 00099 struct TEncoders{ 00100 int left; 00101 int right; 00102 int rear; 00103 TEncoders() 00104 { 00105 left = 0; 00106 right = 0; 00107 rear = 0; 00108 } 00109 }encoders; 00110 00111 00112 /** Establish conection with Rovio and log in its system: Important, fill out "options" members *BEFORE* calling this method. 00113 * \exception std::runtime On errors 00114 */ 00115 void initialize(); //string &errormsg_out, string url_out="150.214.109.134", string user_out="admin", string password_out="investigacion"); 00116 00117 /** move send Rovio the command to move in the specified direcction 00118 * \param direction 'f'->forward, 'b'->backward, 'r'->right, 'l'->left 00119 * \return False on error 00120 */ 00121 bool move(char direction, int speed=5 ); 00122 00123 /** rotate send Rovio the command to rotate in the specified direcction 00124 * 'r'->right, 'l'->left 00125 * \return False on error 00126 */ 00127 bool rotate(char direction, int speed=5 ); 00128 00129 /** Head positions 00130 * \return False on error 00131 */ 00132 bool takeHeadUp(); 00133 bool takeHeadMiddle(); 00134 bool takeHeadDown(); 00135 00136 00137 /* Path commands */ 00138 bool pathRecord(); 00139 bool pathRecordAbort(); 00140 bool pathRecordSave(const string &path_name);//Repasar const 00141 bool pathDelete(const string &path_name); 00142 /** Get list of saved paths 00143 */ 00144 bool pathGetList(string &path_list); 00145 bool pathRunForward(); 00146 bool pathRunBackward(); 00147 bool pathRunStop(); 00148 bool pathRunPause(); 00149 bool pathRename(const string &old_name, const string &new_name); 00150 00151 00152 /** goHome(bool dock) drives Rovio in front of charging station if the paremeter dock is set to false, otherwise it also docks 00153 * \return False on error 00154 */ 00155 bool goHome(bool dock, int speed = 5); 00156 00157 /** Loads the rovio camera calibration parameters (of leave the default ones if not found) (See CGenericSensor), then call to "loadConfig_sensorSpecific" 00158 * \exception This method throws an exception with a descriptive message if some critical parameter is missing or has an invalid value. 00159 */ 00160 void loadConfig( 00161 const mrpt::utils::CConfigFileBase &configSource, 00162 const std::string §ion ); 00163 00164 /** This function launchs a thread with the function "thread_video()" which gets frames into a buffer. 00165 * After calling this method, images can be obtained with getNextImageSync() 00166 * \return False on error 00167 * \sa getNextImageSync 00168 */ 00169 bool retrieve_video();//como la protejo para que no se llame dos veces?????????????????????????????????????????????? 00170 00171 /** This function stops and joins the thread launched by "retrieve_video()". 00172 * \return False on error 00173 */ 00174 bool stop_video(); 00175 00176 /** Returns the next frame from Rovio's live video stream, after starting the live streaming with retrieve_video() 00177 * \return False on error 00178 * \sa retrieve_video, captureImageAsync 00179 */ 00180 bool getNextImageSync(CObservationImagePtr& lastImage ); 00181 00182 /** Returns a snapshot from Rovio, if rectified is set true, the returned image is rectified with the parameters of intrinsic_matrix and distortion_matrix. 00183 * This function works asynchronously and does not need to have enabled the live video streaming. 00184 * \return False on error 00185 * \sa captureImageSync 00186 */ 00187 bool captureImageAsync( CImage&out_img, bool recttified);//string pict_name, 00188 00189 bool isVideoStreamming() const; //!< Return true if video is streaming correctly \sa retrieve_video 00190 00191 00192 //Rovio State 00193 /** Returns a TRovioState with internal information of Rovio (State, Navigation Signal Strength, Wifi Signal Strength) 00194 * \return False on error 00195 */ 00196 bool getRovioState(TRovioState &state); 00197 00198 /** Returns a TEncoders with information of Rovio encoders (since last read, it seems Rovio is continuously reading with unknown sample time) 00199 * \return False on error 00200 */ 00201 bool getEncoders(TEncoders &encoders); 00202 00203 /** Returns the Rovio's pose 00204 * \return False on error 00205 */ 00206 bool getPosition(mrpt::math::TPose2D &out_pose); 00207 00208 00209 00210 CRovio(); 00211 virtual ~CRovio(); 00212 00213 }; // End of class 00214 00215 } // End of namespace 00216 00217 } // End of namespace 00218 00219 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |