Go to the documentation of this file.00001
00005 #include "ros_resources.hpp"
00006
00007 void changemode(int dir)
00008 {
00009 static struct termios oldt, newt;
00010
00011 if ( dir == 1 )
00012 {
00013 tcgetattr( STDIN_FILENO, &oldt);
00014 newt = oldt;
00015 newt.c_lflag &= ~( ICANON | ECHO );
00016 tcsetattr( STDIN_FILENO, TCSANOW, &newt);
00017 }
00018 else
00019 tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
00020 }
00021
00022 int kbhit (void)
00023 {
00024 struct timeval tv;
00025 fd_set rdfs;
00026
00027 tv.tv_sec = 0;
00028 tv.tv_usec = 0;
00029
00030 FD_ZERO(&rdfs);
00031 FD_SET (STDIN_FILENO, &rdfs);
00032
00033 select(STDIN_FILENO+1, &rdfs, NULL, NULL, &tv);
00034 return FD_ISSET(STDIN_FILENO, &rdfs);
00035
00036 }
00037
00038 double timeDiff(ros::Time time1, ros::Time time2) {
00039
00040 double retVal;
00041
00042 retVal = ((double) time1.sec) - ((double) time2.sec);
00043
00044 retVal += 1e-9 * (((double) time1.nsec) - ((double) time2.nsec));
00045
00046 return retVal;
00047
00048 }
00049
00050 ros::Time findAverageTime(ros::Time time1, ros::Time time2) {
00051
00052 long int sec = 0, nsec = 0;
00053
00054 nsec = (time1.nsec/2) + (time2.nsec/2);
00055
00056
00057
00058
00059 if ((time1.sec % 2) > 0) {
00060 sec += (time1.sec-1)/2;
00061 } else {
00062 sec += time1.sec/2;
00063 }
00064
00065 if ((time2.sec % 2) > 0) {
00066 sec += (time2.sec-1)/2;
00067 } else {
00068 sec += time2.sec/2;
00069 }
00070
00071 if (((time1.sec % 2) > 0) && ((time2.sec % 2) > 0)) {
00072 sec += 1;
00073 } else if (((time1.sec % 2) > 0) || ((time2.sec % 2) > 0)) {
00074 nsec += 500000000;
00075 }
00076
00077
00078
00079
00080 ros::Time avTime;
00081
00082 avTime.sec = sec;
00083 avTime.nsec = nsec;
00084
00085 return avTime;
00086
00087 }