Rviz教程(四):Interactive Markers: Getting Started

Interactive Markers: Getting Started

Description:  This tutorial explains what Interactive Marker are and teaches you some of the basic concepts.

Tutorial Level:  BEGINNER

Next Tutorial:   Interactive Markers: Writing a Simple Interactive Marker Server  

Intro

Interactive markers are similar to the "regular" markers described in the previous tutorials, however they allow the user to interact with them by changing their position or rotation, clicking on them or selecting something from a context menu assigned to each marker.

They are represented by the visualization_msgs/InteractiveMarker message, which contains a context menu and several controls (visualization_msgs/InteractiveMarkerControl). The controls define the different visual parts of the interactive marker, can consist of several regular markers (visualization_msgs/Marker) and can each have a different function.

The structure of an <<MsgLink(visualization_msgs/InteractiveMarker)>> message

If you want to create a node providing a set of interactive markers, you need to instantiate an InteractiveMarkerServerobject. This will handle the connection to the client (usually RViz) and make sure that all changes you make are being transmitted and that your application is being notified of all the actions the user performs on the interactive markers.

interactive_marker_architecture.png

Further Documentation

To find out more about how to use interactive markers, refer to this and the following tutorials. The source code used can be found in the interactive_marker_tutorials package.

For writing applications using interactive markers, you will most likely use the interfaces provided in the interactive_markerspackage. Refer to the Code API for more information.

The messages used to describe interactive markers themselves contain a detailed description of all their parameters. Of main interest are visualization_msgs/InteractiveMarkervisualization_msgs/InteractiveMarkerControl and visualization_msgs/InteractiveMarkerFeedback. The recommended way to create context menus is using the MenuHandler interface, so you will not have to deal with the underlying messages.

The interactive_marker_tutorials Package

The best way to understand what interactive markers do is by trying out the examples contained in the interactive_marker_tutorials package. It contains five examples: simple_markerbasic_controlsmenupong and cube.

How To Run The Tutorials

The procedure to run the tutorials is basically the same in all case. E.g. to run basic_controls, open a terminal and type

rosrun interactive_marker_tutorials basic_controls

This will start the node which contains the interactive marker server. Then, start RViz by running the following command in a separate terminal:

rosrun rviz rviz

In RViz, do the following:

  • Set the fixed frame to '/base_link'.
  • Add an 'Interactive Markers' display by clicking on 'Add' in the 'Displays' panel.

  • Set the update topic of this display to '/basic_controls/update'. This should immediately bring up several grey cubes in rviz.

  • Now select 'Interact' in the tool panel. This will enable all interactive elements in the main view, which will bring up additional arrows and rings around the boxes. You can left-click on these controls and in some case on the box itself to change the pose of each interactive marker. Some markers have a context menu which you can access by right-clicking on them.

  • Add a 'Grid' display. This is a useful visual clue for perceiving how the markers move in space while you drag them.

simple_marker

Code (C++): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/src/simple_marker.cpp

Code (Python) https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/scripts/simple_marker.py

This example will display a minimalist marker in RViz. See Writing a Simple Interactive Marker Server for more details.

simple_marker.png

basic_controls

Code (C++): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/src/basic_controls.cpp

Code (Python): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/scripts/basic_controls.py

Displays a selection of interactive markers that can be manipulated in different ways. It is explained in more detail in the Basic Controls tutorial.

basic_controls.png

Code (C++): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/src/menu.cpp

Code (Python): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/scripts/menu.py

Shows how to manage a more complex context menu associated with an interactive marker, including hiding entries and adding check boxes.

menu.png

pong

Code (C++): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/src/pong.cpp

Lets you play the classic arcade game with one or two players in rviz. It is meant to distract you from your work- demonstrate the two-way interaction between an interactive marker server and multiple clients.

If you open two instances of RViz on different computers that are connected to the same pong server, you can play against each other. Otherwise, the computer will take control of the unused paddle.

pong.png

cube

Code (C++): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/src/cube.cpp

Code (Python): https://github.com/ros-visualization/visualization_tutorials/blob/indigo-devel/interactive_marker_tutorials/scripts/cube.py

Demonstrates how to procedurally create and manage a large number of interactive markers.

cube.png

