00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 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 */ 00052 class HWDRIVERS_IMPEXP CRovio 00053 { 00054 private: 00055 mrpt::system::TThreadHandle m_videoThread; 00056 bool m_videothread_must_exit; 00057 bool m_videothread_initialized_done; 00058 bool m_videothread_initialized_error; 00059 bool m_videothread_finished; 00060 00061 mrpt::slam::CObservationImagePtr buffer_img; 00062 mrpt::synch::CCriticalSection buffer_img_cs; 00063 00064 00065 /** This function takes a frame and waits until getLastImage ask for it, and so on. 00066 */ 00067 void thread_video(); 00068 00069 bool send_cmd_action(int act, int speed); 00070 00071 bool path_management(int act); 00072 00073 bool path_management(int act, const string &path_name); 00074 00075 bool general_command(int act, string &response, string &errormsg); 00076 00077 00078 public: 00079 struct TOptions 00080 { 00081 string IP; 00082 string user; 00083 string password; 00084 00085 mrpt::utils::TCamera cameraParams; // Mat. cam. preguntar paco 00086 00087 TOptions(); 00088 } options; 00089 00090 enum status {idle, driving_home, docking, executing_path, recording_path}; 00091 00092 struct TRovioState{ 00093 status state; 00094 unsigned int nss; //Navigation Signal Strength 00095 unsigned int wss; //Wifi Signal Strength 00096 }; 00097 00098 struct TEncoders{ 00099 int left; 00100 int right; 00101 int rear; 00102 TEncoders() 00103 { 00104 left = 0; 00105 right = 0; 00106 rear = 0; 00107 } 00108 }encoders; 00109 00110 00111 /** Establish conection with Rovio and log in its system: Important, fill out "options" members *BEFORE* calling this method. 00112 * \exception std::runtime On errors 00113 */ 00114 void initialize(); //string &errormsg_out, string url_out="150.214.109.134", string user_out="admin", string password_out="investigacion"); 00115 00116 /** move send Rovio the command to move in the specified direcction 00117 * \param direction 'f'->forward, 'b'->backward, 'r'->right, 'l'->left 00118 * \return False on error 00119 */ 00120 bool move(char direction, int speed=5 ); 00121 00122 /** rotate send Rovio the command to rotate in the specified direcction 00123 * 'r'->right, 'l'->left 00124 * \return False on error 00125 */ 00126 bool rotate(char direction, int speed=5 ); 00127 00128 /** Head positions 00129 * \return False on error 00130 */ 00131 bool takeHeadUp(); 00132 bool takeHeadMiddle(); 00133 bool takeHeadDown(); 00134 00135 00136 /* Path commands */ 00137 bool pathRecord(); 00138 bool pathRecordAbort(); 00139 bool pathRecordSave(const string &path_name);//Repasar const 00140 bool pathDelete(const string &path_name); 00141 /** Get list of saved paths 00142 */ 00143 bool pathGetList(string &path_list); 00144 bool pathRunForward(); 00145 bool pathRunBackward(); 00146 bool pathRunStop(); 00147 bool pathRunPause(); 00148 bool pathRename(const string &old_name, const string &new_name); 00149 00150 00151 /** goHome(bool dock) drives Rovio in front of charging station if the paremeter dock is set to false, otherwise it also docks 00152 * \return False on error 00153 */ 00154 bool goHome(bool dock, int speed = 5); 00155 00156 /** Loads the rovio camera calibration parameters (of leave the default ones if not found) (See CGenericSensor), then call to "loadConfig_sensorSpecific" 00157 * \exception This method throws an exception with a descriptive message if some critical parameter is missing or has an invalid value. 00158 */ 00159 void loadConfig( 00160 const mrpt::utils::CConfigFileBase &configSource, 00161 const std::string §ion ); 00162 00163 /** This function launchs a thread with the function "thread_video()" which gets frames into a buffer. 00164 * After calling this method, images can be obtained with getNextImageSync() 00165 * \return False on error 00166 * \sa getNextImageSync 00167 */ 00168 bool retrieve_video();//como la protejo para que no se llame dos veces?????????????????????????????????????????????? 00169 00170 /** This function stops and joins the thread launched by "retrieve_video()". 00171 * \return False on error 00172 */ 00173 bool stop_video(); 00174 00175 /** Returns the next frame from Rovio's live video stream, after starting the live streaming with retrieve_video() 00176 * \return False on error 00177 * \sa retrieve_video, captureImageAsync 00178 */ 00179 bool getNextImageSync(CObservationImagePtr& lastImage ); 00180 00181 /** Returns a snapshot from Rovio, if rectified is set true, the returned image is rectified with the parameters of intrinsic_matrix and distortion_matrix. 00182 * This function works asynchronously and does not need to have enabled the live video streaming. 00183 * \return False on error 00184 * \sa captureImageSync 00185 */ 00186 bool captureImageAsync( CImage&out_img, bool recttified);//string pict_name, 00187 00188 bool isVideoStreamming() const; //!< Return true if video is streaming correctly \sa retrieve_video 00189 00190 00191 //Rovio State 00192 /** Returns a TRovioState with internal information of Rovio (State, Navigation Signal Strength, Wifi Signal Strength) 00193 * \return False on error 00194 */ 00195 bool getRovioState(TRovioState &state); 00196 00197 /** Returns a TEncoders with information of Rovio encoders (since last read, it seems Rovio is continuously reading with unknown sample time) 00198 * \return False on error 00199 */ 00200 bool getEncoders(TEncoders &encoders); 00201 00202 /** Returns the Rovio's pose 00203 * \return False on error 00204 */ 00205 bool getPosition(mrpt::math::TPose2D &out_pose); 00206 00207 00208 00209 CRovio(); 00210 virtual ~CRovio(); 00211 00212 }; // End of class 00213 00214 } // End of namespace 00215 00216 } // End of namespace 00217 00218 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011 |