00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Perception and Robotics | 00009 | research group, 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 #ifndef CActivMediaRobotBase_H 00029 #define CActivMediaRobotBase_H 00030 00031 #include <mrpt/hwdrivers/CGenericSensor.h> 00032 #include <mrpt/hwdrivers/link_pragmas.h> 00033 #include <mrpt/poses/CPose2D.h> 00034 #include <mrpt/slam/CObservationRange.h> 00035 #include <mrpt/hwdrivers/CJoystick.h> 00036 00037 namespace mrpt 00038 { 00039 namespace hwdrivers 00040 { 00041 /** This software driver implements the communications (and some rudimentary control) for ActivMedia robotic bases (Pioneer DX/AT, PeopleBot, etc). 00042 * There is implemented access to robot odometry, ticks counts, velocities, battery charge status, and sonar readings, as well as 00043 * basic velocity control. 00044 * 00045 * It is required to check MRPT_BUILD_ARIA in the cmake configuration to enable this class to work properly. 00046 * 00047 * See also the application "rawlog-grabber" for a ready-to-use application to gather data from the robot base. 00048 * Through that "common sensor interface", this object can collect these kinds of observations: 00049 * - mrpt::slam::CObservationOdometry : For odometry 00050 * - mrpt::slam::CObservationRange : For sonars 00051 * 00052 * To use this class out of rawlog-grabber, "initialize" must be called to connect to the robot. 00053 * Before that, set the serial port with setSerialPortConfig. 00054 * 00055 * 00056 * 00057 * Example .ini block for rawlog-grabber (format used in "loadConfig"): 00058 * 00059 * \code 00060 * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS: 00061 * ------------------------------------------------------- 00062 * [supplied_section_name] 00063 * robotPort_WIN = COM1 00064 * robotPort_LIN = /dev/ttyUSB0 00065 * robotBaud = 115200 00066 * enableSonars = 0 ; 0:Disabled (default), 1: Enabled 00067 * capture_rate = 10.0 ; In Hz, the rate at which sonars & odometry are gathered (default=10Hz) 00068 * 00069 * joystick_control = 0 ; 0:Disabled (default), 1: Enabled 00070 * joystick_max_v = 0.1 ; Max joystick control speed (m/s) 00071 * joystick_max_w_degps = 20 ; Max joystick control speed (deg/s) 00072 * 00073 * \endcode 00074 */ 00075 class HWDLLIMPEXP CActivMediaRobotBase : public CGenericSensor 00076 { 00077 DEFINE_GENERIC_SENSOR(CActivMediaRobotBase) 00078 public: 00079 00080 /** A structure describing the robot */ 00081 struct HWDLLIMPEXP TRobotDescription 00082 { 00083 TRobotDescription(); //!< Init 00084 size_t nFrontBumpers; //!< Number of front bumpers 00085 size_t nRearBumpers; //!< Number of rear bumpers 00086 size_t nSonars; //!< Number of sonars 00087 }; 00088 00089 00090 /** Connects to the robot */ 00091 void initialize(); 00092 00093 /** Constructor 00094 */ 00095 CActivMediaRobotBase(); 00096 00097 /** Destructor: turns off communications */ 00098 virtual ~CActivMediaRobotBase(); 00099 00100 /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes) 00101 * See hwdrivers::CActivMediaRobotBase for the possible parameters 00102 * \sa setSerialPortConfig 00103 */ 00104 void loadConfig( 00105 const mrpt::utils::CConfigFileBase &configSource, 00106 const std::string &iniSection ); 00107 00108 /** Manually sets the serial port configuration. 00109 * \param portName Examples: Windows: "COM1" , Linux: "/dev/ttyUSB0" 00110 * \param portBaudRate 9600, 115200, etc.. 00111 * \sa loadConfig 00112 */ 00113 void setSerialPortConfig( 00114 const std::string &portName, 00115 int portBaudRate ); 00116 00117 /** Returns the current value of the serial port */ 00118 std::string getSerialPort() const { return m_com_port; } 00119 00120 /** Returns the current value of the serial port baudrate */ 00121 int getSerialPortBaudRate() const { return m_robotBaud; } 00122 00123 00124 /** Collect odometry readings and put them in the "observations" queue: DO NOT call this normally, it's useful only for the application rawloggrabber. 00125 */ 00126 void doProcess(); 00127 00128 /** Change the current robot odometry pose 00129 */ 00130 void changeOdometry(const mrpt::poses::CPose2D &newOdometry); 00131 00132 /** Get the current robot's odometry 00133 * \param out_odom The odometry will be returned here. 00134 * \sa getOdometryFull, getOdometryIncrement 00135 */ 00136 void getOdometry(poses::CPose2D &out_odom); 00137 00138 /** Get the current robot's odometry 00139 * \param out_odom The odometry will be returned here. 00140 * \param out_lin_vel The linear speed, in m/s, positive is forward. 00141 * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise. 00142 * \param out_left_encoder_ticks The current overall count of ticks for the left wheel encoder. 00143 * \param out_right_encoder_ticks The current overall count of ticks for the right wheel encoder. 00144 * \sa getOdometry, getOdometryIncrement 00145 */ 00146 void getOdometryFull( 00147 poses::CPose2D &out_odom, 00148 double &out_lin_vel, 00149 double &out_ang_vel, 00150 int64_t &out_left_encoder_ticks, 00151 int64_t &out_right_encoder_ticks 00152 ); 00153 00154 /** Get the robot's odometry increment since the last call to this method (the first time the increments are always fixed to zero). 00155 * \param out_odom The odometry increment. 00156 * \param out_lin_vel The current linear speed, in m/s, positive is forward (Absolute values, not increments) 00157 * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise (Absolute values, not increments). 00158 * \param out_left_encoder_ticks The increment in ticks for the left wheel encoder. 00159 * \param out_right_encoder_ticks The increment in ticks for the right wheel encoder. 00160 * \sa getOdometry, getOdometryFull 00161 */ 00162 void getOdometryIncrement( 00163 poses::CPose2D &out_incr_odom, 00164 double &out_lin_vel, 00165 double &out_ang_vel, 00166 int64_t &out_incr_left_encoder_ticks, 00167 int64_t &out_incr_right_encoder_ticks 00168 ); 00169 00170 /** Get the readings from the sonars, only if the observations are new. 00171 */ 00172 void getSonarsReadings( bool &thereIsObservation, mrpt::slam::CObservationRange &obs ); 00173 00174 /** Get the robot battery charge */ 00175 void getBatteryCharge( double &out_batery_volts ); 00176 00177 /** Set the robot linear and angular velocities 00178 * \param lin_vel Linear speed, in m/s. 00179 * \param ang_vel Angular speed, in rad/s. 00180 */ 00181 void setVelocities( const double lin_vel, const double ang_vel); 00182 00183 void enableSonars(); //!< Enable sonars 00184 void disableSonars(); //!< Disable sonars 00185 00186 00187 void getBumpers(vector_bool &bumper_state); //!< Get state of bumpers: at output, the vector will be resized to the number of bumpers, and elements with "true" means bumper is pressed. 00188 00189 void getRobotInformation(TRobotDescription &info); //!< Get information about the robot and its sensors 00190 00191 protected: 00192 std::string m_com_port; //!< The serial port name to use for communications (COM1, ttyS1,...) 00193 int m_robotBaud; //!< The bauds for ARIA communications to the robot. 00194 00195 bool m_firstIncreOdometry; //!< Used in getOdometryIncrement 00196 bool m_enableSonars; 00197 00198 void* /*ArRobot*/ m_robot; 00199 void* /*ArSonarDevice*/ m_sonarDev; 00200 void* /*ArSimpleConnector* */ m_simpleConnector; //!< The connection to the robot 00201 00202 unsigned int m_lastTimeSonars; 00203 00204 bool m_enableJoyControl; //!< For use with rawlog-grabber 00205 float m_joy_max_v, m_joy_max_w; 00206 00207 CJoystick m_joystick; //!< The joystick opened at first usage. 00208 00209 mrpt::system::TTimeStamp m_last_do_process; 00210 double m_capture_rate; //!< In Hz, the rate at which sonars & odometry are gathered (default=10Hz) 00211 00212 00213 void disconnectAndDisableMotors(); 00214 void connectAndEnableMotors(); 00215 00216 00217 }; // End of class 00218 00219 } // End of namespace 00220 } // End of namespace 00221 #endif
Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 22:58:25 EDT 2009 |