ROS数据可视化rviz简明笔记

https://www.cnblogs.com/shangchele/p/7328473.html

ROS数据可视化rviz简明笔记

----

 

  1. 标记:发送基本形状(C ++)

    显示如何使用visualization_msgs / Marker消息将基本形状(立方体,球体,圆柱体,箭头)发送到rviz。

  2. 标记:点和线(C ++)

    教导如何使用visualization_msgs / Marker消息将点和线发送到rviz。

  3. 交互式标记:入门

    本教程解释什么是交互式标记,并教你一些基本的概念。

  4. 交互式标记:编写简单的交互式标记服务器

    本教程介绍如何设置管理单个交互式标记的极简主义服务器。

  5. 交互式标记:基本控件

    本教程解释basic_controls教程代码如何工作。

  6. 插件:新显示类型

    如何编写一个插件,为RViz添加一个新的显示功能。

  7. 插件:新的可停靠面板

    如何编写一个插件,添加一个新类型的可停靠Panel小部件到RViz。

  8. 插件:新工具类型

    如何编写一个插件,为RViz添加一个新工具。

  9. Librviz:将RViz纳入自定义GUI

    如何使用RViz可视化窗口小部件编写应用程序。

  10. Rviz in Stereo

    教你如何设置Rviz在3D立体声渲染。

 


 

 

----

 

[html] view plaincopyprint?

  1. $ tree -L 3  
  2. .  
  3. ├── interactive_marker_tutorials  
  4. │   ├── CHANGELOG.rst  
  5. │   ├── CMakeLists.txt  
  6. │   ├── package.xml  
  7. │   ├── scripts  
  8. │   │   ├── basic_controls.py  
  9. │   │   ├── cube.py  
  10. │   │   ├── menu.py  
  11. │   │   └── simple_marker.py  
  12. │   └── src  
  13. │       ├── basic_controls.cpp  
  14. │       ├── cube.cpp  
  15. │       ├── menu.cpp  
  16. │       ├── point_cloud.cpp  
  17. │       ├── pong.cpp  
  18. │       ├── selection.cpp  
  19. │       └── simple_marker.cpp  
  20. ├── librviz_tutorial  
  21. │   ├── CHANGELOG.rst  
  22. │   ├── CMakeLists.txt  
  23. │   ├── package.xml  
  24. │   ├── rosdoc.yaml  
  25. │   └── src  
  26. │       ├── doc  
  27. │       ├── main.cpp  
  28. │       ├── myviz.cpp  
  29. │       └── myviz.h  
  30. ├── rviz_plugin_tutorials  
  31. │   ├── CHANGELOG.rst  
  32. │   ├── CMakeLists.txt  
  33. │   ├── icons  
  34. │   │   └── classes  
  35. │   ├── media  
  36. │   │   └── flag.dae  
  37. │   ├── package.xml  
  38. │   ├── plugin_description.xml  
  39. │   ├── rosdoc.yaml  
  40. │   ├── scripts  
  41. │   │   └── send_test_msgs.py  
  42. │   └── src  
  43. │       ├── doc  
  44. │       ├── drive_widget.cpp  
  45. │       ├── drive_widget.h  
  46. │       ├── flag.h  
  47. │       ├── imu_display.cpp  
  48. │       ├── imu_display.h  
  49. │       ├── imu_visual.cpp  
  50. │       ├── imu_visual.h  
  51. │       ├── plant_flag_tool.cpp  
  52. │       ├── plant_flag_tool.h  
  53. │       ├── teleop_panel.cpp  
  54. │       └── teleop_panel.h  
  55. ├── rviz_python_tutorial  
  56. │   ├── CHANGELOG.rst  
  57. │   ├── CMakeLists.txt  
  58. │   ├── config.myviz  
  59. │   ├── doc-src  
  60. │   │   ├── conf.py  
  61. │   │   ├── index.rst  
  62. │   │   ├── myviz.png  
  63. │   │   └── tutorialformatter.py  
  64. │   ├── myviz.py  
  65. │   ├── package.xml  
  66. │   └── rosdoc.yaml  
  67. ├── visualization_marker_tutorials  
  68. │   ├── CHANGELOG.rst  
  69. │   ├── CMakeLists.txt  
  70. │   ├── package.xml  
  71. │   └── src  
  72. │       ├── basic_shapes.cpp  
  73. │       └── points_and_lines.cpp  
  74. └── visualization_tutorials  
  75.     ├── CHANGELOG.rst  
  76.     ├── CMakeLists.txt  
  77.     └── package.xml  
  78.   
  79. 18 directories, 57 files  


 

 

