00001 /* 00002 * surveyor_comms.h 00003 * 00004 * Functions for communicating with a surveyor SR-1 robot 00005 * with the XBee Pro 00006 * 00007 * Copyright (C) 2007 - Michael Janssen (original author) 00008 * Copyright (C) 2009 - Carlos Jaramillo (current maintainer) 00009 * 00010 * This program is free software; you can redistribute it and/or modify it 00011 * under the terms of the GNU General Public License as published by the Free 00012 * Software Foundation; either version 2 of the License, or (at your option) 00013 * any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, but WITHOUT 00016 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00017 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00018 * more details. 00019 * 00020 * You should have received a copy of the GNU General Public License along with 00021 * this program; if not, write to the Free Software Foundation, Inc., 51 00022 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00023 */ 00024 00025 #ifndef SURVEYOR_COMMS_H_ 00026 #define SURVEYOR_COMMS_H_ 00027 00028 // CARLOS: comments this out for cpp: 00029 #ifdef __cplusplus 00030 extern "C" 00031 { 00032 #endif 00033 00034 #include <stdint.h> 00035 #include <limits.h> 00036 00037 // CARLOS: added libraries when using cpp: 00038 //#include <sstream> 00039 00040 #define SRV1_IMAGE_OFF 'Z' 00041 00042 #define SRV1_IMAGE_SMALL 'a' 00043 #define SRV1_IMAGE_MED 'b' 00044 #define SRV1_IMAGE_BIG 'c' 00045 00046 #define SRV1_MAX_VEL_X 0.315 00047 #define SRV1_MAX_VEL_W 2.69 00048 00049 #define SRV1_AXLE_LENGTH 0.258 00050 00051 #define SRV1_DIAMETER 0.10 00052 00057 typedef struct 00058 { 00059 00060 char port[PATH_MAX]; 00061 int fd; 00062 00063 double vx; 00064 double va; 00065 00066 unsigned char need_ir; 00067 int bouncedir[4]; 00068 00069 unsigned char image_mode; 00070 unsigned char set_image_mode; 00071 uint32_t frame_size; 00072 char *frame; 00073 00074 } srv1_comm_t; 00075 00076 /* 00077 * Creates a srv1 for use 00078 */ 00079 srv1_comm_t * 00080 srv1_create(const char *port); 00081 00082 /* 00083 * Destroys. 00084 */ 00085 void 00086 srv1_destroy(srv1_comm_t *x); 00087 00088 /* 00089 * Initialized a srv1, connecting and checking the version 00090 */ 00091 int 00092 srv1_init(srv1_comm_t *x); 00093 00094 /* 00095 * Sets the speed. Forward velocity trumps rotational velocity. 00096 * 00097 * This function sets the speed for 2.5 seconds, so there is 00098 * an automatic failsafe if the robot drives out of range. 00099 * 00100 * \param dx Speed in meters per second forward velocity 00101 * \param dw Speed in radians per second rotational velocity 00102 * \return 1 for success, 0 for failure. 00103 */ 00104 int 00105 srv1_set_speed(srv1_comm_t *x, double dx, double dw); 00106 00107 /* 00108 * Attempts to read the sensors that are enabled. 00109 * Currently only reads images and bounced IR data. 00110 * \param x robot structure. 00111 * \return 1 for success, 0 for failure. 00112 */ 00113 int 00114 srv1_read_sensors(srv1_comm_t *x); 00115 00116 /* 00117 * Resets communication buffers by reading all data waiting 00118 * and querying the version once again. 00119 * 00120 * \param x robot structure 00121 * \return 1 for success, 0 for failure. 00122 */ 00123 int 00124 srv1_reset_comms(srv1_comm_t *x); 00125 00126 /* 00127 * Returns an approximation of the distance an object is away with 00128 * a IR range reading. 00129 * 00130 * \param rangereading Reading from a IR. 00131 * \return approximated distance in cm 00132 */ 00133 //double srv1_range_to_distance(int rangereading); 00134 // 00136 //int saveNamedData(const char *name, char *data, int size); 00140 //void savePhoto(const std::string aPrefix, char *data, int size, uint32_t aWidth = 4); 00141 00142 // CARLOS: comments this out for cpp: 00143 #ifdef __cplusplus 00144 } 00145 #endif 00146 00147 #endif /* SURVEYOR_COMMS_H_ */