51 #include <sys/types.h> 65 #include "rnr/rnrconfig.h" 97 "Operation timed out",
99 "No resource available",
102 "Permissions denied",
103 "Dynamixel chain or servo error",
109 "Robot is in an alarmed state",
110 "Operation interrupted",
111 "Robotic link(s) movement obstructed",
112 "Robot emergency stopped",
113 "Motor controller or motor error",
126 int ec = ecode >= 0 ? ecode : -ecode;
130 ec = LAE_ECODE_BADEC;
142 sscanf(str.c_str(),
"%d.%d.%d", &nMajor, &nMinor, &nRevision);
149 if( lhs.tv_sec < rhs.tv_sec )
153 else if( (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_usec < rhs.tv_usec) )
165 return (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_usec == rhs.tv_usec)?
171 return !(lhs < rhs) && !(lhs == rhs);
176 return lhs < rhs || lhs == rhs;
181 return lhs > rhs || lhs == rhs;
184 struct timeval
laelaps::operator+(const struct timeval& op1,
185 const struct timeval& op2)
187 struct timeval sum = op1;
189 sum.tv_sec += op2.tv_sec;
190 sum.tv_usec += op2.tv_usec;
192 if( sum.tv_usec > MILLION )
195 sum.tv_usec -= MILLION;
201 struct timeval laelaps::operator-(const struct timeval& op1,
202 const struct timeval& op2)
206 diff.tv_sec = op1.tv_sec - op2.tv_sec;
208 if( op1.tv_usec >= op2.tv_usec)
210 diff.tv_usec = op1.tv_usec - op2.tv_usec;
215 diff.tv_usec = MILLION + op1.tv_usec - op2.tv_usec;
223 struct timeval dt = t1 - t0;
225 return (
long)dt.tv_sec * MILLION + (long)dt.tv_usec;
228 double laelaps::dt(
struct timeval& t1,
struct timeval& t0)
232 return (
double)
dt_usec(t1, t0) / (double)MILLION;
236 return -(double)
dt_usec(t0, t1) / (double)MILLION;
242 if( lhs.tv_sec < rhs.tv_sec )
246 else if( (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_nsec < rhs.tv_nsec) )
258 return (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_nsec == rhs.tv_nsec)?
264 return !(lhs < rhs) && !(lhs == rhs);
269 return lhs < rhs || lhs == rhs;
274 return lhs > rhs || lhs == rhs;
277 struct timespec laelaps::operator+(const struct timespec& op1,
278 const struct timespec& op2)
280 struct timespec sum = op1;
282 sum.tv_sec += op2.tv_sec;
283 sum.tv_nsec += op2.tv_nsec;
285 if( sum.tv_nsec > BILLION )
288 sum.tv_nsec -= BILLION;
294 struct timespec laelaps::operator-(const struct timespec& op1,
295 const struct timespec& op2)
297 struct timespec diff;
299 diff.tv_sec = op1.tv_sec - op2.tv_sec;
301 if( op1.tv_nsec >= op2.tv_nsec)
303 diff.tv_nsec = op1.tv_nsec - op2.tv_nsec;
308 diff.tv_nsec = BILLION + op1.tv_nsec - op2.tv_nsec;
316 struct timespec dt = t1 - t0;
318 return (
long long)dt.tv_sec * BILLION + (
long long)dt.tv_nsec;
321 double laelaps::dt(
struct timespec& t1,
struct timespec& t0)
325 return (
double)
dt_nsec(t1, t0) / (double)BILLION;
329 return -(double)
dt_nsec(t0, t1) / (double)BILLION;
335 char buf[MAX_PATH+1];
341 if( (len = readlink(strDevName.c_str(), buf, MAX_PATH)) > 0 )
348 string strRealDevName(buf);
349 return strRealDevName;
355 char s[strDevName.size()+1];
358 strcpy(s, strDevName.c_str());
360 char *sDirName = dirname(s);
362 ss << sDirName <<
"/" << buf;
379 vector<string> &elems)
384 while( getline(ss, item, delim) )
386 elems.push_back(item);
393 vector<string> elems;
395 split(s, delim, elems);
bool operator>=(const struct timeval &lhs, const struct timeval &rhs)
Greater than or equal to compare operator.
double dt(struct timeval &t1, struct timeval &t0)
Calculate delta time.
uint_t strToVersion(const std::string &str)
Convert version dotted string to integer equivalent.
bool operator>(const struct timeval &lhs, const struct timeval &rhs)
Greater than compare operator.
const char * getStrError(const int ecode)
Get the error string describing the <b><i>Laelaps</i></b> error code.
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Split string at the delimiter character.
bool operator<=(const struct timeval &lhs, const struct timeval &rhs)
Less than or equal to compare operator.
bool operator<(const struct timeval &lhs, const struct timeval &rhs)
Less than compare operator.
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Laelaps common utilities.
long long dt_nsec(struct timespec &t1, struct timespec &t0)
Calculate delta time in nanoseconds.
bool operator==(const struct timeval &lhs, const struct timeval &rhs)
Equality compare operator.
static const char * EcodeStrTbl[]
<b><i>Laelaps</i></b> Error Code String Table.
#define LAE_VERSION(major, minor, revision)
Convert version triplet to integer equivalent.
std::string getRealDeviceName(const std::string &strDevName)
Get real device name.
Top-level package include file.
long dt_usec(struct timeval &t1, struct timeval &t0)
Calculate delta time in microseconds.