----

1 标记:基本形状,点,线等

补充阅读:

1 DisplayTypes/Marker:http://wiki.ros.org/rviz/DisplayTypes/Marker 

2 rviz/UserGuide:http://wiki.ros.org/rviz/UserGuide

3 tf/tf2:http://wiki.ros.org/tf http://wiki.ros.org/tf2

代码解析等参考如下:

标记:发送基本形状(C ++)

标记:点和线(C ++)

使用命令和效果,如下:

$ rosrun visualization_marker_tutorials basic_shapes

在rviz中,添加Marker,修改Fixed Frame为my_frame,可见如下不断变化的基本图形:

    

    

$ rosrun visualization_marker_tutorials points_and_lines

    

 

----

2 交互式标记

这部分都分为C++和Python两种语言介绍。

    

这里需要注意,Fixed Frame为base_link等。

这里以simple_marker为例:

python:

 

[python] view plaincopyprint?

  1. import rospy  
  2.   
  3. from interactive_markers.interactive_marker_server import *  
  4. from visualization_msgs.msg import *  
  5.   
  6. def processFeedback(feedback):  
  7.     p = feedback.pose.position  
  8.     print feedback.marker_name + " is now at " + str(p.x) + ", " + str(p.y) + ", " + str(p.z)  
  9.   
  10. if __name__=="__main__":  
  11.     rospy.init_node("simple_marker")  
  12.       
  13.     # create an interactive marker server on the topic namespace simple_marker  
  14.     server = InteractiveMarkerServer("simple_marker")  
  15.       
  16.     # create an interactive marker for our server  
  17.     int_marker = InteractiveMarker()  
  18.     int_marker.header.frame_id = "base_link"  
  19.     int_marker.name = "my_marker"  
  20.     int_marker.description = "Simple 1-DOF Control"  
  21.   
  22.     # create a grey box marker  
  23.     box_marker = Marker()  
  24.     box_marker.type = Marker.CUBE  
  25.     box_marker.scale.x = 0.45  
  26.     box_marker.scale.y = 0.45  
  27.     box_marker.scale.z = 0.45  
  28.     box_marker.color.r = 0.0  
  29.     box_marker.color.g = 0.5  
  30.     box_marker.color.b = 0.5  
  31.     box_marker.color.a = 1.0  
  32.   
  33.     # create a non-interactive control which contains the box  
  34.     box_control = InteractiveMarkerControl()  
  35.     box_control.always_visible = True  
  36.     box_control.markers.append( box_marker )  
  37.   
  38.     # add the control to the interactive marker  
  39.     int_marker.controls.append( box_control )  
  40.   
  41.     # create a control which will move the box  
  42.     # this control does not contain any markers,  
  43.     # which will cause RViz to insert two arrows  
  44.     rotate_control = InteractiveMarkerControl()  
  45.     rotate_control.name = "move_x"  
  46.     rotate_control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS  
  47.   
  48.     # add the control to the interactive marker  
  49.     int_marker.controls.append(rotate_control);  
  50.   
  51.     # add the interactive marker to our collection &  
  52.     # tell the server to call processFeedback() when feedback arrives for it  
  53.     server.insert(int_marker, processFeedback)  
  54.   
  55.     # 'commit' changes and send to all clients  
  56.     server.applyChanges()  
  57.   
  58.     rospy.spin()  

 

 

C++:

 

