25 CRovio::TOptions::TOptions() :
26 IP(
"150.214.109.134"),
28 password(
"investigacion")
31 double cam_params[] = {
32 1650.740234375, 0, 805.33190917968750,
33 0, 1640.6497802734375, 675.1627197265625,
45 string response, errormsg;
48 if (!response.empty())
49 cout<<
"[CRovio::Initialize] Response:\n"<<response<<endl;
51 if (!errormsg.empty())
60 string response, errormsg;
61 string command =
format(
"http://%s/rev.cgi?Cmd=nav&action=18&drive=%i&speed=%i",
options.
IP.c_str(), direction, speed);
63 return errormsg.empty();
71 string response, errormsg;
73 command =
format(
"http://%s/rev.cgi?Cmd=nav&action=%i",
options.
IP.c_str(), act);
75 return errormsg.empty();
80 string response, errormsg;
82 command =
format(
"http://%s/rev.cgi?Cmd=nav&action=%i&name=%s",
options.
IP.c_str(), act, path_name.c_str());
84 return errormsg.empty();
93 command =
format(
"http://%s/rev.cgi?Cmd=nav&action=%i",
options.
IP.c_str(), act);
95 return errormsg.empty();
115 cout <<
"Error in parameter of move()";
129 cout <<
"Error in parameter of rotate()";
173 return error.empty();
193 string response, errormsg;
194 string command =
format(
"http://%s/rev.cgi?Cmd=nav&action=11&name=%s&newname=%s",
options.
IP.c_str(), current_name.c_str(), new_name.c_str());
196 return errormsg.empty();
232 const bool open_ok = in_video.
openURL(video_url,
false ,
false );
239 std::cerr <<
"[CRovio] Error opening video stream: " << video_url << std::endl;
245 CObservationImagePtr obs = CObservationImage::Create();
261 cout<<
"[CRovio::thread_video] Warning: the program doesn't receive any image\n";
270 catch(std::exception &e)
274 cout<<
"Error in thread_video thread";
275 cerr << e.what() << endl;
281 cout<<
"Error in thread_video thread";
319 bool was_already_stop =
true;
324 was_already_stop =
false;
328 return !was_already_stop;
356 string MF=
format(
"http://%s/Jpeg/CamImg[0000].jpg",
options.
IP.c_str());
367 catch(std::exception &e)
369 cerr << e.what() << endl;
380 size_t x_pos, lenght;
381 string x_value, response, errormsg;
386 x_pos=response.find(
"x=");
387 x_value=response.substr((x_pos+2),8);
388 lenght=x_value.find(
'|');
389 x_value=x_value.substr(0,lenght);
390 char* x_char=
new char [lenght];
391 strcpy(x_char, x_value.c_str());
398 return error.empty();
406 char * result=strpbrk(sLong,
"-0123456789ABCDEF");
408 return strtol(result,&stop,16);
414 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)||(i==6) )
440 l_value=( (l_value>>1) & 0x1);
445 this->encoders.
left += a_enc[3];
447 this->encoders.
left -= a_enc[3];
449 this->encoders.
left += a_enc[5];
451 this->encoders.
left -= a_enc[5];
453 this->encoders.
left += a_enc[7];
455 this->encoders.
left -= a_enc[7];
460 cout <<
"\n---------------------------------------------------" << endl;
461 cout <<
"ERROR->" <<
error <<endl;
472 size_t x_pos, y_pos, theta_pos, lenght;
473 string x_value, y_value, theta_value, response, errormsg;
477 x_pos=response.find(
"x=");
478 x_value=response.substr((x_pos+2),8);
479 lenght=x_value.find(
'|');
480 x_value=x_value.substr(0,lenght);
481 char* x_char=
new char [lenght];
482 strcpy(x_char, x_value.c_str());
486 y_pos=response.find(
"y=");
487 y_value=response.substr((y_pos+2),8);
488 lenght=y_value.find(
'|');
489 y_value=y_value.substr(0,lenght);
490 char* y_char=
new char [lenght];
491 strcpy(y_char, y_value.c_str());
495 theta_pos=response.find(
"theta=");
496 theta_value=response.substr((theta_pos+6),8);
497 lenght=theta_value.find(
'|');
498 theta_value=theta_value.substr(0,lenght);
499 char* theta_char=
new char [lenght];
500 strcpy(theta_char, theta_value.c_str());
501 pose.
phi=atof(theta_char);
503 return errormsg.empty();
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
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)
struct mrpt::hwdrivers::CRovio::TEncoders encoders
bool m_videothread_initialized_error
bool m_videothread_initialized_done
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.
char BASE_IMPEXP * strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcpy.
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...
ERRORCODE_HTTP BASE_IMPEXP 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=NULL, mrpt::utils::TParameters< string > *extra_headers=NULL, mrpt::utils::TParameters< string > *out_headers=NULL, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
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.
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
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.
A set of useful routines for networking.
void thread_video()
This function takes a frame and waits until getLastImage ask for it, and so on.
std::string BASE_IMPEXP 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 isClear() const
Returns true if the handle is uninitialized.
mrpt::obs::CObservationImagePtr buffer_img
bool retrieve_video()
This function launchs a thread with the function "thread_video()" which gets frames into a buffer...
mrpt::synch::CCriticalSection buffer_img_cs
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)
TThreadHandle createThreadFromObjectMethod(CLASS *obj, void(CLASS::*func)(PARAM), PARAM param)
Creates a new thread running a non-static method (so it will have access to "this") from another meth...
mrpt::system::TThreadHandle m_videoThread
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
GLuint GLsizei GLsizei * length
bool takeHeadUp()
Head positions.
bool pathRecordSave(const std::string &path_name)
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
bool getNextImageSync(mrpt::obs::CObservationImagePtr &lastImage)
Returns the next frame from Rovio's live video stream, after starting the live streaming with retriev...
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)
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 BASE_IMPEXP joinThread(const TThreadHandle &threadHandle)
Waits until the given thread ends.
void loadFromStreamAsJPEG(CStream &in)
Reads the image from a binary stream containing a binary jpeg file.