• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

ROS Qt5 librviz人机交互界面开发六(显示激光雷达点云数据)

人工智能 蒋程扬 2820次浏览 0个评论

一,实现效果:

ROS Qt5 librviz人机交互界面开发六(显示激光雷达点云数据)

二,核心代码

如果按照本人前几篇博客的话进程的话,就很容易实现这个功能了,主要就是用manager添加一个display:
核心代码:

//显示激光雷达
void QRviz::Display_LaserScan(bool enable,QString topic)
{
	if(laser_==NULL) {
		laser_=manager_->createDisplay("rviz/LaserScan","QLaser",enable);
		ROS_ASSERT(laser_);
		laser_->subProp("Topic")->setValue(topic);
	} else {
		delete laser_;
		laser_=manager_->createDisplay("rviz/LaserScan","QLaser",enable);
		ROS_ASSERT(laser_);
		laser_->subProp("Topic")->setValue(topic);
	}
	qDebug()<<"topic:"<<topic;
	laser_->setEnabled(enable);
	manager_->startUpdate();
}

 

qrviz.hpp

#ifndef QRVIZ_H
#define QRVIZ_H

#include <QVBoxLayout>
#include <rviz/visualization_manager.h>
#include <rviz/render_panel.h>
#include <rviz/display.h>
#include <rviz/tool_manager.h>
#include <rviz/visualization_manager.h>
#include <rviz/render_panel.h>
#include <rviz/display.h>
#include<rviz/tool_manager.h>
#include <rviz_visual_tools/rviz_visual_tools.h>
#include <QThread>
#include <QDebug>
class QRviz:public QThread
{
	Q_OBJECT
public:
	QRviz(QVBoxLayout *layout,QString node_name);
	void run();
	void createDisplay(QString display_name,QString topic_name);
//显示Grid
	void Display_Grid(bool enable,QString Reference_frame,int Plan_Cell_count,QColor color=QColor(125,125,125));
//显示map
	void Display_Map(bool enable,QString topic,double Alpha,QString Color_Scheme);
//设置全局显示属性
	void SetGlobalOptions(QString frame_name,QColor backColor,int frame_rate);
//显示激光雷达点云
	void Display_LaserScan(bool enable,QString topic);

private:
	rviz::RenderPanel *render_panel_;
	rviz::VisualizationManager *manager_;
	rviz::Display* grid_=NULL ;
	rviz::Display* map_=NULL ;
	rviz::Display* laser_=NULL ;
	QVBoxLayout *layout;
	QString nodename;

// rviz::VisualizationManager *manager_=NULL;
// rviz::RenderPanel *render_panel_;

};

#endif // QRVIZ_H

 

qrviz.cpp

#include "../include/cyrobot_monitor/qrviz.hpp"

QRviz::QRviz(QVBoxLayout *layout,QString node_name)
{
	int argc;
	char **argv;
	this->layout=layout;
	this->nodename=node_name;
	ros::init(argc,argv,"QRviz",ros::init_options::AnonymousName);
//创建rviz容器
	render_panel_=new rviz::RenderPanel;
//向layout添加widget
	layout->addWidget(render_panel_);
//初始化rviz控制对象
	manager_=new rviz::VisualizationManager(render_panel_);
//初始化camera 这行代码实现放大 缩小 平移等操作
	render_panel_->initialize(manager_->getSceneManager(),manager_);

// //工具管理
// rviz::ToolManager* tool_man;
// connect( tool_man, SIGNAL( toolAdded( Tool* )), this, SLOT( addTool( Tool* )));
// connect( tool_man, SIGNAL( toolRemoved( Tool* )), this, SLOT( removeTool( Tool* )));
// connect( tool_man, SIGNAL( toolRefreshed( Tool* )), this, SLOT( refreshTool( Tool* )));
// connect( tool_man, SIGNAL( toolChanged( Tool* )), this, SLOT( indicateToolIsCurrent( Tool* )));
	manager_->initialize();
	manager_->removeAllDisplays();

}
//显示grid
void QRviz::Display_Grid(bool enable,QString Reference_frame,int Plan_Cell_count,QColor color)
{
	if(grid_==NULL) {
		grid_ = manager_->createDisplay( "rviz/Grid", "adjustable grid", true );
		ROS_ASSERT( grid_ != NULL );
// Configure the GridDisplay the way we like it.
		grid_->subProp( "Line Style" )->setValue("Billboards");
		grid_->subProp( "Color" )->setValue(color);
		grid_->subProp( "Reference Frame" )->setValue(Reference_frame);
		grid_->subProp("Plane Cell Count")->setValue(Plan_Cell_count);

	} else {
		delete grid_;
		grid_ = manager_->createDisplay( "rviz/Grid", "adjustable grid", true );
		ROS_ASSERT( grid_ != NULL );
// Configure the GridDisplay the way we like it.
		grid_->subProp( "Line Style" )->setValue("Billboards");
		grid_->subProp( "Color" )->setValue(color);
		grid_->subProp( "Reference Frame" )->setValue(Reference_frame);
		grid_->subProp("Plane Cell Count")->setValue(Plan_Cell_count);
	}
	grid_->setEnabled(enable);
	manager_->startUpdate();
}
//显示map
void QRviz::Display_Map(bool enable,QString topic,double Alpha,QString Color_Scheme)
{
	if(!enable&&map_) {
		map_->setEnabled(false);
		return ;
	}
	if(map_==NULL) {
		map_=manager_->createDisplay("rviz/Map","QMap",true);

		ROS_ASSERT(map_);
		map_->subProp("Topic")->setValue(topic);
		map_->subProp("Alpha")->setValue(Alpha);
		map_->subProp("Color Scheme")->setValue(Color_Scheme);
	} else {
		ROS_ASSERT(map_);
		qDebug()<<"asdasdasd:"<<topic<<Alpha;

		delete map_;
		map_=manager_->createDisplay("rviz/Map","QMap",true);
		ROS_ASSERT(map_);
		map_->subProp("Topic")->setValue(topic);
		map_->subProp("Alpha")->setValue(Alpha);
		map_->subProp("Color Scheme")->setValue(Color_Scheme);
	}

	map_->setEnabled(enable);
	manager_->startUpdate();
}
//显示激光雷达
void QRviz::Display_LaserScan(bool enable,QString topic)
{
	if(laser_==NULL) {
		laser_=manager_->createDisplay("rviz/LaserScan","QLaser",enable);
		ROS_ASSERT(laser_);
		laser_->subProp("Topic")->setValue(topic);
	} else {
		delete laser_;
		laser_=manager_->createDisplay("rviz/LaserScan","QLaser",enable);
		ROS_ASSERT(laser_);
		laser_->subProp("Topic")->setValue(topic);
	}
	qDebug()<<"topic:"<<topic;
	laser_->setEnabled(enable);
	manager_->startUpdate();
}
//设置全局显示
void QRviz::SetGlobalOptions(QString frame_name,QColor backColor,int frame_rate)
{
	manager_->setFixedFrame(frame_name);
	manager_->setProperty("Background Color",backColor);
	manager_->setProperty("Frame Rate",frame_rate);
	manager_->startUpdate();
}
void QRviz::createDisplay(QString display_name,QString topic_name)
{


}
void QRviz::run()
{

}

 

三,完整开源项目

在我自己学习的过程中目前发现没有相关类似完整开源项目,为了帮助其他人少走弯路,我决定将自己的完整项目开源:
github

转载自:

蒋程扬的部落格


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明ROS Qt5 librviz人机交互界面开发六(显示激光雷达点云数据)
喜欢 (0)

您必须 登录 才能发表评论!

加载中……