[cpp] view plaincopyprint?

  1. #include <ros/ros.h>  
  2.   
  3. #include <interactive_markers/interactive_marker_server.h>  
  4.   
  5. void processFeedback(  
  6.     const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )  
  7. {  
  8.   ROS_INFO_STREAM( feedback->marker_name << " is now at "  
  9.       << feedback->pose.position.x << ", " << feedback->pose.position.y  
  10.       << ", " << feedback->pose.position.z );  
  11. }  
  12.   
  13. int main(int argc, char** argv)  
  14. {  
  15.   ros::init(argc, argv, "simple_marker");  
  16.   
  17.   // create an interactive marker server on the topic namespace simple_marker  
  18.   interactive_markers::InteractiveMarkerServer server("simple_marker");  
  19.   
  20.   // create an interactive marker for our server  
  21.   visualization_msgs::InteractiveMarker int_marker;  
  22.   int_marker.header.frame_id = "base_link";  
  23.   int_marker.header.stamp=ros::Time::now();  
  24.   int_marker.name = "my_marker";  
  25.   int_marker.description = "Simple 1-DOF Control";  
  26.   
  27.   // create a grey box marker  
  28.   visualization_msgs::Marker box_marker;  
  29.   box_marker.type = visualization_msgs::Marker::CUBE;  
  30.   box_marker.scale.x = 0.45;  
  31.   box_marker.scale.y = 0.45;  
  32.   box_marker.scale.z = 0.45;  
  33.   box_marker.color.r = 0.5;  
  34.   box_marker.color.g = 0.5;  
  35.   box_marker.color.b = 0.5;  
  36.   box_marker.color.a = 1.0;  
  37.   
  38.   // create a non-interactive control which contains the box  
  39.   visualization_msgs::InteractiveMarkerControl box_control;  
  40.   box_control.always_visible = true;  
  41.   box_control.markers.push_back( box_marker );  
  42.   
  43.   // add the control to the interactive marker  
  44.   int_marker.controls.push_back( box_control );  
  45.   
  46.   // create a control which will move the box  
  47.   // this control does not contain any markers,  
  48.   // which will cause RViz to insert two arrows  
  49.   visualization_msgs::InteractiveMarkerControl rotate_control;  
  50.   rotate_control.name = "move_x";  
  51.   rotate_control.interaction_mode =  
  52.       visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;  
  53.   
  54.   // add the control to the interactive marker  
  55.   int_marker.controls.push_back(rotate_control);  
  56.   
  57.   // add the interactive marker to our collection &  
  58.   // tell the server to call processFeedback() when feedback arrives for it  
  59.   server.insert(int_marker, &processFeedback);  
  60.   
  61.   // 'commit' changes and send to all clients  
  62.   server.applyChanges();  
  63.   
  64.   // start the ROS main loop  
  65.   ros::spin();  
  66. }  


--

 

可以比较一下,然后输入下面命令:

$ rosrun interactive_marker_tutorials simple_marker

    

 

  • 定义一个函数processFeedback,通过打印出位置来处理来自RViz的反馈消息。

  • 初始化roscpp。
  • 创建交互式标记服务器对象。
  • 设置交互式标记并将其添加到服务器的集合。
  • 输入ROS消息循环。

 

注意,当调用insert时,服务器对象将在内部只将新标记推入等待列表。一旦你调用applyChanges,它将它包含在它的公开可见的交互式标记集,并发送到所有连接的客户端。

 

$ rosrun interactive_marker_tutorials basic_controls

$ rosrun interactive_marker_tutorials menu

点击box会出现目录选项。

$ rosrun interactive_marker_tutorials pong

$ rosrun interactive_marker_tutorials cube

$ rosrun interactive_marker_tutorials selection

$ rosrun interactive_marker_tutorials point_cloud

欲了解具体实现,请参考源码~

----

3 插件

$ rosrun rviz_plugin_tutorials send_test_msgs.py

    

----

4 librviz

$ rosrun librviz_tutorial myviz 


  

----

补充:

http://wiki.ros.org/rviz/Tutorials

----

数学补充:

 

四元数说明:http://blog.csdn.net/candycat1992/article/details/41254799

欧拉角到四元数

 

给定一个欧拉旋转(X, Y, Z)(即分别绕x轴、y轴和z轴旋转X、Y、Z度),则对应的四元数为:

 

x = sin(Y/2)sin(Z/2)cos(X/2)+cos(Y/2)cos(Z/2)sin(X/2)

y = sin(Y/2)cos(Z/2)cos(X/2)+cos(Y/2)sin(Z/2)sin(X/2)

z = cos(Y/2)sin(Z/2)cos(X/2)-sin(Y/2)cos(Z/2)sin(X/2)

w = cos(Y/2)cos(Z/2)cos(X/2)-sin(Y/2)sin(Z/2)sin(X/2)

q = ((x, y, z), w)

 

它的证明过程可以依靠轴角到四元数的公式进行推导。

结合程序说明:

        locations['Goal'] = Pose(Point(1.4, 0.2, 0.000), Quaternion(0.000, 0.000, 0.7, 0.7))

        locations['Home'] = Pose(Point(0.0, 0.0, 0.000), Quaternion(0.000, 0.000, 0.0, 1.0))

 

如果Home为起点,那么Goal为Home前1.4m 左0.2米 并左转90度

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值