28 CRovio::TOptions::TOptions()
29 : IP(
"150.214.109.134"), user(
"admin"), password(
"investigacion")
32 double cam_params[] = {1650.740234375,
43 0.12792350351810455, -0.4786585867404937, 0.011172077618539333,
44 -0.0037264013662934303);
54 string response, errormsg;
59 if (!response.empty())
60 cout <<
"[CRovio::Initialize] Response:\n" << response << endl;
62 if (!errormsg.empty())
71 string response, errormsg;
73 "http://%s/rev.cgi?Cmd=nav&action=18&drive=%i&speed=%i",
76 return errormsg.empty();
84 string response, errormsg;
89 return errormsg.empty();
94 string response, errormsg;
97 "http://%s/rev.cgi?Cmd=nav&action=%i&name=%s",
options.
IP.c_str(), act,
100 return errormsg.empty();
110 format(
"http://%s/rev.cgi?Cmd=nav&action=%i",
options.
IP.c_str(), act);
112 return errormsg.empty();
131 cout <<
"Error in parameter of move()";
145 cout <<
"Error in parameter of rotate()";
172 return error.empty();
180 string response, errormsg;
182 "http://%s/rev.cgi?Cmd=nav&action=11&name=%s&newname=%s",
183 options.
IP.c_str(), current_name.c_str(), new_name.c_str());
185 return errormsg.empty();
222 const bool open_ok = in_video.
openURL(
223 video_url,
false ,
false );
230 std::cerr <<
"[CRovio] Error opening video stream: " << video_url
253 cout <<
"[CRovio::thread_video] Warning: the program doesn't " 254 "receive any image\n";
256 std::this_thread::sleep_for(10ms);
263 catch (
const 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;
359 catch (
const std::exception& e)
361 cerr << e.what() << endl;
372 size_t x_pos, lenght;
373 string x_value, response, errormsg;
379 x_pos = response.find(
"x=");
380 x_value = response.substr((x_pos + 2), 8);
381 lenght = x_value.find(
'|');
382 x_value = x_value.substr(0, lenght);
383 char* x_char =
new char[lenght];
384 strcpy(x_char, x_value.c_str());
385 pose.
x = atof(x_char);
391 return error.empty();
399 char* result = strpbrk(sLong,
"-0123456789ABCDEF");
401 return strtol(result, &stop, 16);
407 string resp,
error, field;
413 int* a_enc =
new int[11];
419 size_t pos = (resp.find(
"responses =") + 12);
420 for (
int i = 0; i <= 11; i++)
422 if ((i == 3) || (i == 5) || (i == 7))
427 field = resp.substr(pos,
length);
431 char* cstr =
new char[field.size() + 1];
432 strcpy(cstr, field.c_str());
435 if ((i == 2) || (i == 4) ||
437 l_value = ((l_value >> 1) & 0x1);
444 this->encoders.
left += a_enc[3];
448 this->encoders.
left -= a_enc[3];
450 this->encoders.
left += a_enc[5];
452 this->encoders.
left -= a_enc[5];
454 this->encoders.
left += a_enc[7];
456 this->encoders.
left -= a_enc[7];
462 cout <<
"\n---------------------------------------------------" << endl;
463 cout <<
"ERROR->" <<
error << endl;
474 size_t x_pos, y_pos, theta_pos, lenght;
475 string x_value, y_value, theta_value, response, errormsg;
480 x_pos = response.find(
"x=");
481 x_value = response.substr((x_pos + 2), 8);
482 lenght = x_value.find(
'|');
483 x_value = x_value.substr(0, lenght);
484 char* x_char =
new char[lenght];
485 strcpy(x_char, x_value.c_str());
486 pose.
x = atof(x_char);
489 y_pos = response.find(
"y=");
490 y_value = response.substr((y_pos + 2), 8);
491 lenght = y_value.find(
'|');
492 y_value = y_value.substr(0, lenght);
493 char* y_char =
new char[lenght];
494 strcpy(y_char, y_value.c_str());
495 pose.
y = atof(y_char);
498 theta_pos = response.find(
"theta=");
499 theta_value = response.substr((theta_pos + 6), 8);
500 lenght = theta_value.find(
'|');
501 theta_value = theta_value.substr(0, lenght);
502 char* theta_char =
new char[lenght];
503 strcpy(theta_char, theta_value.c_str());
504 pose.
phi = atof(theta_char);
506 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...
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) ...
void loadFromArray(const VECTOR &vals)
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)
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.
void undistort(CImage &out_img, const mrpt::img::TCamera &cameraParams) const
Undistort the image according to some camera parameters, and returns an output undistorted image...
#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.