00001 #ifndef OVERHEAD_VISION_CLIENT_H_GAURD 00002 #define OVERHEAD_VISION_CLIENT_H_GAURD 00003 00004 // ========================================================================== 00005 // File name: vision.c 00006 // Author: Troy K. Becicka - Derek King 00007 // Description: 00008 // The purpose of vision is to act as only as a vision packet client for the 00009 // overhead vision system. The class accepts vision packets, parses and 00010 // saves the data. 00011 // ./vision --bt/--wlan <craftnum> 00012 // NOTE: If you get a connect error "too many links", just unplug the USB 00013 // Bluetooth adapter and plug it back in. 00014 // ========================================================================== 00015 00016 // ========================================================================== 00017 // Directions for starting overhead vision system 00018 // 00019 // First start vision client on each vision machine 00020 // logon to vision machine as root (you might need to do this from tale): 00021 // ssh root@vision#.me.uiuc.edu 00022 // move to vision program directory: 00023 // cd /home/afulford/PROJECT/CURRENT_WORKING_VISION 00024 // run vision client: 00025 // ./client 00026 // 00027 //+ Next start vision server on tale: 00028 // /home2/becicka/HoTDeC/bt_wlan_server_sbc/server/server 1234 --wlan 00029 // ========================================================================== 00030 00031 #include "../trucknet/unp.h" 00032 #include <math.h> 00033 #include <queue> 00034 00035 00036 // Packet types 00037 //#define CONTROL_DATA 0 00038 //#define VISION_DATA 1 00039 //#define CRAFT2CRAFT 2 00040 //#define MAX_NUM_HC 10 00041 //#define PUCK_ID 10 00042 //#define SEQ_NUM_ROLLOVER 20000 00043 //#define ACL_DATA_HDR_SIZE 5 // header size of an HCI ACL data packet (Bluetooth) 00044 00045 00046 enum hc_feedback_type {DISCONN_REQ, CHARGING_STATE, CONTROL_ACK}; 00047 typedef enum hc_feedback_type hc_fb_type; 00048 00049 00050 typedef struct 00051 { 00052 hc_fb_type type; 00053 int charging; // 0 when craft is not charging 00054 unsigned int sbc_battery_voltage; 00055 unsigned int thruster_battery_voltage; 00056 unsigned short ctrl_ack_num; // only used for feedback type CONTROL_ACK 00057 } hc_feedback_t; 00058 00059 00060 00061 // Defines the header for control and vision packets sent from 00062 // the server to the hovercraft 00063 typedef struct 00064 { 00065 unsigned short int seq_number; 00066 struct timeval timestamp; 00067 unsigned int packet_size : 8; // total packet size in bytes (including header and payload) 00068 unsigned int packet_type : 3; // 000 for control, 001 for vision data, 010 for craft-to-craft messages 00069 unsigned int num_hc_included : 5; // total number of craft for which vision data is included in the packet 00070 } srv_pkt_header_t; 00071 00072 // Defines the structure for control and vision packets sent from 00073 // the server to the hovercraft 00074 typedef struct 00075 { 00076 srv_pkt_header_t header; 00077 unsigned short data[256]; 00078 } srv_packet_t; 00079 00080 00081 00082 00083 class OverheadVisionClient 00084 { 00085 protected: 00086 00087 enum {CONTROL_DATA=0, VISION_DATA=1, CRAFT2CRAFT=2}; 00088 00089 public: 00090 00091 OverheadVisionClient(int patternNumber = 0); 00092 virtual ~OverheadVisionClient(void); 00093 00094 00095 int nextPacket(void); 00096 inline int findMyPattern(void) {return findPattern(myPatternNumber);} 00097 int findPattern(int patternNumber); 00098 int getIndex(int index); 00099 00100 virtual int recv(void) = 0; 00101 virtual int recvNoWait(void) = 0; 00102 00103 inline int getSeqNum(void); 00104 inline int getCount(void); 00105 inline int getID(void); 00106 inline float getX(void); 00107 inline float getZ(void); 00108 inline float getAngle(void); 00109 00110 protected: 00111 00112 int myPatternNumber; 00113 00114 std::queue<srv_packet_t> packetQ; 00115 const srv_packet_t *currentPacket; 00116 const unsigned short *currentData; 00117 00118 static const float toMeters = 1.0 / 10000.0; 00119 static const float toRadians = M_PI / 1800.0; 00120 00121 private: 00122 // Make sure defaults copy constructor and operator= aren't created, 00123 // they are not safe, we need to duplicate or reference count the SOCKETS 00124 // we use to make them safe 00125 OverheadVisionClient(const OverheadVisionClient &o) {} 00126 const OverheadVisionClient& operator= (const OverheadVisionClient &o) {return *this;} 00127 00128 }; 00129 00130 00131 inline int 00132 OverheadVisionClient::getSeqNum(void) { 00133 assert(currentPacket != NULL); 00134 return currentPacket->header.seq_number; 00135 } 00136 00137 inline int 00138 OverheadVisionClient::getCount(void) { 00139 assert(currentPacket != NULL); 00140 return currentPacket->header.num_hc_included; 00141 } 00142 00143 inline int 00144 OverheadVisionClient::getID(void) { 00145 assert(currentData != NULL); 00146 return currentData[0]; 00147 } 00148 00149 inline float 00150 OverheadVisionClient::getX(void) { 00151 assert(currentData != NULL); 00152 return ((float) currentData[1]) * toMeters; 00153 } 00154 00155 inline float 00156 OverheadVisionClient::getZ(void) { 00157 assert(currentData != NULL); 00158 return ((float) currentData[2]) * toMeters; 00159 } 00160 00161 inline float 00162 OverheadVisionClient::getAngle(void) { 00163 assert(currentData != NULL); 00164 return ((float) currentData[3]) * toRadians; 00165 } 00166 00167 00168 00169 #endif
1.4.4