Go to the documentation of this file.00001 #include <unistd.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <stdio.h>
00005 #include "udp.h"
00006 #include <pthread.h>
00007
00008 #include <ros/ros.h>
00009
00010
00011 void diep(const char *s)
00012 {
00013 perror(s);
00014 exit(1);
00015 }
00016
00017 struct att_struct {
00018 double tm;
00019 double tm_pre;
00020 float frame;
00021
00022
00023 float pitch_w;
00024 float pitch_a;
00025 float pitch;
00026
00027
00028 float roll_w;
00029 float roll_a;
00030 float roll;
00031
00032
00033 float yaw_w;
00034 float yaw_m;
00035 float yaw;
00036
00037 double dt;
00038 double dt2;
00039
00040 double q_est[4];
00041 double b_est[3];
00042
00043
00044 double ts;
00045 float hraw;
00046 char h_meas;
00047 float ax;
00048 float ay;
00049 float az;
00050
00051 float wx;
00052 float wy;
00053 float wz;
00054
00055 float magX;
00056 float magY;
00057 float magZ;
00058
00059 float pressure;
00060
00061 float rotX;
00062 float rotY;
00063 float rotZ;
00064
00065 float altd;
00066
00067 float motor1;
00068 float motor2;
00069 float motor3;
00070 float motor4;
00071 };
00072
00073 int main(int argc, char **argv)
00074 {
00075 udp_struct udp;
00076 ardrone_islab::Navdataislab navdata;
00077
00078 int msglen;
00079 char buf[512];
00080 char * pch;
00081 ardrone_islab::Navdataislab navdataformat;
00082 ros::init(argc, argv, "ardrone_ground_node_server");
00083 ros::NodeHandle n;
00084 ros::Rate loop_rate(300);
00085
00086 ros::Publisher navdata_pub = n.advertise<ardrone_islab::Navdataislab>("ardrone/navdata",1000);
00087
00088 printf("check1");
00089
00090 ROS_INFO_STREAM("Start ROS node!");
00091
00092 if(udpServer_Init(&udp,9930,0)) diep("udpServer_Init");
00093 printf("check2");
00094 while (ros::ok())
00095 {
00096
00097 int cnt=0;
00098 do {
00099 msglen = udpServer_Receive(&udp, buf, 512);
00100 cnt++;
00101 } while(msglen<=0);
00102
00103 pch = strtok (buf," ,");
00104 int countpart = 0;
00105
00106
00107 while (countpart<=42)
00108 {
00109 if (countpart == 0) navdata.tm = atof(pch);
00110 if (countpart == 1) navdata.tm_pre = atof(pch);
00111 if (countpart == 2) navdata.frame = atof(pch);
00112 if (countpart == 3) navdata.pitch_w = atof(pch);
00113 if (countpart == 4) navdata.pitch_a = atof(pch);
00114 if (countpart == 5) navdata.pitch = atof(pch);
00115 if (countpart == 6) navdata.roll_w = atof(pch);
00116 if (countpart == 7) navdata.roll_a = atof(pch);
00117 if (countpart == 8) navdata.roll = atof(pch);
00118 if (countpart == 9) navdata.yaw_w = atof(pch);
00119 if (countpart == 10) navdata.yaw_m = atof(pch);
00120 if (countpart == 11) navdata.yaw = atof(pch);
00121 if (countpart == 12) navdata.dt = atof(pch);
00122 if (countpart == 13) navdata.dt2 = atof(pch);
00123 if (countpart == 14) navdata.q_est[0] = atof(pch);
00124 if (countpart == 15) navdata.q_est[1] = atof(pch);
00125 if (countpart == 16) navdata.q_est[2] = atof(pch);
00126 if (countpart == 17) navdata.q_est[3] = atof(pch);
00127 if (countpart == 18) navdata.b_est[0] = atof(pch);
00128 if (countpart == 19) navdata.b_est[1] = atof(pch);
00129 if (countpart == 20) navdata.b_est[2] = atof(pch);
00130
00131 if (countpart == 21) navdata.ts = atof(pch);
00132 if (countpart == 22) navdata.hraw = atof(pch);
00133 if (countpart == 23) navdata.h_meas = atof(pch);
00134 if (countpart == 24) navdata.ax = atof(pch);
00135 if (countpart == 25) navdata.ay = atof(pch);
00136 if (countpart == 26) navdata.az = atof(pch);
00137 if (countpart == 27) navdata.wx = atof(pch);
00138 if (countpart == 28) navdata.wy = atof(pch);
00139 if (countpart == 29) navdata.wz = atof(pch);
00140 if (countpart == 30) navdata.magX = atof(pch);
00141 if (countpart == 31) navdata.magY = atof(pch);
00142 if (countpart == 32) navdata.magZ = atof(pch);
00143 if (countpart == 33) navdata.pressure = atof(pch);
00144 if (countpart == 34) navdata.rotX = atof(pch);
00145 if (countpart == 35) navdata.rotY = atof(pch);
00146 if (countpart == 36) navdata.rotZ = atof(pch);
00147 if (countpart == 37) navdata.altd = atof(pch);
00148 if (countpart == 38) navdata.motor1 = atof(pch);
00149 if (countpart == 39) navdata.motor2 = atof(pch);
00150 if (countpart == 40) navdata.motor3 = atof(pch);
00151 if (countpart == 41) navdata.motor4 = atof(pch);
00152 countpart ++;
00153 pch = strtok (NULL, " ,");
00154 }
00155
00156
00157 navdata.header.stamp = ros::Time::now();
00158 navdata_pub.publish(navdata);
00159
00160 ros::spinOnce();
00161 loop_rate.sleep();
00162 }
00163
00164 udpClient_Close(&udp);
00165 return 0;
00166 }