[rviz2-20] [ERROR] [1751273079.904134286] [rviz2]: PluginlibFactory: The plugin for class 'grid_map_rviz_plugin/GridMap' failed to load. Error: According to the loaded plugin descriptions the class grid_map_rviz_plugin/GridMap with base class type rviz_common::Display does not exist. Declared types are autoware_auto_perception_rviz_plugin/DetectedObjects autoware_auto_perception_rviz_plugin/PredictedObjects autoware_auto_perception_rviz_plugin/TrackedObjects rviz_default_plugins/AccelStamped rviz_default_plugins/Axes rviz_default_plugins/Camera rviz_default_plugins/DepthCloud rviz_default_plugins/Effort rviz_default_plugins/FluidPressure rviz_default_plugins/Grid rviz_default_plugins/GridCells rviz_default_plugins/Illuminance rviz_default_plugins/Image rviz_default_plugins/InteractiveMarkers rviz_default_plugins/LaserScan rviz_default_plugins/Map rviz_default_plugins/Marker rviz_default_plugins/MarkerArray rviz_default_plugins/Odometry rviz_default_plugins/Path rviz_default_plugins/PointCloud rviz_default_plugins/PointCloud2 rviz_default_plugins/PointStamped rviz_default_plugins/Polygon rviz_default_plugins/Pose rviz_default_plugins/PoseArray rviz_default_plugins/PoseWithCovariance rviz_default_plugins/Range rviz_default_plugins/RelativeHumidity rviz_default_plugins/RobotModel rviz_default_plugins/TF rviz_default_plugins/Temperature rviz_default_plugins/TwistStamped rviz_default_plugins/Wrench rviz_plugins/AccelerationMeter rviz_plugins/ConsoleMeter rviz_plugins/Float32MultiArrayStampedPieChart rviz_plugins/MaxVelocity rviz_plugins/MrmSummaryOverlayDisplay rviz_plugins/Path rviz_plugins/PathWithLaneId rviz_plugins/PolarGridDisplay rviz_plugins/PoseWithUuidStamped rviz_plugins/SteeringAngle rviz_plugins/Trajectory rviz_plugins/TurnSignal rviz_plugins/VelocityHistory rviz_plugins::PoseHistory rviz_plugins::PoseHistoryFootprint
最新发布
07-01
<think>我们正在解决rviz2中GridMap插件加载失败的问题。根据错误信息“PluginlibFactory:GridMapplugin loaderror”,这通常与插件未正确安装、依赖缺失或配置问题有关。参考站内引用中提到的插件加载错误案例,我们可以总结一些常见解决步骤:1.确保插件已正确安装(参考引用[1]和[3]中提到的插件安装问题)2.检查依赖项是否满足(参考引用[1]中提到的依赖问题)3.清除缓存并重新构建(参考引用[2]中的快速解决方案)4.检查环境变量和路径设置(参考引用[1]中关于平台插件的路径设置)具体到rviz2的GridMap插件,我们可以按照以下步骤排查:步骤1:确认GridMap插件已安装在ROS2中,GridMap插件通常由`grid_map_rviz_plugin`包提供。请确保已通过apt或源码安装该包。例如,在Ubuntu上,可以尝试安装:sudo aptinstall ros-<distro>-grid-map-rviz-plugin请将`<distro>`替换为你的ROS2发行版名称(如foxy、galactic、humble等)。步骤2:检查插件是否被正确加载运行以下命令查看rviz2的插件列表,确认GridMap插件是否在其中:ros2 runrviz2 rviz2--display-config/path/to/config.rviz或者在rviz2启动后,在“Add”面板中查看是否有GridMap相关的显示类型。步骤3:检查依赖项确保GridMap相关的ROS2包已正确安装,包括`grid_map_core`、`grid_map_ros`等。如果从源码构建,请确保这些包在同一个工作空间中,并且已经构建。步骤4:清除缓存并重新构建如果是从源码构建,尝试清除构建文件夹并重新构建:rm-rfbuild installlogcolcon build--symlink-install步骤5:检查环境变量确保环境变量设置正确,特别是`LD_LIBRARY_PATH`和`ROS_PACKAGE_PATH`。在ROS2中,通常通过`sourceinstall/setup.bash`来设置环境。步骤6:查看日志运行rviz2时,查看终端输出是否有更详细的错误信息。例如:ros2run rviz2rviz2如果上述步骤无法解决,可能需要查看插件的具体实现或寻求社区帮助。根据引用[4]中提到的插件初始化错误,有时插件本身在初始化过程中可能会失败,这可能需要检查插件的代码或配置文件。生成相关问题:1.如何安装ROS2的GridMap插件?2.如何查看rviz2已加载的插件列表?3.如何从源码构建GridMap插件?4.在ROS2中,如何解决插件加载失败的一般性问题?</think>### rviz2 GridMap插件加载失败解决方案 当在rviz2中遇到`PluginlibFactory: GridMap plugin load error`错误时,通常由以下原因引起: #### 1. **插件未正确安装** - **检查安装**:确认已安装`grid_map_rviz_plugin`包: ```bash sudo apt install ros-<distro>-grid-map-rviz-plugin ``` 将`<distro>`替换为你的ROS 2发行版(如`humble`、`foxy`)。若从源码构建,确保在`colcon build`时包含该包[^1]。 #### 2. **依赖缺失** - **关键依赖**:GridMap插件依赖`grid_map_core`和`grid_map_ros`。验证安装: ```bash sudo apt install ros-<distro>-grid-map-core ros-<distro>-grid-map-ros ``` - **链接库路径**:检查动态链接库路径是否包含插件: ```bash echo $LD_LIBRARY_PATH | grep grid_map ``` #### 3. **环境配置问题** - **工作空间激活**:若从源码构建,每次打开新终端需激活工作空间: ```bash source install/setup.bash ``` - **插件描述文件**:确认`grid_map_rviz_plugin.xml`存在于: ``` /opt/ros/<distro>/share/grid_map_rviz_plugin/plugin_description.xml ``` #### 4. **缓存冲突** - **清除缓存**:删除rviz2的本地配置缓存: ```bash rm ~/.local/share/rviz/* ``` - **重建索引**:强制重新加载插件: ```bash rosclean purge # 谨慎使用,会删除所有ROS日志 ``` #### 5. **版本兼容性** - **检查兼容性**:确认`grid_map_rviz_plugin`版本与ROS 2发行版匹配。例如: - ROS 2 Humble → `grid_map_rviz_plugin` ≥ 1.6.4 - **源码编译**:若版本不匹配,从源码编译: ```bash git clone https://github.com/ANYbotics/grid_map.git colcon build --packages-select grid_map_rviz_plugin ``` #### 6. **调试输出** 启动rviz2时启用详细日志: ```bash export RVIZ_LOGLEVEL=DEBUG ros2 run rviz2 rviz2 ``` 查看输出中是否有`ClassLoader`相关的加载错误线索。 --- ### 验证步骤 1. 检查插件是否在列表中: ```bash ros2 run rviz2 rviz2 --display-config /tmp/test.rviz # 在GUI中查看"Add"面板是否有"GridMap"选项 ``` 2. 通过命令行验证: ```bash ros2 plugin info grid_map_rviz_plugin/GridMapDisplay ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值