26 CRovio::TOptions::TOptions()
27 : IP(
"150.214.109.134"), user(
"admin"), password(
"investigacion")
30 double cam_params[] = {1650.740234375,
41 0.12792350351810455, -0.4786585867404937, 0.011172077618539333,
42 -0.0037264013662934303);
52 string response, errormsg;
57 if (!response.empty())
58 cout <<
"[CRovio::Initialize] Response:\n" << response << endl;
60 if (!errormsg.empty())
69 string response, errormsg;
71 "http://%s/rev.cgi?Cmd=nav&action=18&drive=%i&speed=%i",
74 return errormsg.empty();
82 string response, errormsg;
87 return errormsg.empty();
92 string response, errormsg;
95 "http://%s/rev.cgi?Cmd=nav&action=%i&name=%s",
options.
IP.c_str(), act,
98 return errormsg.empty();
108 format(
"http://%s/rev.cgi?Cmd=nav&action=%i",
options.
IP.c_str(), act);
110 return errormsg.empty();
129 cout <<
"Error in parameter of move()";
143 cout <<
"Error in parameter of rotate()";
170 return error.empty();
178 string response, errormsg;
180 "http://%s/rev.cgi?Cmd=nav&action=11&name=%s&newname=%s",
181 options.
IP.c_str(), current_name.c_str(), new_name.c_str());
183 return errormsg.empty();
220 const bool open_ok = in_video.
openURL(
221 video_url,
false ,
false );
228 std::cerr <<
"[CRovio] Error opening video stream: " << video_url
236 mrpt::make_aligned_shared<CObservationImage>();
252 cout <<
"[CRovio::thread_video] Warning: the program doesn't " 253 "receive any image\n";
255 std::this_thread::sleep_for(10ms);
262 catch (std::exception& e)
266 cout <<
"Error in thread_video thread";
267 cerr << e.what() << endl;
273 cout <<
"Error in thread_video thread";
291 std::this_thread::sleep_for(10ms);
313 bool was_already_stop =
true;
318 was_already_stop =
false;
321 return !was_already_stop;
362 catch (std::exception& e)
364 cerr << e.what() << endl;
375 size_t x_pos, lenght;
376 string x_value, response, errormsg;
382 x_pos = response.find(
"x=");
383 x_value = response.substr((x_pos + 2), 8);
384 lenght = x_value.find(
'|');
385 x_value = x_value.substr(0, lenght);
386 char* x_char =
new char[lenght];
387 strcpy(x_char, x_value.c_str());
388 pose.
x = atof(x_char);
394 return error.empty();
402 char* result = strpbrk(sLong,
"-0123456789ABCDEF");
404 return strtol(result, &stop, 16);
410 string resp,
error, field;
416 int* a_enc =
new int[11];
422 size_t pos = (resp.find(
"responses =") + 12);
423 for (
int i = 0; i <= 11; i++)
425 if ((i == 3) || (i == 5) || (i == 7))
430 field = resp.substr(pos,
length);
434 char* cstr =
new char[field.size() + 1];
435 strcpy(cstr, field.c_str());
438 if ((i == 2) || (i == 4) ||
440 l_value = ((l_value >> 1) & 0x1);
447 this->encoders.
left += a_enc[3];
451 this->encoders.
left -= a_enc[3];
453 this->encoders.
left += a_enc[5];
455 this->encoders.
left -= a_enc[5];
457 this->encoders.
left += a_enc[7];
459 this->encoders.
left -= a_enc[7];
465 cout <<
"\n---------------------------------------------------" << endl;
466 cout <<
"ERROR->" <<
error << endl;
477 size_t x_pos, y_pos, theta_pos, lenght;
478 string x_value, y_value, theta_value, response, errormsg;
483 x_pos = response.find(
"x=");
484 x_value = response.substr((x_pos + 2), 8);
485 lenght = x_value.find(
'|');
486 x_value = x_value.substr(0, lenght);
487 char* x_char =
new char[lenght];
488 strcpy(x_char, x_value.c_str());
489 pose.
x = atof(x_char);
492 y_pos = response.find(
"y=");
493 y_value = response.substr((y_pos + 2), 8);
494 lenght = y_value.find(
'|');
495 y_value = y_value.substr(0, lenght);
496 char* y_char =
new char[lenght];
497 strcpy(y_char, y_value.c_str());
498 pose.
y = atof(y_char);
501 theta_pos = response.find(
"theta=");
502 theta_value = response.substr((theta_pos + 6), 8);
503 lenght = theta_value.find(
'|');
504 theta_value = theta_value.substr(0, lenght);
505 char* theta_char =
new char[lenght];
506 strcpy(theta_char, theta_value.c_str());
507 pose.
phi = atof(theta_char);
509 return errormsg.empty();
std::thread m_videoThread
bool getNextImageSync(mrpt::obs::CObservationImage::Ptr &lastImage)
Returns the next frame from Rovio's live video stream, after starting the live streaming with retriev...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::vector< uint8_t > vector_byte
bool getEncoders(TEncoders &encoders)
Returns a TEncoders with information of Rovio encoders (since last read, it seems Rovio is continuous...
bool send_cmd_action(int act, int speed)
bool path_management(int act)
A class for storing images as grayscale or RGB bitmaps.
void rectifyImageInPlace(const mrpt::utils::TCamera &cameraParams)
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coeffici...
bool rotate(char direction, int speed=5)
rotate send Rovio the command to rotate in the specified direcction 'r'->right, 'l'->left ...
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
bool pathDelete(const std::string &path_name)
bool m_videothread_initialized_error
bool m_videothread_initialized_done
ERRORCODE_HTTP http_get(const string &url, vector_byte &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=nullptr, mrpt::utils::TParameters< string > *extra_headers=nullptr, mrpt::utils::TParameters< string > *out_headers=nullptr, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
Contains classes for various device interfaces.
bool getPosition(mrpt::math::TPose2D &out_pose)
Returns the Rovio's pose.
bool pathGetList(std::string &path_list)
Get list of saved paths.
bool m_videothread_finished
This class allows loading and storing values and vectors of different types from a configuration text...
bool captureImageAsync(mrpt::utils::CImage &out_img, bool recttified)
Returns a snapshot from Rovio, if rectified is set true, the returned image is rectified with the par...
bool move(char direction, int speed=5)
move send Rovio the command to move in the specified direcction
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This CStream derived class allow using a memory buffer as a CStream.
mrpt::utils::TCamera cameraParams
void initialize()
Establish Connection with Rovio and log in its system: Important, fill out "options" members BEFORE c...
This namespace contains representation of robot actions and observations.
void thread_video()
This function takes a frame and waits until getLastImage ask for it, and so on.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool isVideoStreamming() const
Return true if video is streaming correctly.
bool retrieve_video()
This function launchs a thread with the function "thread_video()" which gets frames into a buffer...
GLsizei const GLchar ** string
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
long convertToLong(char *sLong)
void loadFromArray(const T *vals)
struct mrpt::hwdrivers::CRovio::TEncoders encoders
bool stop_video()
This function stops and joins the thread launched by "retrieve_video()".
bool getRovioState(TRovioState &state)
Returns a TRovioState with internal information of Rovio (State, Navigation Signal Strength...
bool m_videothread_must_exit
std::shared_ptr< CObservationImage > Ptr
GLuint GLsizei GLsizei * length
bool takeHeadUp()
Head positions.
bool pathRecordSave(const std::string &path_name)
A set of useful routines for networking.
void setDistortionParamsFromValues(double k1, double k2, double p1, double p2, double k3=0)
Set the vector of distortion params of the camera from the individual values of the distortion coeffi...
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...
struct mrpt::hwdrivers::CRovio::TOptions options
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
double phi
Orientation (rads)
bool general_command(int act, std::string &response, std::string &errormsg)
void loadFromConfigFile(const std::string §ion, const mrpt::utils::CConfigFileBase &cfg)
Load all the params from a config source, in the format used in saveToConfigFile(), that is:
bool pathRename(const std::string &old_name, const std::string &new_name)
mrpt::obs::CObservationImage::Ptr buffer_img
void loadConfig(const mrpt::utils::CConfigFileBase &configSource, const std::string §ion)
Loads the rovio camera calibration parameters (of leave the default ones if not found) (See CGenericS...
void loadFromStreamAsJPEG(CStream &in)
Reads the image from a binary stream containing a binary jpeg file.