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 #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 * \ingroup mrpt_hwdrivers_grp 00075 */ 00076 class HWDRIVERS_IMPEXP CActivMediaRobotBase : public CGenericSensor 00077 { 00078 DEFINE_GENERIC_SENSOR(CActivMediaRobotBase) 00079 public: 00080 00081 /** A structure describing the robot */ 00082 struct HWDRIVERS_IMPEXP TRobotDescription 00083 { 00084 TRobotDescription(); //!< Init 00085 size_t nFrontBumpers; //!< Number of front bumpers 00086 size_t nRearBumpers; //!< Number of rear bumpers 00087 size_t nSonars; //!< Number of sonars 00088 }; 00089 00090 00091 /** Connects to the robot */ 00092 void initialize(); 00093 00094 /** Constructor 00095 */ 00096 CActivMediaRobotBase(); 00097 00098 /** Destructor: turns off communications */ 00099 virtual ~CActivMediaRobotBase(); 00100 00101 /** Manually sets the serial port configuration. 00102 * \param portName Examples: Windows: "COM1" , Linux: "/dev/ttyUSB0" 00103 * \param portBaudRate 9600, 115200, etc.. 00104 * \sa loadConfig 00105 */ 00106 void setSerialPortConfig( 00107 const std::string &portName, 00108 int portBaudRate ); 00109 00110 /** Returns the current value of the serial port */ 00111 std::string getSerialPort() const { return m_com_port; } 00112 00113 /** Returns the current value of the serial port baudrate */ 00114 int getSerialPortBaudRate() const { return m_robotBaud; } 00115 00116 00117 /** Collect odometry readings and put them in the "observations" queue: DO NOT call this normally, it's useful only for the application rawloggrabber. 00118 */ 00119 void doProcess(); 00120 00121 /** Change the current robot odometry pose 00122 */ 00123 void changeOdometry(const mrpt::poses::CPose2D &newOdometry); 00124 00125 /** Get the current robot's odometry 00126 * \param out_odom The odometry will be returned here. 00127 * \sa getOdometryFull, getOdometryIncrement 00128 */ 00129 void getOdometry(poses::CPose2D &out_odom); 00130 00131 /** Get the current robot's odometry 00132 * \param out_odom The odometry will be returned here. 00133 * \param out_lin_vel The linear speed, in m/s, positive is forward. 00134 * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise. 00135 * \param out_left_encoder_ticks The current overall count of ticks for the left wheel encoder. 00136 * \param out_right_encoder_ticks The current overall count of ticks for the right wheel encoder. 00137 * \sa getOdometry, getOdometryIncrement 00138 */ 00139 void getOdometryFull( 00140 poses::CPose2D &out_odom, 00141 double &out_lin_vel, 00142 double &out_ang_vel, 00143 int64_t &out_left_encoder_ticks, 00144 int64_t &out_right_encoder_ticks 00145 ); 00146 00147 /** Get the robot's odometry increment since the last call to this method (the first time the increments are always fixed to zero). 00148 * \param out_odom The odometry increment. 00149 * \param out_lin_vel The current linear speed, in m/s, positive is forward (Absolute values, not increments) 00150 * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise (Absolute values, not increments). 00151 * \param out_left_encoder_ticks The increment in ticks for the left wheel encoder. 00152 * \param out_right_encoder_ticks The increment in ticks for the right wheel encoder. 00153 * \sa getOdometry, getOdometryFull 00154 */ 00155 void getOdometryIncrement( 00156 poses::CPose2D &out_incr_odom, 00157 double &out_lin_vel, 00158 double &out_ang_vel, 00159 int64_t &out_incr_left_encoder_ticks, 00160 int64_t &out_incr_right_encoder_ticks 00161 ); 00162 00163 /** Get the readings from the sonars, only if the observations are new. 00164 */ 00165 void getSonarsReadings( bool &thereIsObservation, mrpt::slam::CObservationRange &obs ); 00166 00167 /** Get the robot battery charge */ 00168 void getBatteryCharge( double &out_batery_volts ); 00169 00170 /** Set the robot linear and angular velocities 00171 * \param lin_vel Linear speed, in m/s. 00172 * \param ang_vel Angular speed, in rad/s. 00173 */ 00174 void setVelocities( const double lin_vel, const double ang_vel); 00175 00176 void enableSonars(); //!< Enable sonars 00177 void disableSonars(); //!< Disable sonars 00178 00179 00180 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. 00181 00182 void getRobotInformation(TRobotDescription &info); //!< Get information about the robot and its sensors 00183 00184 /** Enable/disable manual control of the robot with a Joystick */ 00185 void enableJoystickControl(bool enable=true) { m_enableJoyControl = enable; } 00186 00187 /** Get state of manual control with a joystick */ 00188 bool isJoystickControlEnabled() const { return m_enableJoyControl;} 00189 00190 protected: 00191 std::string m_com_port; //!< The serial port name to use for communications (COM1, ttyS1,...) 00192 int m_robotBaud; //!< The bauds for ARIA communications to the robot. 00193 00194 bool m_firstIncreOdometry; //!< Used in getOdometryIncrement 00195 bool m_enableSonars; 00196 00197 void* /*ArRobot*/ m_robot; 00198 void* /*ArSonarDevice*/ m_sonarDev; 00199 void* /*ArSimpleConnector* */ m_simpleConnector; //!< The connection to the robot 00200 00201 unsigned int m_lastTimeSonars; 00202 00203 bool m_enableJoyControl; //!< For use with rawlog-grabber 00204 float m_joy_max_v, m_joy_max_w; 00205 00206 CJoystick m_joystick; //!< The joystick opened at first usage. 00207 00208 mrpt::system::TTimeStamp m_last_do_process; 00209 double m_capture_rate; //!< In Hz, the rate at which sonars & odometry are gathered (default=10Hz) 00210 00211 00212 void disconnectAndDisableMotors(); 00213 void connectAndEnableMotors(); 00214 00215 /** 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) 00216 * See hwdrivers::CActivMediaRobotBase for the possible parameters 00217 * \sa setSerialPortConfig 00218 */ 00219 void loadConfig_sensorSpecific( 00220 const mrpt::utils::CConfigFileBase &configSource, 00221 const std::string &iniSection ); 00222 00223 00224 }; // End of class 00225 00226 } // End of namespace 00227 } // End of namespace 00228 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |