00001 #include <iostream>
00002 #include "ros/ros.h"
00003 #include "sensor_msgs/PointCloud2.h"
00004 #include "sensor_msgs/NavSatFix.h"
00005 #include "sensor_msgs/MagneticField.h"
00006 #include "sensor_msgs/Imu.h"
00007 #include "sensor_msgs/JointState.h"
00008 #include "nav_msgs/Odometry.h"
00009 #include "laser_transform_core.h"
00010 #include "octomap_msgs/BoundingBoxQuery.h"
00011
00012 using std::string;
00013
00014 int main (int argc, char **argv)
00015 {
00016 ros::init(argc, argv, "laser_transform");
00017 ros::NodeHandle n;
00018
00019
00020 int rate;
00021 int imu_convergence_speed;
00022 bool imu_msgs;
00023 bool mf_msgs;
00024 bool gps_msgs;
00025 bool odo_msgs;
00026 bool bounding_box;
00027 bool checkConvergenceSpeed = false;
00028 string pcl_in_topic;
00029 string pcl_out_topic;
00030 string mf_topic;
00031 string imu_topic;
00032 string gps_topic;
00033 string odo_topic;
00034 string odo_topic_filtered;
00035 XmlRpc::XmlRpcValue v;
00036
00037
00038 LaserTransform *node_lt = new LaserTransform();
00039
00040
00041 ros::NodeHandle private_node_handle_("~");
00042 private_node_handle_.param("rate", rate, int(10));
00043 private_node_handle_.param("mf_msgs", mf_msgs, bool(false));
00044 private_node_handle_.param("imu_msgs", imu_msgs, bool(true));
00045 private_node_handle_.param("gps_msgs", gps_msgs, bool(false));
00046 private_node_handle_.param("odo_msgs", odo_msgs, bool(true));
00047 private_node_handle_.param("pcl_in_topic", pcl_in_topic, string("/cloud"));
00048 private_node_handle_.param("pcl_out_topic", pcl_out_topic, string("/cloud_world"));
00049 private_node_handle_.param("mf_topic", mf_topic, string("magnetic/data"));
00050 private_node_handle_.param("imu_topic", imu_topic, string("/imu/data"));
00051 private_node_handle_.param("gps_topic", gps_topic, string("/gps/fix"));
00052 private_node_handle_.param("odo_topic", odo_topic, string("odom"));
00053 private_node_handle_.param("odo_filtered", odo_topic_filtered, string("/odometry/filtered"));
00054 private_node_handle_.param("imu_convergence_speed", imu_convergence_speed, int(20));
00055 private_node_handle_.param("laser_pose", v, v);
00056 private_node_handle_.param("bounding_box", bounding_box, bool(false));
00057
00058 if (v.valid())
00059 {
00060 if (v.size() == 6 && v.getType() == XmlRpc::XmlRpcValue::TypeArray)
00061 {
00062 node_lt->setLaserPose(static_cast<double>(v[0]), static_cast<double>(v[1]),
00063 static_cast<double>(v[2]), static_cast<double>(v[3]), static_cast<double>(v[4]),
00064 static_cast<double>(v[5]));
00065 }
00066 else
00067 {
00068 node_lt->setLaserPose(0.0,0.0,0.0,0.0,0.0,0.0);
00069 }
00070 }
00071 else
00072 {
00073 node_lt->setLaserPose(0.0,0.0,0.0,0.0,0.0,0.0);
00074 }
00075
00076 ros::Rate r(rate);
00077
00078
00079 ros::Subscriber sub_pcl = n.subscribe(pcl_in_topic.c_str(), 1000, &LaserTransform::callbackPcl, node_lt);
00080
00081
00082 ros::Subscriber sub_odo = n.subscribe(odo_topic_filtered.c_str(), 1000, &LaserTransform::callbackOdometryFiltered, node_lt);
00083
00084
00085 ros::Publisher pcl_pub = n.advertise<sensor_msgs::PointCloud2>(pcl_out_topic.c_str(), 50);
00086 node_lt->setPclPublisher(&pcl_pub);
00087
00088
00089 ros::Publisher mf_pub = n.advertise<sensor_msgs::MagneticField>(mf_topic.c_str(), 50);
00090
00091
00092 ros::Publisher imu_pub = n.advertise<sensor_msgs::Imu>(imu_topic.c_str(), 50);
00093
00094
00095 ros::Publisher gps_pub = n.advertise<sensor_msgs::NavSatFix>(gps_topic.c_str(), 50);
00096
00097
00098 ros::Publisher odo_pub = n.advertise<nav_msgs::Odometry>(odo_topic.c_str(),50);
00099
00100
00101 r.sleep();
00102 ros::ServiceClient client = n.serviceClient<octomap_msgs::BoundingBoxQuery>("/octomap_server_node/clear_bbx");
00103
00104 node_lt->setImuConvergenceSpeed(imu_convergence_speed);
00105
00106 node_lt->init();
00107
00108
00109 while (n.ok())
00110 {
00111 if (checkConvergenceSpeed)
00112 node_lt->checkConvergenceSpeed();
00113 if (imu_msgs)
00114 node_lt->publishImuMessage(&imu_pub);
00115 if (gps_msgs)
00116 node_lt->publishNavSatFixMessage(&gps_pub);
00117 if (mf_msgs)
00118 node_lt->publishMagneticFieldMessage(&mf_pub);
00119 if (odo_msgs)
00120 node_lt->publishOdometryMessage(&odo_pub);
00121 if (bounding_box)
00122 node_lt->clearOctomap(&client);
00123 ros::spinOnce();
00124 r.sleep();
00125 }
00126
00127 return 0;
00128 }