这个是鉴于另一个Github上的项目学习的

https://github.com/chaoli2/rviz_teleop_commander/tree/master/src

其中代码注释很清楚,大家也可以去看源代码

首先是CmakeList.txt文件

cmake_minimum_required(VERSION 2.8.3)

project(bing_pannel)

find_package(catkin REQUIRED COMPONENTS rviz)

catkin_package()

include_directories(${catkin_INCLUDE_DIRS})

link_directories(${catkin_LIBRARY_DIRS})set(CMAKE_AUTOMOC ON)if(rviz_QT_VERSION VERSION_LESS "5")

message(STATUS"Using Qt4 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")

find_package(Qt4 ${rviz_QT_VERSION} EXACT REQUIRED QtCore QtGui)

include(${QT_USE_FILE})else()

message(STATUS"Using Qt5 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")

find_package(Qt5 ${rviz_QT_VERSION} EXACT REQUIRED Core Widgets)set(QT_LIBRARIES Qt5::Widgets)

endif()

add_definitions(-DQT_NO_KEYWORDS)set(SOURCE_FILES

src/bing_pannel.cpp ##这里是你的主文件

${MOC_FILES}

)

add_library(${PROJECT_NAME} ${SOURCE_FILES})

target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${catkin_LIBRARIES})

install(TARGETS

${PROJECT_NAME}

ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}

LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}

RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

)

