Main MRPT website > C++ reference for MRPT 1.9.9
CRovio.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-2018, 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 
10 #ifndef CROVIO_H
11 #define CROVIO_H
12 
13 #include <mrpt/img/TCamera.h>
15 
17 
18 #include <thread>
19 
20 namespace mrpt
21 {
22 namespace hwdrivers
23 {
24 /** A class to interface a Rovio robot (manufactured by WowWee).
25  * Supports: Simple motion commands, video streaming.
26  * \ingroup mrpt_hwdrivers_grp
27  */
28 class CRovio
29 {
30  private:
31  std::thread m_videoThread;
36 
38  std::mutex buffer_img_cs;
39 
40  /** This function takes a frame and waits until getLastImage ask for it, and
41  * so on.
42  */
43  void thread_video();
44 
45  bool send_cmd_action(int act, int speed);
46 
47  bool path_management(int act);
48 
49  bool path_management(int act, const std::string& path_name);
50 
51  bool general_command(int act, std::string& response, std::string& errormsg);
52 
53  public:
54  struct TOptions
55  {
59 
60  mrpt::img::TCamera cameraParams; // Mat. cam. preguntar paco
61 
62  TOptions();
63  } options;
64 
65  enum status
66  {
72  };
73 
74  struct TRovioState
75  {
77  unsigned int nss; // Navigation Signal Strength
78  unsigned int wss; // Wifi Signal Strength
79  };
80 
81  struct TEncoders
82  {
83  int left;
84  int right;
85  int rear;
87  {
88  left = 0;
89  right = 0;
90  rear = 0;
91  }
92  } encoders;
93 
94  /** Establish Connection with Rovio and log in its system: Important, fill
95  * out "options" members *BEFORE* calling this method.
96  * \exception std::runtime On errors
97  */
98  void initialize(); // string &errormsg_out, std::string
99  // url_out="150.214.109.134", std::string
100  // user_out="admin", std::string
101  // password_out="investigacion");
102 
103  /** move send Rovio the command to move in the specified direcction
104  * \param direction 'f'->forward, 'b'->backward, 'r'->right, 'l'->left
105  * \return False on error
106  */
107  bool move(char direction, int speed = 5);
108 
109  /** rotate send Rovio the command to rotate in the specified direcction
110  * 'r'->right, 'l'->left
111  * \return False on error
112  */
113  bool rotate(char direction, int speed = 5);
114 
115  /** Head positions
116  * \return False on error
117  */
118  bool takeHeadUp();
119  bool takeHeadMiddle();
120  bool takeHeadDown();
121 
122  /* Path commands */
123  bool pathRecord();
124  bool pathRecordAbort();
125  bool pathRecordSave(const std::string& path_name); // Repasar const
126  bool pathDelete(const std::string& path_name);
127  /** Get list of saved paths
128  */
129  bool pathGetList(std::string& path_list);
130  bool pathRunForward();
131  bool pathRunBackward();
132  bool pathRunStop();
133  bool pathRunPause();
134  bool pathRename(const std::string& old_name, const std::string& new_name);
135 
136  /** goHome(bool dock) drives Rovio in front of charging station if the
137  * paremeter dock is set to false, otherwise it also docks
138  * \return False on error
139  */
140  bool goHome(bool dock, int speed = 5);
141 
142  /** Loads the rovio camera calibration parameters (of leave the default ones
143  * if not found) (See CGenericSensor), then call to
144  * "loadConfig_sensorSpecific"
145  * \exception This method throws an exception with a descriptive message
146  * if some critical parameter is missing or has an invalid value.
147  */
148  void loadConfig(
149  const mrpt::config::CConfigFileBase& configSource,
150  const std::string& section);
151 
152  /** This function launchs a thread with the function "thread_video()" which
153  * gets frames into a buffer.
154  * After calling this method, images can be obtained with
155  * getNextImageSync()
156  * \return False on error
157  * \sa getNextImageSync
158  */
159  bool retrieve_video(); // como la protejo para que no se llame dos
160  // veces??????????????????????????????????????????????
161 
162  /** This function stops and joins the thread launched by "retrieve_video()".
163  * \return False on error
164  */
165  bool stop_video();
166 
167  /** Returns the next frame from Rovio's live video stream, after starting
168  * the live streaming with retrieve_video()
169  * \return False on error
170  * \sa retrieve_video, captureImageAsync
171  */
173 
174  /** Returns a snapshot from Rovio, if rectified is set true, the returned
175  * image is rectified with the parameters of intrinsic_matrix and
176  * distortion_matrix.
177  * This function works asynchronously and does not need to have enabled the
178  * live video streaming.
179  * \return False on error
180  * \sa captureImageSync
181  */
182  bool captureImageAsync(
183  mrpt::img::CImage& out_img, bool recttified); // string pict_name,
184 
185  /** Return true if video is streaming correctly \sa retrieve_video */
186  bool isVideoStreamming() const;
187 
188  // Rovio State
189  /** Returns a TRovioState with internal information of Rovio (State,
190  * Navigation Signal Strength, Wifi Signal Strength)
191  * \return False on error
192  */
193  bool getRovioState(TRovioState& state);
194 
195  /** Returns a TEncoders with information of Rovio encoders (since last read,
196  * it seems Rovio is continuously reading with unknown sample time)
197  * \return False on error
198  */
199  bool getEncoders(TEncoders& encoders);
200 
201  /** Returns the Rovio's pose
202  * \return False on error
203  */
204  bool getPosition(mrpt::math::TPose2D& out_pose);
205 
206  CRovio();
207  virtual ~CRovio();
208 
209 }; // End of class
210 
211 } // End of namespace
212 
213 } // End of namespace
214 
215 #endif
mrpt::hwdrivers::CRovio::path_management
bool path_management(int act)
Definition: CRovio.cpp:81
mrpt::hwdrivers::CRovio::pathRunPause
bool pathRunPause()
Definition: CRovio.cpp:176
mrpt::hwdrivers::CRovio::loadConfig
void loadConfig(const mrpt::config::CConfigFileBase &configSource, const std::string &section)
Loads the rovio camera calibration parameters (of leave the default ones if not found) (See CGenericS...
Definition: CRovio.cpp:201
mrpt::hwdrivers::CRovio::getPosition
bool getPosition(mrpt::math::TPose2D &out_pose)
Returns the Rovio's pose.
Definition: CRovio.cpp:476
mrpt::hwdrivers::CRovio::pathGetList
bool pathGetList(std::string &path_list)
Get list of saved paths.
Definition: CRovio.cpp:167
mrpt::hwdrivers::CRovio::pathRecord
bool pathRecord()
Definition: CRovio.cpp:157
mrpt::hwdrivers::CRovio::pathDelete
bool pathDelete(const std::string &path_name)
Definition: CRovio.cpp:163
mrpt::hwdrivers::CRovio::m_videoThread
std::thread m_videoThread
Definition: CRovio.h:31
mrpt::hwdrivers::CRovio::TRovioState::nss
unsigned int nss
Definition: CRovio.h:77
mrpt::hwdrivers::CRovio::getEncoders
bool getEncoders(TEncoders &encoders)
Returns a TEncoders with information of Rovio encoders (since last read, it seems Rovio is continuous...
Definition: CRovio.cpp:408
mrpt::hwdrivers::CRovio::TEncoders::TEncoders
TEncoders()
Definition: CRovio.h:86
mrpt::hwdrivers::CRovio::getNextImageSync
bool getNextImageSync(mrpt::obs::CObservationImage::Ptr &lastImage)
Returns the next frame from Rovio's live video stream, after starting the live streaming with retriev...
Definition: CRovio.cpp:325
mrpt::hwdrivers::CRovio::encoders
struct mrpt::hwdrivers::CRovio::TEncoders encoders
mrpt::hwdrivers::CRovio::TRovioState::wss
unsigned int wss
Definition: CRovio.h:78
mrpt::hwdrivers::CRovio
A class to interface a Rovio robot (manufactured by WowWee).
Definition: CRovio.h:28
mrpt::hwdrivers::CRovio::TRovioState
Definition: CRovio.h:74
mrpt::hwdrivers::CRovio::m_videothread_initialized_error
bool m_videothread_initialized_error
Definition: CRovio.h:34
mrpt::hwdrivers::CRovio::send_cmd_action
bool send_cmd_action(int act, int speed)
Definition: CRovio.cpp:68
mrpt::hwdrivers::CRovio::~CRovio
virtual ~CRovio()
Definition: CRovio.cpp:514
mrpt::hwdrivers::CRovio::move
bool move(char direction, int speed=5)
move send Rovio the command to move in the specified direcction
Definition: CRovio.cpp:117
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::hwdrivers::CRovio::docking
@ docking
Definition: CRovio.h:69
mrpt::hwdrivers::CRovio::pathRunStop
bool pathRunStop()
Definition: CRovio.cpp:175
mrpt::hwdrivers::CRovio::m_videothread_initialized_done
bool m_videothread_initialized_done
Definition: CRovio.h:33
mrpt::hwdrivers::CRovio::rotate
bool rotate(char direction, int speed=5)
rotate send Rovio the command to rotate in the specified direcction 'r'->right, 'l'->left
Definition: CRovio.cpp:135
mrpt::hwdrivers::CRovio::status
status
Definition: CRovio.h:65
mrpt::hwdrivers::CRovio::m_videothread_finished
bool m_videothread_finished
Definition: CRovio.h:35
TCamera.h
mrpt::hwdrivers::CRovio::captureImageAsync
bool captureImageAsync(mrpt::img::CImage &out_img, bool recttified)
Returns a snapshot from Rovio, if rectified is set true, the returned image is rectified with the par...
Definition: CRovio.cpp:344
mrpt::hwdrivers::CRovio::retrieve_video
bool retrieve_video()
This function launchs a thread with the function "thread_video()" which gets frames into a buffer.
Definition: CRovio.cpp:278
mrpt::hwdrivers::CRovio::TOptions
Definition: CRovio.h:54
mrpt::hwdrivers::CRovio::TEncoders::rear
int rear
Definition: CRovio.h:85
mrpt::hwdrivers::CRovio::TOptions::password
std::string password
Definition: CRovio.h:58
mrpt::hwdrivers::CRovio::isVideoStreamming
bool isVideoStreamming() const
Return true if video is streaming correctly.
Definition: CRovio.cpp:307
mrpt::hwdrivers::CRovio::TOptions::TOptions
TOptions()
Definition: CRovio.cpp:27
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
mrpt::hwdrivers::CRovio::pathRunBackward
bool pathRunBackward()
Definition: CRovio.cpp:174
mrpt::obs::CObservationImage::Ptr
std::shared_ptr< CObservationImage > Ptr
Definition: CObservationImage.h:37
CGenericSensor.h
mrpt::math::TPose2D
Lightweight 2D pose.
Definition: lightweight_geom_data.h:186
mrpt::hwdrivers::CRovio::driving_home
@ driving_home
Definition: CRovio.h:68
mrpt::img::TCamera
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:29
mrpt::hwdrivers::CRovio::pathRecordAbort
bool pathRecordAbort()
Definition: CRovio.cpp:158
mrpt::hwdrivers::CRovio::thread_video
void thread_video()
This function takes a frame and waits until getLastImage ask for it, and so on.
Definition: CRovio.cpp:212
mrpt::hwdrivers::CRovio::m_videothread_must_exit
bool m_videothread_must_exit
Definition: CRovio.h:32
mrpt::hwdrivers::CRovio::takeHeadDown
bool takeHeadDown()
Definition: CRovio.cpp:153
mrpt::hwdrivers::CRovio::initialize
void initialize()
Establish Connection with Rovio and log in its system: Important, fill out "options" members BEFORE c...
Definition: CRovio.cpp:50
mrpt::hwdrivers::CRovio::takeHeadUp
bool takeHeadUp()
Head positions.
Definition: CRovio.cpp:151
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
mrpt::hwdrivers::CRovio::pathRecordSave
bool pathRecordSave(const std::string &path_name)
Definition: CRovio.cpp:159
mrpt::hwdrivers::CRovio::TEncoders::right
int right
Definition: CRovio.h:84
mrpt::hwdrivers::CRovio::idle
@ idle
Definition: CRovio.h:67
mrpt::hwdrivers::CRovio::stop_video
bool stop_video()
This function stops and joins the thread launched by "retrieve_video()".
Definition: CRovio.cpp:312
mrpt::hwdrivers::CRovio::executing_path
@ executing_path
Definition: CRovio.h:70
mrpt::hwdrivers::CRovio::takeHeadMiddle
bool takeHeadMiddle()
Definition: CRovio.cpp:152
mrpt::hwdrivers::CRovio::buffer_img_cs
std::mutex buffer_img_cs
Definition: CRovio.h:38
mrpt::hwdrivers::CRovio::goHome
bool goHome(bool dock, int speed=5)
goHome(bool dock) drives Rovio in front of charging station if the paremeter dock is set to false,...
Definition: CRovio.cpp:190
mrpt::hwdrivers::CRovio::getRovioState
bool getRovioState(TRovioState &state)
Returns a TRovioState with internal information of Rovio (State, Navigation Signal Strength,...
Definition: CRovio.cpp:373
mrpt::hwdrivers::CRovio::pathRename
bool pathRename(const std::string &old_name, const std::string &new_name)
Definition: CRovio.cpp:177
mrpt::hwdrivers::CRovio::buffer_img
mrpt::obs::CObservationImage::Ptr buffer_img
Definition: CRovio.h:37
mrpt::hwdrivers::CRovio::general_command
bool general_command(int act, std::string &response, std::string &errormsg)
Definition: CRovio.cpp:105
mrpt::hwdrivers::CRovio::TOptions::user
std::string user
Definition: CRovio.h:57
mrpt::hwdrivers::CRovio::TEncoders
Definition: CRovio.h:81
mrpt::hwdrivers::CRovio::TEncoders::left
int left
Definition: CRovio.h:83
CObservationImage.h
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::hwdrivers::CRovio::TOptions::IP
std::string IP
Definition: CRovio.h:56
mrpt::hwdrivers::CRovio::TRovioState::state
status state
Definition: CRovio.h:76
mrpt::hwdrivers::CRovio::CRovio
CRovio()
Definition: CRovio.cpp:513
mrpt::hwdrivers::CRovio::recording_path
@ recording_path
Definition: CRovio.h:71
mrpt::hwdrivers::CRovio::pathRunForward
bool pathRunForward()
Definition: CRovio.cpp:173
mrpt::hwdrivers::CRovio::options
struct mrpt::hwdrivers::CRovio::TOptions options
mrpt::hwdrivers::CRovio::TOptions::cameraParams
mrpt::img::TCamera cameraParams
Definition: CRovio.h:60



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST