Go to the documentation of this file.00001 #include "ros/ros.h"
00002 #include "komodo_sensors/apm_adc.h"
00003 #include "komodo_sensors/apm_gps.h"
00004 #include "komodo_sensors/apm_imu.h"
00005 #include "sensor_msgs/Imu.h"
00006 #include "sensor_msgs/Range.h"
00007 #include "sensor_msgs/NavSatFix.h"
00008 #include "sensor_msgs/NavSatStatus.h"
00009 #include "geometry_msgs/Quaternion.h"
00010 #include "geometry_msgs/Vector3Stamped.h"
00011 #include "tf/transform_datatypes.h"
00012 #include "std_msgs/Float32.h"
00013
00014
00015 ros::Publisher pc_bat_pub;
00016
00017 ros::Publisher imu_raw_pub;
00018 ros::Publisher imu_mag_pub;
00019
00020 ros::Publisher us1_pub;
00021 ros::Publisher us2_pub;
00022 ros::Publisher us3_pub;
00023 ros::Publisher ir1_pub;
00024 ros::Publisher ir2_pub;
00025 ros::Publisher ir3_pub;
00026
00027 ros::Publisher gps_pub;
00028
00029 sensor_msgs::Range us1_range_msg;
00030 sensor_msgs::Range us2_range_msg;
00031 sensor_msgs::Range us3_range_msg;
00032 sensor_msgs::Range ir1_range_msg;
00033 sensor_msgs::Range ir2_range_msg;
00034 sensor_msgs::Range ir3_range_msg;
00035
00036 std::string gps_frame_id;
00037
00038
00039
00040 void gpsCallback(const komodo_sensors::apm_gps::ConstPtr& msg) {
00041
00042
00043 sensor_msgs::NavSatFix gps_msg;
00044 gps_msg.header.frame_id = gps_frame_id;
00045 gps_msg.header.stamp = ros::Time::now();
00046 gps_msg.latitude = (float)msg->lat / 10000000.0;
00047 gps_msg.longitude = (float)msg->lon / 10000000.0;
00048 gps_msg.altitude = (float)msg->alt / 100;
00049
00050 sensor_msgs::NavSatStatus gps_status_msg;
00051
00052 gps_status_msg.service = 1;
00053 if ((msg->status == 0) || (msg->status == 1))
00054 gps_status_msg.status = 1;
00055 else
00056 gps_status_msg.status = 0;
00057
00058 gps_msg.status = gps_status_msg;
00059
00060 gps_msg.position_covariance_type = 1;
00061
00062
00063
00064
00065
00066 float cov = ((float) (msg->hdop) / 100.0) * ((float) (msg->hdop) / 100.0);
00067 gps_msg.position_covariance[0] = cov;
00068 gps_msg.position_covariance[4] = cov;
00069 gps_msg.position_covariance[8] = cov;
00070
00071
00072
00073
00074 gps_pub.publish(gps_msg);
00075
00076
00077
00078
00079 }
00080
00081 void adcCallback(const komodo_sensors::apm_adc::ConstPtr& msg) {
00082 std_msgs::Float32 v_bat;
00083 v_bat.data = (float)(msg->A7) * 5.0 / 1023.0;
00084 pc_bat_pub.publish(v_bat);
00085
00086
00087 ros::Time now = ros::Time::now();
00088
00089 us1_range_msg.header.stamp = now;
00090 us1_range_msg.range = (float) msg->A0 / 1.7 * 2.54 / 100.0;
00091
00092 us2_range_msg.header.stamp = ros::Time::now();
00093 us2_range_msg.range = (float) msg->A1 / 1.7 * 2.54 / 100.0;
00094
00095 us3_range_msg.header.stamp = now;
00096 us3_range_msg.range = (float) msg->A2 / 1.7 * 2.54 / 100.0;
00097
00098 ir1_range_msg.header.stamp = now;
00099
00100
00101
00102 if (((float)(msg->A3) >=80)&&((float)(msg->A3) <= 500)) ir1_range_msg.range = (4800.0/((float)(msg->A3 - 20)))/100.0;
00103 else if ((float)(msg->A3) <80) ir1_range_msg.range =ir1_range_msg.max_range;
00104 else ir1_range_msg.range =ir1_range_msg.min_range;
00105
00106
00107
00108 ir2_range_msg.header.stamp = now;
00109
00110 if (((float)(msg->A4) >=80)&&((float)(msg->A4) <= 500)) ir2_range_msg.range = (4800.0/((float)(msg->A4 - 20)))/100.0;
00111 else if ((float)(msg->A4) <80) ir2_range_msg.range =ir2_range_msg.max_range;
00112 else ir2_range_msg.range =ir2_range_msg.min_range;
00113
00114
00115
00116 ir3_range_msg.header.stamp = now;
00117
00118 if (((float)(msg->A5) >=80)&&((float)(msg->A5) <= 500)) ir3_range_msg.range = (4800.0/((float)(msg->A5 - 20)))/100.0;
00119 else if ((float)(msg->A5) <80) ir3_range_msg.range =ir3_range_msg.max_range;
00120 else ir3_range_msg.range =ir3_range_msg.min_range;
00121
00122
00123 us1_pub.publish(us1_range_msg);
00124 us2_pub.publish(us2_range_msg);
00125 us3_pub.publish(us3_range_msg);
00126 ir1_pub.publish(ir1_range_msg);
00127 ir2_pub.publish(ir2_range_msg);
00128 ir3_pub.publish(ir3_range_msg);
00129
00130 }
00131
00132 void imuCallback(const komodo_sensors::apm_imu::ConstPtr& msg) {
00133
00134
00135
00136
00137
00138 sensor_msgs::Imu imu_msg;
00139 geometry_msgs::Vector3Stamped m;
00140
00141 imu_msg.header.frame_id = "imu_base_link";
00142 imu_msg.header.stamp = ros::Time::now();
00143
00144 imu_msg.linear_acceleration.x = msg->ax;
00145 imu_msg.linear_acceleration.y = msg->ay;
00146 imu_msg.linear_acceleration.z = msg->az;
00147 imu_msg.angular_velocity.x = msg->gx;
00148 imu_msg.angular_velocity.y = msg->gy;
00149 imu_msg.angular_velocity.z = msg->gz;
00150
00151 double angular_velocity_stdev_ = 0.012;
00152 double orientation_stdev_ = 0.035;
00153 double linear_acceleration_stdev_ = 0.098;
00154 double angular_velocity_covariance = angular_velocity_stdev_
00155 * angular_velocity_stdev_;
00156 double orientation_covariance = orientation_stdev_ * orientation_stdev_;
00157 double linear_acceleration_covariance = linear_acceleration_stdev_
00158 * linear_acceleration_stdev_;
00159
00160 imu_msg.linear_acceleration_covariance[0] = linear_acceleration_covariance;
00161 imu_msg.linear_acceleration_covariance[4] = linear_acceleration_covariance;
00162 imu_msg.linear_acceleration_covariance[8] = linear_acceleration_covariance;
00163
00164 imu_msg.angular_velocity_covariance[0] = angular_velocity_covariance;
00165 imu_msg.angular_velocity_covariance[4] = angular_velocity_covariance;
00166 imu_msg.angular_velocity_covariance[8] = angular_velocity_covariance;
00167
00168 imu_msg.orientation_covariance[0] = orientation_covariance;
00169 imu_msg.orientation_covariance[4] = orientation_covariance;
00170 imu_msg.orientation_covariance[8] = orientation_covariance;
00171
00172 m.header.frame_id = "imu_base_link";
00173 m.header.stamp = ros::Time::now();
00174 m.vector.x = msg->mx;
00175 m.vector.y = msg->my;
00176 m.vector.z = msg->mz;
00177
00178
00179
00180
00181
00182
00183 imu_raw_pub.publish(imu_msg);
00184 imu_mag_pub.publish(m);
00185
00186
00187
00188
00189
00190
00191
00192
00193 }
00194
00195 int main(int argc, char **argv) {
00196
00197
00198 ros::init(argc, argv, "apm_driver");
00199
00200 ros::NodeHandle n;
00201
00202 n.param("GPS_frame_id", gps_frame_id, std::string("/map"));
00203
00204 ros::Subscriber adc_sub = n.subscribe("apm_adc", 10, adcCallback);
00205 ros::Subscriber imu_sub = n.subscribe("apm_imu", 10, imuCallback);
00206 ros::Subscriber gps_sub = n.subscribe("apm_gps", 10, gpsCallback);
00207
00208 imu_raw_pub = n.advertise < sensor_msgs::Imu > ("imu/data_raw", 10);
00209 imu_mag_pub = n.advertise < geometry_msgs::Vector3Stamped > ("imu/mag", 10);
00210
00211 us1_range_msg.header.frame_id = "/Right_US_link";
00212 us1_range_msg.field_of_view = 0.8;
00213 us1_range_msg.radiation_type = 0;
00214 us1_range_msg.min_range = 0.2;
00215 us1_range_msg.max_range = 6.5;
00216
00217 us2_range_msg.header.frame_id = "/Back_US_link";
00218 us2_range_msg.field_of_view = 0.8;
00219 us2_range_msg.radiation_type = 0;
00220 us2_range_msg.min_range = 0.2;
00221 us2_range_msg.max_range = 6.5;
00222
00223 us3_range_msg.header.frame_id = "/Left_US_link";
00224 us3_range_msg.field_of_view = 0.8;
00225 us3_range_msg.radiation_type = 0;
00226 us3_range_msg.min_range = 0.2;
00227 us3_range_msg.max_range = 6.5;
00228
00229 ir1_range_msg.header.frame_id = "/Right_IR_link";
00230 ir1_range_msg.field_of_view = 0.05;
00231 ir1_range_msg.radiation_type = 1;
00232 ir1_range_msg.min_range = 0.1;
00233 ir1_range_msg.max_range = 0.8;
00234
00235 ir2_range_msg.header.frame_id = "/Back_IR_link";
00236 ir2_range_msg.field_of_view = 0.05;
00237 ir2_range_msg.radiation_type = 1;
00238 ir2_range_msg.min_range = 0.1;
00239 ir2_range_msg.max_range = 0.8;
00240
00241 ir3_range_msg.header.frame_id = "/Left_IR_link";
00242 ir3_range_msg.field_of_view = 0.05;
00243 ir3_range_msg.radiation_type = 1;
00244 ir3_range_msg.min_range = 0.1;
00245 ir3_range_msg.max_range = 0.8;
00246
00247 us1_pub = n.advertise < sensor_msgs::Range > ("Rangers/Right_US", 5);
00248 us2_pub = n.advertise < sensor_msgs::Range > ("Rangers/Back_US", 5);
00249 us3_pub = n.advertise < sensor_msgs::Range > ("Rangers/Left_US", 5);
00250 ir1_pub = n.advertise < sensor_msgs::Range > ("Rangers/Right_IR", 5);
00251 ir2_pub = n.advertise < sensor_msgs::Range > ("Rangers/Back_IR", 5);
00252 ir3_pub = n.advertise < sensor_msgs::Range > ("Rangers/Left_IR", 5);
00253
00254 gps_pub = n.advertise < sensor_msgs::NavSatFix > ("gps_publish", 5);
00255
00256 pc_bat_pub = n.advertise < std_msgs::Float32 > ("pc_bat", 5);
00257
00258
00259
00260 ros::spin();
00261
00262 return 0;
00263 }
00264