Main MRPT website > C++ reference
MRPT logo

CActivMediaRobotBase.h

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



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011