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();
204 const std::string& section)
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;
371 size_t x_pos, lenght;
372 string x_value, response, errormsg;
378 x_pos = response.find(
"x=");
379 x_value = response.substr((x_pos + 2), 8);
380 lenght = x_value.find(
'|');
381 x_value = x_value.substr(0, lenght);
382 char* x_char =
new char[lenght];
383 strcpy(x_char, x_value.c_str());
384 pose.
x = atof(x_char);
390 return error.empty();
398 char* result = strpbrk(sLong,
"-0123456789ABCDEF");
400 return strtol(result, &stop, 16);
405 string resp,
error, field;
411 int* a_enc =
new int[11];
417 size_t pos = (resp.find(
"responses =") + 12);
418 for (
int i = 0; i <= 11; i++)
420 if ((i == 3) || (i == 5) || (i == 7))
425 field = resp.substr(pos, length);
429 char* cstr =
new char[field.size() + 1];
430 strcpy(cstr, field.c_str());
433 if ((i == 2) || (i == 4) ||
435 l_value = ((l_value >> 1) & 0x1);
461 cout <<
"\n---------------------------------------------------" << endl;
462 cout <<
"ERROR->" <<
error << endl;
473 size_t x_pos, y_pos, theta_pos, lenght;
474 string x_value, y_value, theta_value, response, errormsg;
479 x_pos = response.find(
"x=");
480 x_value = response.substr((x_pos + 2), 8);
481 lenght = x_value.find(
'|');
482 x_value = x_value.substr(0, lenght);
483 char* x_char =
new char[lenght];
484 strcpy(x_char, x_value.c_str());
485 pose.
x = atof(x_char);
488 y_pos = response.find(
"y=");
489 y_value = response.substr((y_pos + 2), 8);
490 lenght = y_value.find(
'|');
491 y_value = y_value.substr(0, lenght);
492 char* y_char =
new char[lenght];
493 strcpy(y_char, y_value.c_str());
494 pose.
y = atof(y_char);
497 theta_pos = response.find(
"theta=");
498 theta_value = response.substr((theta_pos + 6), 8);
499 lenght = theta_value.find(
'|');
500 theta_value = theta_value.substr(0, lenght);
501 char* theta_char =
new char[lenght];
502 strcpy(theta_char, theta_value.c_str());
503 pose.
phi = atof(theta_char);
505 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)
std::string std::string format(std::string_view fmt, ARGS &&... args)
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
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
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...
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...
bool m_videothread_must_exit
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
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