27 CRovio::TOptions::TOptions()
28 : IP(
"150.214.109.134"), user(
"admin"), password(
"investigacion")
31 double cam_params[] = {1650.740234375,
42 0.12792350351810455, -0.4786585867404937, 0.011172077618539333,
43 -0.0037264013662934303);
53 string response, errormsg;
58 if (!response.empty())
59 cout <<
"[CRovio::Initialize] Response:\n" << response << endl;
61 if (!errormsg.empty())
70 string response, errormsg;
72 "http://%s/rev.cgi?Cmd=nav&action=18&drive=%i&speed=%i",
75 return errormsg.empty();
83 string response, errormsg;
88 return errormsg.empty();
93 string response, errormsg;
96 "http://%s/rev.cgi?Cmd=nav&action=%i&name=%s",
options.
IP.c_str(), act,
99 return errormsg.empty();
109 format(
"http://%s/rev.cgi?Cmd=nav&action=%i",
options.
IP.c_str(), act);
111 return errormsg.empty();
130 cout <<
"Error in parameter of move()";
144 cout <<
"Error in parameter of rotate()";
171 return error.empty();
179 string response, errormsg;
181 "http://%s/rev.cgi?Cmd=nav&action=11&name=%s&newname=%s",
182 options.
IP.c_str(), current_name.c_str(), new_name.c_str());
184 return errormsg.empty();
221 const bool open_ok = in_video.
openURL(
222 video_url,
false ,
false );
229 std::cerr <<
"[CRovio] Error opening video stream: " << video_url
237 mrpt::make_aligned_shared<CObservationImage>();
253 cout <<
"[CRovio::thread_video] Warning: the program doesn't " 254 "receive any image\n";
256 std::this_thread::sleep_for(10ms);
263 catch (std::exception& e)
267 cout <<
"Error in thread_video thread";
268 cerr << e.what() << endl;
274 cout <<
"Error in thread_video thread";
292 std::this_thread::sleep_for(10ms);
314 bool was_already_stop =
true;
319 was_already_stop =
false;
322 return !was_already_stop;
348 std::vector<uint8_t> resp;
363 catch (std::exception& e)
365 cerr << e.what() << endl;
376 size_t x_pos, lenght;
377 string x_value, response, errormsg;
383 x_pos = response.find(
"x=");
384 x_value = response.substr((x_pos + 2), 8);
385 lenght = x_value.find(
'|');
386 x_value = x_value.substr(0, lenght);
387 char* x_char =
new char[lenght];
388 strcpy(x_char, x_value.c_str());
389 pose.
x = atof(x_char);
395 return error.empty();
403 char* result = strpbrk(sLong,
"-0123456789ABCDEF");
405 return strtol(result, &stop, 16);
411 string resp,
error, field;
417 int* a_enc =
new int[11];
423 size_t pos = (resp.find(
"responses =") + 12);
424 for (
int i = 0; i <= 11; i++)
426 if ((i == 3) || (i == 5) || (i == 7))
431 field = resp.substr(pos,
length);
435 char* cstr =
new char[field.size() + 1];
436 strcpy(cstr, field.c_str());
439 if ((i == 2) || (i == 4) ||
441 l_value = ((l_value >> 1) & 0x1);
448 this->encoders.
left += a_enc[3];
452 this->encoders.
left -= a_enc[3];
454 this->encoders.
left += a_enc[5];
456 this->encoders.
left -= a_enc[5];
458 this->encoders.
left += a_enc[7];
460 this->encoders.
left -= a_enc[7];
466 cout <<
"\n---------------------------------------------------" << endl;
467 cout <<
"ERROR->" <<
error << endl;
478 size_t x_pos, y_pos, theta_pos, lenght;
479 string x_value, y_value, theta_value, response, errormsg;
484 x_pos = response.find(
"x=");
485 x_value = response.substr((x_pos + 2), 8);
486 lenght = x_value.find(
'|');
487 x_value = x_value.substr(0, lenght);
488 char* x_char =
new char[lenght];
489 strcpy(x_char, x_value.c_str());
490 pose.
x = atof(x_char);
493 y_pos = response.find(
"y=");
494 y_value = response.substr((y_pos + 2), 8);
495 lenght = y_value.find(
'|');
496 y_value = y_value.substr(0, lenght);
497 char* y_char =
new char[lenght];
498 strcpy(y_char, y_value.c_str());
499 pose.
y = atof(y_char);
502 theta_pos = response.find(
"theta=");
503 theta_value = response.substr((theta_pos + 6), 8);
504 lenght = theta_value.find(
'|');
505 theta_value = theta_value.substr(0, lenght);
506 char* theta_char =
new char[lenght];
507 strcpy(theta_char, theta_value.c_str());
508 pose.
phi = atof(theta_char);
510 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...
void rectifyImageInPlace(const mrpt::img::TCamera &cameraParams)
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coeffici...
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)
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 rotate(char direction, int speed=5)
rotate send Rovio the command to rotate in the specified direcction 'r'->right, 'l'->left ...
bool pathDelete(const std::string &path_name)
bool m_videothread_initialized_error
bool m_videothread_initialized_done
Contains classes for various device interfaces.
mrpt::img::TCamera cameraParams
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
ERRORCODE_HTTP http_get(const string &url, std::vector< uint8_t > &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=nullptr, mrpt::system::TParameters< string > *extra_headers=nullptr, mrpt::system::TParameters< string > *out_headers=nullptr, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a std::vector<uint8_t>) ...
void loadFromConfigFile(const std::string §ion, const mrpt::config::CConfigFileBase &cfg)
Load all the params from a config source, in the format used in saveToConfigFile(), that is:
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
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
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...
This CStream derived class allow using a memory buffer as a CStream.
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.
bool isVideoStreamming() const
Return true if video is streaming correctly.
void loadFromStreamAsJPEG(mrpt::io::CStream &in)
Reads the image from a binary stream containing a binary jpeg file.
bool retrieve_video()
This function launchs a thread with the function "thread_video()" which gets frames into a buffer...
GLsizei const GLchar ** string
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...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool m_videothread_must_exit
GLuint GLsizei GLsizei * length
bool takeHeadUp()
Head positions.
bool pathRecordSave(const std::string &path_name)
A set of useful routines for networking.
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.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
double phi
Orientation (rads)
bool general_command(int act, std::string &response, std::string &errormsg)
void loadConfig(const mrpt::config::CConfigFileBase &configSource, const std::string §ion)
Loads the rovio camera calibration parameters (of leave the default ones if not found) (See CGenericS...
bool pathRename(const std::string &old_name, const std::string &new_name)
A class for storing images as grayscale or RGB bitmaps.
mrpt::obs::CObservationImage::Ptr buffer_img
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.