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



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020