ROS点云数据显示

13 篇文章 1 订阅
3 篇文章 0 订阅
  • 创建工程
    首先,我们创建ROS Package,假设,我们创建的名为wb_serial。接下来打开src下的main.cpp文件,添加节点代码和发布点云数据代码。这里我们截取了两段:
    第一段:创建节点
//初始化节点 
ros::init(argc, argv, "lbwb_ladar"); 
//声明节点句柄 
ros::NodeHandle nh; 
// 发布话题
//ros::Publisher read_pub = nh.advertise<std_msgs::String>("lbwb_data", 1000); 
ros::Publisher lbwb_pub_0 = nh.advertise<sensor_msgs::PointCloud>("lbwb_pointer", 1000);

第二段:发布点云数据

// 点云
if (data->detecte_objs != NULL)
{
	
	printf("num_detecte_obj: %d\n",data->num_detecte_obj);
	for (i = 0; i< data->num_detecte_obj; i++)
	{
		printf("speed: %f\n",data->detecte_objs[i].speed);
		printf("peak: %d \n",data->detecte_objs[i].peakval);
		printf("x: %f \n",data->detecte_objs[i].x);
		printf("y: %f \n",data->detecte_objs[i].y);
		printf(" \n\n");
	}
	// 发布点云数据
	num_points = data->num_detecte_obj;
	sensor_msgs::PointCloud cloud;
	cloud.header.stamp = ros::Time::now();
	cloud.header.frame_id = "sensor_pointer";
	cloud.points.resize(num_points);
	// 
	cloud.channels.resize(2);
	cloud.channels[0].name = "peakval";
	cloud.channels[0].values.resize(num_points);
	cloud.channels[1].name = "speed";
	cloud.channels[1].values.resize(num_points);						
	// generate some fake data for our point cloud
	for(unsigned int i = 0; i < num_points; ++i){
		cloud.points[i].x = data->detecte_objs[i].x;
		cloud.points[i].y = data->detecte_objs[i].y;
		cloud.points[i].z = 5;
		cloud.channels[0].values[i] = data->detecte_objs[i].peakval;
		cloud.channels[1].values[i] = data->detecte_objs[i].speed;
	}
	lbwb_pub_0.publish(cloud);
}

然后,我们创建一个launch文件:

<?xml version="1.0"?>
<launch>
	<node name ="lbwb_ladar" pkg="wb_serial" type="lbwb_serial" output="screen"/>
</launch> 

至此,我们已经可以做下面的实验了,也有一些通用的操作,比如创建rviz文件。

  • 编译
    catkin_make
    如果没问题的话,我们就打开一个命令窗口输入:
~/catkin_ws$ roslaunch wb_serial lbwb_serial.launch

接下来,我们就可以在新的窗口运行一些ROS自带的工具,比如:rosnode,rosmsg, rostopic等等。
这里,我们直接通过Rviz查看点云数据,输入如下命令:

rosrun rviz rviz
或者
rosrun rviz rviz -d `rospack find wb_serial`/config/example9.rviz

打开Rviz界面之后,我们需要添加我们的点云数据,如下图所示:
在这里插入图片描述然后,我们需要设置几个参数,为了是传感器采集的数据在世界坐标系显示,首先,要知道以什么为基准。所以,在Global Options里将Fixed Frame填写我们自己的frame_id,也就是cloud.header.frame_id = “sensor_pointer”;,其次,我们需要修改PointCloud里的Topic为我们发布的主题, nh.advertise<sensor_msgs::PointCloud>(“lbwb_pointer”, 1000);。执行完上面操作,我们就能看到传感器的点云数据在Rviz的三维空间中显示。

  • ubuntu Ros log文件清理
    使用ROS期间,/home目录常常出现空间不足。
rosclean check
rosclean purge
// rosclean purge 是清理日志文件的哦!!!输入后输入y就能自动清理啦!
  • tf:transform,ROS中管理3D坐标系变换的工具
    static_transform_publisher is a command line tool for sending static transforms. 静态发布一个从父坐标系到子坐标系的一个坐标变换。
static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms

Publish a static coordinate transform to tf using an x/y/z offset in meters and yaw/pitch/roll in radians. (yaw is rotation about Z, pitch is rotation about Y, and roll is rotation about X). The period, in milliseconds, specifies how often to send a transform. 100ms (10hz) is a good value.

static_transform_publisher x y z qx qy qz qw frame_id child_frame_id  period_in_ms

Publish a static coordinate transform to tf using an x/y/z offset in meters and quaternion. The period, in milliseconds, specifies how often to send a transform. 100ms (10hz) is a good value.

static_transform_publisher is designed both as a command-line tool for manual use, as well as for use within roslaunch files for setting static transforms. For example:
<launch>
  <node pkg="tf" type="static_transform_publisher" name="link1_broadcaster" args="1 0 0 0 0 0 1 link1_parent link1 100" />
</launch>

值得一提的是:这个命令是发布静态坐标变换的,只能发布两个静止的坐标系间的坐标变换,而且,它是将坐标变换发布到tf中,剩下的由tf进行操作。

今天的分享就到这里,感觉受益的同学们请点个赞。

TF参考文章:https://blog.csdn.net/tiancailx/article/details/78910317
launch文件参考:https://www.cnblogs.com/zjiaxing/p/5542614.html
TF网站:http://www.guyuehome.com/279

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值