Main MRPT website > C++ reference for MRPT 1.4.0
CActivMediaRobotBase.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CActivMediaRobotBase_H
10 #define CActivMediaRobotBase_H
11 
14 #include <mrpt/poses/CPose2D.h>
17 
18 namespace mrpt
19 {
20  namespace hwdrivers
21  {
22  /** This software driver implements the communications (and some rudimentary control) for ActivMedia robotic bases (Pioneer DX/AT, PeopleBot, etc).
23  * There is implemented access to robot odometry, ticks counts, velocities, battery charge status, and sonar readings, as well as
24  * basic velocity control.
25  *
26  * It is required to check MRPT_BUILD_ARIA in the cmake configuration to enable this class to work properly.
27  *
28  * See also the application "rawlog-grabber" for a ready-to-use application to gather data from the robot base.
29  * Through that "common sensor interface", this object can collect these kinds of observations:
30  * - mrpt::obs::CObservationOdometry : For odometry
31  * - mrpt::obs::CObservationRange : For sonars
32  *
33  * To use this class out of rawlog-grabber, "initialize" must be called to connect to the robot.
34  * Before that, set the serial port with setSerialPortConfig.
35  *
36  *
37  *
38  * Example .ini block for rawlog-grabber (format used in "loadConfig"):
39  *
40  * \code
41  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
42  * -------------------------------------------------------
43  * [supplied_section_name]
44  * robotPort_WIN = COM1
45  * robotPort_LIN = /dev/ttyUSB0
46  * robotBaud = 115200
47  * enableSonars = 0 ; 0:Disabled (default), 1: Enabled
48  * capture_rate = 10.0 ; In Hz, the rate at which sonars & odometry are gathered (default=10Hz)
49  *
50  * joystick_control = 0 ; 0:Disabled (default), 1: Enabled
51  * joystick_max_v = 0.1 ; Max joystick control speed (m/s)
52  * joystick_max_w_degps = 20 ; Max joystick control speed (deg/s)
53  *
54  * \endcode
55  * \ingroup mrpt_hwdrivers_grp
56  */
58  {
60  public:
61 
62  /** A structure describing the robot */
64  {
65  TRobotDescription(); //!< Init
66  size_t nFrontBumpers; //!< Number of front bumpers
67  size_t nRearBumpers; //!< Number of rear bumpers
68  size_t nSonars; //!< Number of sonars
69  };
70 
71 
72  /** Connects to the robot */
73  void initialize();
74 
75  /** Constructor
76  */
78 
79  /** Destructor: turns off communications */
80  virtual ~CActivMediaRobotBase();
81 
82  /** Manually sets the serial port configuration.
83  * \param portName Examples: Windows: "COM1" , Linux: "/dev/ttyUSB0"
84  * \param portBaudRate 9600, 115200, etc..
85  * \sa loadConfig
86  */
87  void setSerialPortConfig(
88  const std::string &portName,
89  int portBaudRate );
90 
91  /** Returns the current value of the serial port */
92  std::string getSerialPort() const { return m_com_port; }
93 
94  /** Returns the current value of the serial port baudrate */
95  int getSerialPortBaudRate() const { return m_robotBaud; }
96 
97 
98  /** Collect odometry readings and put them in the "observations" queue: DO NOT call this normally, it's useful only for the application rawloggrabber.
99  */
100  void doProcess();
101 
102  /** Change the current robot odometry pose
103  */
104  void changeOdometry(const mrpt::poses::CPose2D &newOdometry);
105 
106  /** Get the current robot's odometry
107  * \param out_odom The odometry will be returned here.
108  * \sa getOdometryFull, getOdometryIncrement
109  */
110  void getOdometry(poses::CPose2D &out_odom);
111 
112  /** Get the current robot's odometry
113  * \param out_odom The odometry will be returned here.
114  * \param out_lin_vel The linear speed, in m/s, positive is forward.
115  * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise.
116  * \param out_left_encoder_ticks The current overall count of ticks for the left wheel encoder.
117  * \param out_right_encoder_ticks The current overall count of ticks for the right wheel encoder.
118  * \sa getOdometry, getOdometryIncrement
119  */
120  void getOdometryFull(
121  poses::CPose2D &out_odom,
122  double &out_lin_vel,
123  double &out_ang_vel,
124  int64_t &out_left_encoder_ticks,
125  int64_t &out_right_encoder_ticks
126  );
127 
128  /** Get the robot's odometry increment since the last call to this method (the first time the increments are always fixed to zero).
129  * \param out_odom The odometry increment.
130  * \param out_lin_vel The current linear speed, in m/s, positive is forward (Absolute values, not increments)
131  * \param out_ang_vel The angular speed, in rad/s, positive is anticlockwise (Absolute values, not increments).
132  * \param out_left_encoder_ticks The increment in ticks for the left wheel encoder.
133  * \param out_right_encoder_ticks The increment in ticks for the right wheel encoder.
134  * \sa getOdometry, getOdometryFull
135  */
136  void getOdometryIncrement(
137  poses::CPose2D &out_incr_odom,
138  double &out_lin_vel,
139  double &out_ang_vel,
140  int64_t &out_incr_left_encoder_ticks,
141  int64_t &out_incr_right_encoder_ticks
142  );
143 
144  /** Get the readings from the sonars, only if the observations are new.
145  */
146  void getSonarsReadings( bool &thereIsObservation, mrpt::obs::CObservationRange &obs );
147 
148  /** Get the robot battery charge - normalized to 12V */
149  void getBatteryCharge( double &out_batery_volts );
150  /** Get the robot real battery charge */
151  void getRealBatteryCharge( double &out_batery_volts );
152 
153  /** Set the robot linear and angular velocities
154  * \param lin_vel Linear speed, in m/s.
155  * \param ang_vel Angular speed, in rad/s.
156  */
157  void setVelocities( const double lin_vel, const double ang_vel);
158 
159  void enableSonars(); //!< Enable sonars
160  void disableSonars(); //!< Disable sonars
161 
162 
163  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.
164 
165  void getRobotInformation(TRobotDescription &info); //!< Get information about the robot and its sensors
166 
167  /** Enable/disable manual control of the robot with a Joystick */
168  void enableJoystickControl(bool enable=true) { m_enableJoyControl = enable; }
169 
170  /** Get state of manual control with a joystick */
171  bool isJoystickControlEnabled() const { return m_enableJoyControl;}
172 
173  /** Disable motors but keeps the connection with ARIA*/
174  void DisableMotors();
175 
176  /** Enable motors after a call to DisableMotors()*/
177  void EnableMotors();
178 
179  /** Get the motors state*/
180  bool areMotorsEnabled() const;
181 
182  protected:
183  std::string m_com_port; //!< The serial port name to use for communications (COM1, ttyS1,...)
184  int m_robotBaud; //!< The bauds for ARIA communications to the robot.
185 
186  bool m_firstIncreOdometry; //!< Used in getOdometryIncrement
188 
189 
190  void* /*ArRobot*/ m_robot;
191  void* /*ArSonarDevice*/ m_sonarDev;
192  void* /*ArSimpleConnector* */ m_simpleConnector; //!< The connection to the robot
193 
194  unsigned int m_lastTimeSonars;
195 
196  bool m_enableJoyControl; //!< For use with rawlog-grabber
197  float m_joy_max_v, m_joy_max_w;
198 
199  CJoystick m_joystick; //!< The joystick opened at first usage.
200 
202  double m_capture_rate; //!< In Hz, the rate at which sonars & odometry are gathered (default=10Hz)
203 
204  void disconnectAndDisableMotors();
205  void connectAndEnableMotors();
206 
207  /** See the class documentation at the top for expected parameters */
208  void loadConfig_sensorSpecific(
209  const mrpt::utils::CConfigFileBase &configSource,
210  const std::string &iniSection );
211 
212 
213  }; // End of class
214 
215  } // End of namespace
216 } // End of namespace
217 #endif
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
Declares a class derived from "CObservation" that encapsules a single range measurement, and associated parameters.
int m_robotBaud
The bauds for ARIA communications to the robot.
bool m_firstIncreOdometry
Used in getOdometryIncrement.
void enableJoystickControl(bool enable=true)
Enable/disable manual control of the robot with a Joystick.
std::string getSerialPort() const
Returns the current value of the serial port.
std::string m_com_port
The serial port name to use for communications (COM1, ttyS1,...)
This class allows loading and storing values and vectors of different types from a configuration text...
std::vector< bool > vector_bool
A type for passing a vector of bools.
Definition: types_simple.h:29
bool isJoystickControlEnabled() const
Get state of manual control with a joystick.
CJoystick m_joystick
The joystick opened at first usage.
void * m_simpleConnector
The connection to the robot.
int getSerialPortBaudRate() const
Returns the current value of the serial port baudrate.
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
double m_capture_rate
In Hz, the rate at which sonars & odometry are gathered (default=10Hz)
A class used to store a 2D pose.
Definition: CPose2D.h:36
This software driver implements the communications (and some rudimentary control) for ActivMedia robo...
bool m_enableJoyControl
For use with rawlog-grabber.
#define HWDRIVERS_IMPEXP
Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the ...
Definition: CJoystick.h:25



Page generated by Doxygen 1.8.6 for MRPT 1.4.0 SVN: at dom ago 20 02:31:29 CEST 2017 Hosted on:
SourceForge.net Logo