Main MRPT website > C++ reference
MRPT logo
CActivMediaRobotBase.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CActivMediaRobotBase_H
29 #define CActivMediaRobotBase_H
30 
33 #include <mrpt/poses/CPose2D.h>
36 
37 namespace mrpt
38 {
39  namespace hwdrivers
40  {
41  /** This software driver implements the communications (and some rudimentary control) for ActivMedia robotic bases (Pioneer DX/AT, PeopleBot, etc).
42  * There is implemented access to robot odometry, ticks counts, velocities, battery charge status, and sonar readings, as well as
43  * basic velocity control.
44  *
45  * It is required to check MRPT_BUILD_ARIA in the cmake configuration to enable this class to work properly.
46  *
47  * See also the application "rawlog-grabber" for a ready-to-use application to gather data from the robot base.
48  * Through that "common sensor interface", this object can collect these kinds of observations:
49  * - mrpt::slam::CObservationOdometry : For odometry
50  * - mrpt::slam::CObservationRange : For sonars
51  *
52  * To use this class out of rawlog-grabber, "initialize" must be called to connect to the robot.
53  * Before that, set the serial port with setSerialPortConfig.
54  *
55  *
56  *
57  * Example .ini block for rawlog-grabber (format used in "loadConfig"):
58  *
59  * \code
60  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
61  * -------------------------------------------------------
62  * [supplied_section_name]
63  * robotPort_WIN = COM1
64  * robotPort_LIN = /dev/ttyUSB0
65  * robotBaud = 115200
66  * enableSonars = 0 ; 0:Disabled (default), 1: Enabled
67  * capture_rate = 10.0 ; In Hz, the rate at which sonars & odometry are gathered (default=10Hz)
68  *
69  * joystick_control = 0 ; 0:Disabled (default), 1: Enabled
70  * joystick_max_v = 0.1 ; Max joystick control speed (m/s)
71  * joystick_max_w_degps = 20 ; Max joystick control speed (deg/s)
72  *
73  * \endcode
74  * \ingroup mrpt_hwdrivers_grp
75  */
77  {
79  public:
80 
81  /** A structure describing the robot */
83  {
84  TRobotDescription(); //!< Init
85  size_t nFrontBumpers; //!< Number of front bumpers
86  size_t nRearBumpers; //!< Number of rear bumpers
87  size_t nSonars; //!< Number of sonars
88  };
89 
90 
91  /** Connects to the robot */
92  void initialize();
93 
94  /** Constructor
95  */
97 
98  /** Destructor: turns off communications */
99  virtual ~CActivMediaRobotBase();
100 
101  /** Manually sets the serial port configuration.
102  * \param portName Examples: Windows: "COM1" , Linux: "/dev/ttyUSB0"
103  * \param portBaudRate 9600, 115200, etc..
104  * \sa loadConfig
105  */
106  void setSerialPortConfig(
107  const std::string &portName,
108  int portBaudRate );
109 
110  /** Returns the current value of the serial port */
111  std::string getSerialPort() const { return m_com_port; }
112 
113  /** Returns the current value of the serial port baudrate */
114  int getSerialPortBaudRate() const { return m_robotBaud; }
115 
116 
117  /** Collect odometry readings and put them in the "observations" queue: DO NOT call this normally, it's useful only for the application rawloggrabber.
118  */
119  void doProcess();
120 
121  /** Change the current robot odometry pose
122  */
123  void changeOdometry(const mrpt::poses::CPose2D &newOdometry);
124 
125  /** Get the current robot's odometry
126  * \param out_odom The odometry will be returned here.
127  * \sa getOdometryFull, getOdometryIncrement
128  */
129  void getOdometry(poses::CPose2D &out_odom);
130 
131  /** Get the current robot's odometry
132  * \param out_odom The odometry will be returned here.
133  * \param out_lin_vel The linear speed, in m/s, positive is forward.
134  * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise.
135  * \param out_left_encoder_ticks The current overall count of ticks for the left wheel encoder.
136  * \param out_right_encoder_ticks The current overall count of ticks for the right wheel encoder.
137  * \sa getOdometry, getOdometryIncrement
138  */
139  void getOdometryFull(
140  poses::CPose2D &out_odom,
141  double &out_lin_vel,
142  double &out_ang_vel,
143  int64_t &out_left_encoder_ticks,
144  int64_t &out_right_encoder_ticks
145  );
146 
147  /** Get the robot's odometry increment since the last call to this method (the first time the increments are always fixed to zero).
148  * \param out_odom The odometry increment.
149  * \param out_lin_vel The current linear speed, in m/s, positive is forward (Absolute values, not increments)
150  * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise (Absolute values, not increments).
151  * \param out_left_encoder_ticks The increment in ticks for the left wheel encoder.
152  * \param out_right_encoder_ticks The increment in ticks for the right wheel encoder.
153  * \sa getOdometry, getOdometryFull
154  */
155  void getOdometryIncrement(
156  poses::CPose2D &out_incr_odom,
157  double &out_lin_vel,
158  double &out_ang_vel,
159  int64_t &out_incr_left_encoder_ticks,
160  int64_t &out_incr_right_encoder_ticks
161  );
162 
163  /** Get the readings from the sonars, only if the observations are new.
164  */
165  void getSonarsReadings( bool &thereIsObservation, mrpt::slam::CObservationRange &obs );
166 
167  /** Get the robot battery charge */
168  void getBatteryCharge( double &out_batery_volts );
169 
170  /** Set the robot linear and angular velocities
171  * \param lin_vel Linear speed, in m/s.
172  * \param ang_vel Angular speed, in rad/s.
173  */
174  void setVelocities( const double lin_vel, const double ang_vel);
175 
176  void enableSonars(); //!< Enable sonars
177  void disableSonars(); //!< Disable sonars
178 
179 
180  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.
181 
182  void getRobotInformation(TRobotDescription &info); //!< Get information about the robot and its sensors
183 
184  /** Enable/disable manual control of the robot with a Joystick */
185  void enableJoystickControl(bool enable=true) { m_enableJoyControl = enable; }
186 
187  /** Get state of manual control with a joystick */
188  bool isJoystickControlEnabled() const { return m_enableJoyControl;}
189 
190  protected:
191  std::string m_com_port; //!< The serial port name to use for communications (COM1, ttyS1,...)
192  int m_robotBaud; //!< The bauds for ARIA communications to the robot.
193 
194  bool m_firstIncreOdometry; //!< Used in getOdometryIncrement
196 
197  void* /*ArRobot*/ m_robot;
198  void* /*ArSonarDevice*/ m_sonarDev;
199  void* /*ArSimpleConnector* */ m_simpleConnector; //!< The connection to the robot
200 
201  unsigned int m_lastTimeSonars;
202 
203  bool m_enableJoyControl; //!< For use with rawlog-grabber
204  float m_joy_max_v, m_joy_max_w;
205 
206  CJoystick m_joystick; //!< The joystick opened at first usage.
207 
209  double m_capture_rate; //!< In Hz, the rate at which sonars & odometry are gathered (default=10Hz)
210 
211 
212  void disconnectAndDisableMotors();
213  void connectAndEnableMotors();
214 
215  /** 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)
216  * See hwdrivers::CActivMediaRobotBase for the possible parameters
217  * \sa setSerialPortConfig
218  */
219  void loadConfig_sensorSpecific(
220  const mrpt::utils::CConfigFileBase &configSource,
221  const std::string &iniSection );
222 
223 
224  }; // End of class
225 
226  } // End of namespace
227 } // End of namespace
228 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013