install(FILES

plugin_discription.xml ##这里是你的plugin_discription.xml

DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

只要在workspace下catkin_make后,这个包里的插件便直接安装了。package.xml文件应该如下:

bing_pannel

0.0.0

The bing_pannel package

bing

TODO

catkin

roscpp

rviz

std_msgs

roscpp

rviz

std_msgs

而真正描述的plugin_discription.xml为如下:

Bing test pannel.

中name中的bing_pannel/BingPannel里,写的是package的名字加class

type中是namespace加class名。

我们在src文件夹下加入bing_pannel.cpp和bing_pannel.h。这个package的文件夹如下。

我们先看.h文件。

#ifndef BING_PANNEL_H#define BING_PANNEL_H#include#include#include

classQLineEdit;namespacebing_rviz_plugin

{class BingPannel: publicrviz::Panel

{

Q_OBJECTpublic:

BingPannel( QWidget* parent = 0);virtual void load( const rviz::Config&config );virtual void save( rviz::Config config ) const;publicQ_SLOTS:void setTopic( const QString&topic );protectedQ_SLOTS:voidsendVel();voidupdate_Linear_Velocity();voidupdate_Angular_Velocity();voidupdateTopic();protected:

QLineEdit*output_topic_editor_;

QString output_topic_;

QLineEdit*output_topic_editor_1;

QString output_topic_1;

ros::Publisher velocity_publisher_;

ros::NodeHandle nh_;floatlinear_velocity_;

};

}#endif

头文件中,rviz/panel.h 就是 pannel头文件。插件显示如下图。在rviz中加入pannel的话,要在标题栏中,找到Panels 〉Add New Panel。选择并加入需要的pannel。

选择添加的Pannel。

我们这里的插件会通过文本框里的输入发送一个输入的Topic名字的消息。在后面需要填写速度X和速度Y,并且回车就可以发布消息了。

回车后,rostopic list会显示/test_velocity。我们这里发布的是geometry_msgs::Twist。

下面我们的代码,里面是.h文件。

#ifndef BING_PANNEL_H#define BING_PANNEL_H#include#include#include

classQLineEdit;namespacebing_rviz_plugin

{class BingPannel: publicrviz::Panel

{

Q_OBJECTpublic:

//用QWigdet的实例来实现GUI界面

BingPannel( QWidget* parent = 0);virtual void load( const rviz::Config&config );virtual void save( rviz::Config config ) const;publicQ_SLOTS:

//当填写完时候,回车后,执行会调函数void setTopic( const QString&topic );protectedQ_SLOTS:voidsendVel();voidupdate_Linear_Velocity_X();voidupdate_Linear_Velocity_Y();voidupdateTopic();protected:

//这里是三个显示的文字框的定义

QLineEdit*output_topic_editor_;

QString output_topic_;

QLineEdit*output_topic_editor_1;

QString output_topic_1;

QLineEdit*output_topic_editor_2;

QString output_topic_2;

//Ros消息发布

ros::Publisher velocity_publisher_;

ros::NodeHandle nh_;

//x速度,y速度floatlinear_velocity_X;floatlinear_velocity_Y;

};

}#endif

相应的.cpp文件如下:

#include #include#include#include#include#include#include#include#include#include"bing_pannel.h"

namespacebing_rviz_plugin{

BingPannel::BingPannel( QWidget* parent ): rviz::Panel( parent ), linear_velocity_X( 0 ),linear_velocity_Y( 0){

//topic窗口

QVBoxLayout* topic_layout = newQVBoxLayout;

topic_layout->addWidget( new QLabel( "Teleop Topic:"));

output_topic_editor_= newQLineEdit;

topic_layout->addWidget( output_topic_editor_ );

//xvelocity窗口

topic_layout->addWidget( new QLabel( "Linear Velocity X:"));

output_topic_editor_1= newQLineEdit;

topic_layout->addWidget( output_topic_editor_1 );

//yvelocity窗口

topic_layout->addWidget( new QLabel( "Linear Velocity Y:"));

output_topic_editor_2= newQLineEdit;

topic_layout->addWidget( output_topic_editor_2 );

QHBoxLayout* layout = newQHBoxLayout;

layout->addLayout( topic_layout );

setLayout( layout );

QTimer* output_timer = new QTimer( this);

//回车回调函数,设置信号连接

connect( output_topic_editor_, SIGNAL( editingFinished() ),this, SLOT( updateTopic() ));

connect( output_topic_editor_1, SIGNAL( editingFinished() ),this, SLOT( update_Linear_Velocity_X() ));

connect( output_topic_editor_1, SIGNAL( editingFinished() ),this, SLOT( update_Linear_Velocity_Y() ));

//定时器回调,定时运行sendVel()

connect( output_timer, SIGNAL( timeout() ),this, SLOT( sendVel() ));

output_timer->start( 100);

}

//读取x速度voidBingPannel::update_Linear_Velocity_X()

{

QString temp_string= output_topic_editor_1->text();float lin =temp_string.toFloat();

linear_velocity_X=lin;

}

//读取y速度voidBingPannel::update_Linear_Velocity_Y()

{

QString temp_string= output_topic_editor_2->text();float lin =temp_string.toFloat();

linear_velocity_Y=lin;

}

//更新topicvoidBingPannel::updateTopic()

{

setTopic( output_topic_editor_->text() );

}

//topic名字void BingPannel::setTopic( const QString&new_topic )

{if( new_topic !=output_topic_ )

{

output_topic_=new_topic;if( output_topic_ == "")

{

velocity_publisher_.shutdown();

}else{

velocity_publisher_= nh_.advertise<:twist>( output_topic_.toStdString(), 1);

}

Q_EMIT configChanged();

}

}voidBingPannel::sendVel()

{if( ros::ok() &&velocity_publisher_ )

{

geometry_msgs::Twist msg;

msg.linear.x=linear_velocity_X;

msg.linear.y=linear_velocity_Y ;

msg.linear.z= 0;

msg.angular.x= 0;

msg.angular.y= 0;

msg.angular.z= 1;

velocity_publisher_.publish( msg );

}

}void BingPannel::save( rviz::Config config ) const{

rviz::Panel::save( config );

config.mapSetValue("Topic", output_topic_ );

}void BingPannel::load( const rviz::Config&config )

{

rviz::Panel::load( config );

QString topic;if( config.mapGetString( "Topic", &topic ))

{

output_topic_editor_->setText( topic );

updateTopic();

}

}

}

#includePLUGINLIB_EXPORT_CLASS(bing_rviz_plugin::BingPannel,rviz::Panel )

保存后,catkin_make 就可以在rviz里找到了。

参考:

roszhong指定rviz的点启动_Rviz 实现 pannel 插件相关推荐

  1. roszhong指定rviz的点启动_怎样在1秒内启动 Linux

    欢迎关注我的头条号:Wooola,专注于Java.Golang.微服务架构,致力于每天分享原创文章.快乐编码和开源技术. 背景知识 系统从上电到完全启动,需要经过许多过程.一个简化的启动流程大概包含: ...

  2. 指定rviz的点启动_好消息!武汉已经启动新冠疫苗紧急接种工作

    新冠病毒形式皇冠而得名,其也是影响了全球,虽然能治愈,但是感染力和变异力强,自身产生的抗体无法识别.不过中国始终没有停止制造疫苗,美国制造疫苗是从信使RNA着手,而中国则以灭活的病毒为下手点,虽然比较 ...

  3. k8s minikube启动时指定镜像源的启动方式

    k8s minikube启动时指定镜像源的启动方式

  4. linux fedora35指定某个固定的启动项作为默认的启动项

    linux fedora35指定某个固定的启动项作为默认的启动项 修改符号链接/boot/grub2/grubenv同前,不知道不修改会怎样-- 修改/etc/default/grub同样是加入GRU ...

  5. 【内网安全-CS】Cobalt Strike启动运行上线方法插件

    前言: 介绍: 博主:网络安全领域狂热爱好者(承诺在CSDN永久无偿分享文章). 殊荣:CSDN网络安全领域优质创作者,2022年双十一业务安全保卫战-某厂第一名,某厂特邀数字业务安全研究员,edus ...

  6. 无法启动 parallels desktop 缺少插件_手机资讯:iOS7.1.2越狱插件推荐:CCSliders亮度滑动条变万能神器...

    如今使用IT数码设备的小伙伴们是越来越多了,那么IT数码设备当中是有很多知识的,这些知识很多小伙伴一般都是不知道的,就好比最近就有很多小伙伴们想要知道越狱插件推荐:CCSliders亮度滑动条变万能神 ...

  7. rviz可视化点云_rviz三维可视化平台的使用

    rviz三维可视化平台的使用 任务: 1.学习rviz并使用其显示地图数据. 2.保存地图数据,并且能够将地图重新加载. 完成情况: rviz是ROS针对机器人系统的可视化需求,提供给用户的一种可以显 ...

  8. Qt Creator中如何指定某个项目为启动项目

    当我使用Qt Creator时,常常开启多个项目以方便相互借鉴与改进,但调试运行时,想指定运行某个项目时怎么办呢?我们可以在Qt Creator IDE中,在左下角的显示器形状按钮中选择要运行的程序. ...

  9. Linux kernel编译、安装及指定默认内核版本启动

    内容转自: https://blog.csdn.net/weixin_41666796/article/details/96434229 https://blog.mtkfan.com/post-43 ...

最新文章

  1. 忽略这一点,人工智能变人工智障!
  2. linux面试题-基础题1
  3. Vue.js——60分钟组件快速入门(上篇)
  4. Linux学习之CentOS(三)----将Cent0S 7的网卡名称eno16777736改为eth0
  5. Error:-81024 LR_VUG:The 'QTWeb' type is not supported on win32 platforms
  6. ECS实践案例丨逻辑卷的创建和扩容操作指导
  7. 【LeetCode】剑指 Offer 11. 旋转数组的最小数字
  8. 【Spark】Spark kafka because consumer rebalance same group id joined different streaming
  9. 【java】动态高并发时为什么推荐重入锁而不是Synchronized?
  10. 【Vue2.0】— 组件的自定义事件(十八)
  11. 切片 里面包含interface_Golang的数组和切片
  12. mysql 字段加减_Mysql数据清洗—Null值的处理技巧
  13. VS工程下的tlb, tlh, tli文件说明(COM)
  14. 第一章 行列式 第六节 行列式按行(列)展开
  15. 核爆rpg学院站计算机,给新人的一点收集建议
  16. (PTA)数据结构(作业)11、树和图
  17. W10应用商店Microsoft Store的安装
  18. 【图像去噪】基于柯西近端分裂 (CPS) 算法实现图像去噪附MATLAB源代码
  19. 曼哈顿距离及其应用场景/曼哈顿距离与欧氏距离的不同
  20. 7个半月股价涨了40%多,DXC做对了什么?

热门文章

  1. SyntaxHighlighter示例源码[代码高亮]
  2. html+css+js 制作表白翻页相册
  3. obsidian移动端PC段同步
  4. python画八卦图的指令_12行javascript代码绘制一个八卦图
  5. 初学爬虫之试---爬取51笑话网站(源代码)
  6. PTA 7-56 365次方
  7. 串行传输和并行传输有什么区别?
  8. html5播放器怎么小窗播放器,悬浮画中画播放器插件,边工作边用小窗口看视频的摸鱼神器...
  9. 《缠中说禅108课》48:暴跌,牛市行情的一夜Q
  10. 2022 BUAA 软工第二次作业