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
mrpt::hwdrivers::CRovio::path_management
bool path_management(int act)
Definition: CRovio.cpp:82
mrpt::hwdrivers::CRovio::pathRunPause
bool pathRunPause()
Definition: CRovio.cpp:177
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:202
mrpt::hwdrivers::CRovio::getPosition
bool getPosition(mrpt::math::TPose2D &out_pose)
Returns the Rovio's pose.
Definition: CRovio.cpp:471
mrpt::hwdrivers::CRovio::pathGetList
bool pathGetList(std::string &path_list)
Get list of saved paths.
Definition: CRovio.cpp:168
mrpt::hwdrivers::CRovio::pathRecord
bool pathRecord()
Definition: CRovio.cpp:158
mrpt::hwdrivers::CRovio::pathDelete
bool pathDelete(const std::string &path_name)
Definition: CRovio.cpp:164
mrpt::hwdrivers::CRovio::m_videoThread
std::thread m_videoThread
Definition: CRovio.h:28
mrpt::hwdrivers::CRovio::TRovioState::nss
unsigned int nss
Definition: CRovio.h:74
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:403
mrpt::hwdrivers::CRovio::TEncoders::TEncoders
TEncoders()
Definition: CRovio.h:83
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:75
mrpt::hwdrivers::CRovio
A class to interface a Rovio robot (manufactured by WowWee).
Definition: CRovio.h:25
mrpt::hwdrivers::CRovio::TRovioState
Definition: CRovio.h:71
mrpt::obs::CObservationImage::Ptr
std::shared_ptr< mrpt::obs ::CObservationImage > Ptr
Definition: CObservationImage.h:34
mrpt::hwdrivers::CRovio::m_videothread_initialized_error
bool m_videothread_initialized_error
Definition: CRovio.h:31
mrpt::hwdrivers::CRovio::send_cmd_action
bool send_cmd_action(int act, int speed)
Definition: CRovio.cpp:69
mrpt::hwdrivers::CRovio::~CRovio
virtual ~CRovio()
Definition: CRovio.cpp:509
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:19
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:118
mrpt::hwdrivers::CRovio::docking
@ docking
Definition: CRovio.h:66
mrpt::hwdrivers::CRovio::pathRunStop
bool pathRunStop()
Definition: CRovio.cpp:176
mrpt::hwdrivers::CRovio::m_videothread_initialized_done
bool m_videothread_initialized_done
Definition: CRovio.h:30
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:136
mrpt::hwdrivers::CRovio::status
status
Definition: CRovio.h:62
mrpt::hwdrivers::CRovio::m_videothread_finished
bool m_videothread_finished
Definition: CRovio.h:32
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:51
mrpt::hwdrivers::CRovio::TEncoders::rear
int rear
Definition: CRovio.h:82
mrpt::hwdrivers::CRovio::TOptions::password
std::string password
Definition: CRovio.h:55
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:28
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:175
CGenericSensor.h
mrpt::math::TPose2D
Lightweight 2D pose.
Definition: TPose2D.h:22
mrpt::hwdrivers::CRovio::driving_home
@ driving_home
Definition: CRovio.h:65
mrpt::img::TCamera
Parameters for the Brown-Conrady camera lens distortion model.
Definition: TCamera.h:26
mrpt::hwdrivers::CRovio::pathRecordAbort
bool pathRecordAbort()
Definition: CRovio.cpp:159
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:213
mrpt::hwdrivers::CRovio::m_videothread_must_exit
bool m_videothread_must_exit
Definition: CRovio.h:29
mrpt::hwdrivers::CRovio::takeHeadDown
bool takeHeadDown()
Definition: CRovio.cpp:154
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:51
mrpt::hwdrivers::CRovio::takeHeadUp
bool takeHeadUp()
Head positions.
Definition: CRovio.cpp:152
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
mrpt::hwdrivers::CRovio::pathRecordSave
bool pathRecordSave(const std::string &path_name)
Definition: CRovio.cpp:160
mrpt::hwdrivers::CRovio::TEncoders::right
int right
Definition: CRovio.h:81
mrpt::hwdrivers::CRovio::idle
@ idle
Definition: CRovio.h:64
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:67
mrpt::hwdrivers::CRovio::takeHeadMiddle
bool takeHeadMiddle()
Definition: CRovio.cpp:153
mrpt::hwdrivers::CRovio::buffer_img_cs
std::mutex buffer_img_cs
Definition: CRovio.h:35
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:191
mrpt::hwdrivers::CRovio::getRovioState
bool getRovioState(TRovioState &state)
Returns a TRovioState with internal information of Rovio (State, Navigation Signal Strength,...
Definition: CRovio.cpp:369
mrpt::hwdrivers::CRovio::pathRename
bool pathRename(const std::string &old_name, const std::string &new_name)
Definition: CRovio.cpp:178
mrpt::hwdrivers::CRovio::buffer_img
mrpt::obs::CObservationImage::Ptr buffer_img
Definition: CRovio.h:34
mrpt::hwdrivers::CRovio::general_command
bool general_command(int act, std::string &response, std::string &errormsg)
Definition: CRovio.cpp:106
mrpt::hwdrivers::CRovio::TOptions::user
std::string user
Definition: CRovio.h:54
mrpt::hwdrivers::CRovio::TEncoders
Definition: CRovio.h:78
mrpt::hwdrivers::CRovio::TEncoders::left
int left
Definition: CRovio.h:80
CObservationImage.h
mrpt::hwdrivers::CRovio::TOptions::IP
std::string IP
Definition: CRovio.h:53
mrpt::hwdrivers::CRovio::TRovioState::state
status state
Definition: CRovio.h:73
mrpt::hwdrivers::CRovio::CRovio
CRovio()
mrpt::hwdrivers::CRovio::recording_path
@ recording_path
Definition: CRovio.h:68
mrpt::hwdrivers::CRovio::pathRunForward
bool pathRunForward()
Definition: CRovio.cpp:174
mrpt::hwdrivers::CRovio::options
struct mrpt::hwdrivers::CRovio::TOptions options
mrpt::hwdrivers::CRovio::TOptions::cameraParams
mrpt::img::TCamera cameraParams
Definition: CRovio.h:57



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020