Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <sensor_msgs/PointCloud2.h>
00003 #include <pcl_ros/point_cloud.h>
00004 #include <pcl/point_cloud.h>
00005 #include <pcl/point_types.h>
00006
00007 #include <hrl_ellipsoidal_control/EllipsoidParams.h>
00008
00009 #include <hrl_ellipsoidal_control/ellipsoid_space.h>
00010
00011 typedef pcl::PointXYZRGB PRGB;
00012 typedef pcl::PointCloud<PRGB> PCRGB;
00013
00014 void sampleEllipse(double A, double B, double height, PCRGB::Ptr& pc);
00015 void publishEllipsoid(hrl_ellipsoidal_control::EllipsoidParams::ConstPtr e_params);
00016
00017 ros::Publisher pub_pc;
00018
00019 void sampleEllipse(double A, double B, double height, PCRGB::Ptr& pc)
00020 {
00021 bool is_prolate;
00022 ros::param::param<bool>("~is_prolate", is_prolate, true);
00023 Ellipsoid e(A, B, is_prolate);
00024 double lat, lon;
00025 int numlat = 8, numlon = 16;
00026 lat = (is_prolate) ? 0 : -PI/2;
00027 for(int i=0;i<numlat;i++) {
00028 lon = (is_prolate) ? 0 : -PI;
00029 lat += PI / numlat;
00030 for(int j=0;j<600;j++) {
00031 lon += 2 * PI / 600;
00032 PRGB pt;
00033 ((uint32_t*) &pt.rgb)[0] = 0xffffffff;
00034 double x, y, z;
00035 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00036 pt.x = x; pt.y = y; pt.z = z;
00037 pc->points.push_back(pt);
00038 }
00039 }
00040 lon = (is_prolate) ? 0 : -PI;
00041 for(int i=0;i<numlon;i++) {
00042 lat = (is_prolate) ? 0 : -PI/2;
00043 lon += 2 * PI / numlon;
00044 for(int j=0;j<600;j++) {
00045 lat += PI / 600;
00046 PRGB pt;
00047 ((uint32_t*) &pt.rgb)[0] = 0xffffffff;
00048 double x, y, z;
00049 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00050 pt.x = x; pt.y = y; pt.z = z;
00051 pc->points.push_back(pt);
00052 }
00053 }
00054 }
00055
00056 void publishEllipsoid(hrl_ellipsoidal_control::EllipsoidParams::ConstPtr e_params)
00057 {
00058 PCRGB::Ptr pc(new PCRGB());
00059 double A = 1;
00060 double E = e_params->E;
00061 double B = sqrt(1 - SQ(E));
00062 sampleEllipse(A, B, e_params->height, pc);
00063 pc->header.frame_id = "/ellipse_frame";
00064 pc->header.stamp = ros::Time::now();
00065 pub_pc.publish(pc);
00066 }
00067
00068 int main(int argc, char **argv)
00069 {
00070 ros::init(argc, argv, "ellipsoid_visualizer");
00071 ros::NodeHandle nh;
00072
00073 pub_pc = nh.advertise<sensor_msgs::PointCloud2>(argv[1], 1);
00074 ros::Subscriber sub_e_params = nh.subscribe("/ellipsoid_params", 1, &publishEllipsoid);
00075
00076 ros::spin();
00077 return 0;
00078 }