/*************************************************************************** * * * Laser Range finder Functions: lrf_functions.h * * * * Function Proto-types and constant definitions. * * * * WRITTEN BY: Bill Kapralos * * DATE: June 9, 1997 * * * * York University * * Department of Computer Science * * * * The serial port initialization code (serialPortInit), was obtained * * from the Greg Reid's Lego project (York University), and from tty-io.c * * written by James R. Service. The function fdHasCharacters() was also * * obtained from code written by James R. Service (lrfd.c). * * * ****************************************************************************/ #ifndef LRF_FUNCTIONS #define LRF_FUNCTIONS #include #include #include #include #include #include #include #include /* laser Range Finder control commands. */ #define LR_TIMEOUT "150\r" /* Shots per reading. */ #define BEEPON "B\r" #define BEEPOFF "Q\r" #define INMETERES "M\r" #define INFEET "F\r" #define SINGLEUPDATE "S\r" #define CONT_UPDATE "C\r" #define SATURATEDREADING '(' #define BATTERYLOW '*' #define LR_READINGLEN 11 /* 8 bytes data + "\r\n" + '\0" */ #define LRF_READY_STRING "READY" /* Sent by LRF once it is turned ON and has passed it self-test routine. */ #define ERROR 0 #define CR '\r' #define DECIMAL_POINT '.' #define ASCII_ZERO '0' #define TTY_DEVICE "/dev/ttyb" /* Serial Port used. */ #define DELAY_TIME 900 /* Required between commands sent to LRF.*/ /*****************************************************/ static int serialFd = 0; /* Port file descriptor. */ static int lrfInitialized = 0; /*****************************************************/ /* Initialize the serial port */ int serialPortInit(char *); /* Send data to the serial port. */ int sendCommand(char *, int); /* Returns the number of bytes available to be read from the serial port. */ int fdHasCharacters(int); /* Read the data available at the serial port. */ int getReading(unsigned char *); /* Convert number in the string format to a double. */ float processReading(unsigned char *); /* Sends initialization commands to the LRF. */ void lrfSetUp(); /* Calculates the avearge value from an array of values. */ double calcAvgDistance(double *, int); /* Display message and exit program. */ void error(char *); int lrfChangeShotsPerReading(int); #endif