当前位置:   article > 正文

(四)添加rviz自定义插件_rviz 插件

rviz 插件

一、创建工作空间

选择【New Project】创建项目。

。 选择【其他项目】,选择【ROS Workspace】,点击【Choose...】按钮

 写入【Name:】名称,选择【Workspace Path:】工作空间路径,点击【下一步】按钮。

点击【完成】按钮,完成工作空间的创建。

 

二、添加自定义消息

1.创建消息包以及文件

在工作空间src下创建存放消息的包,右击【src】,选择【添加新文件...】。

 选择【ROS】,选择【Package】,点击【Choose...】按钮。

写入【Name:】名称,写入【Catkin:】依赖,消息依赖于 std_msgs和message_generation。

点击【完成】按钮。

 

 找到创建的消息包【plugin_msg】文件夹,在此新建文件夹,名称为【msg】,目录结构如下:

 

右击【msg】,选择【添加新文件...】。

 

 选择【ROS】,选中【Basic msg file】,点击【Choose...】按钮。

 写入【名称:】,点击【下一步】按钮。

点击【完成】按钮。

 2.修改消息内容

修改ProgressBarMsg.msg内容:

  1. std_msgs/Header header
  2. string context
  3. uint32 value

std_msgs/Header header:

数据类型的标准元数据,通常用于在特定坐标系中传达时间戳数据。 

包含字段

uint32 seq //表示序列 ID

time stamp //表示时间戳

string frame_id //和frame有关,序列id

3.修改package.xml内容

添加编译时的依赖

<build_depend>message_generation</build_depend>

添加执行时的依赖

<exec_depend>message_runtime</exec_depend>

<exec_depend>message_generation</exec_depend>

  1. <?xml version="1.0"?>
  2. <package format="2">
  3. <name>plugin_msg</name>
  4. <version>0.1.0</version>
  5. <description>The plugin_msg package</description>
  6. <!-- One maintainer tag required, multiple allowed, one person per tag -->
  7. <!-- Example: -->
  8. <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  9. <maintainer email="root@todo.todo">root</maintainer>
  10. <!-- One license tag required, multiple allowed, one license per tag -->
  11. <!-- Commonly used license strings: -->
  12. <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  13. <license>Apache 2.0</license>
  14. <!-- Url tags are optional, but multiple are allowed, one per tag -->
  15. <!-- Optional attribute type can be: website, bugtracker, or repository -->
  16. <!-- Example: -->
  17. <!-- <url type="website">http://wiki.ros.org/plugin_msg</url> -->
  18. <!-- Author tags are optional, multiple are allowed, one per tag -->
  19. <!-- Authors do not have to be maintainers, but could be -->
  20. <!-- Example: -->
  21. <!-- <author email="jane.doe@example.com">Jane Doe</author> -->
  22. <!-- The *depend tags are used to specify dependencies -->
  23. <!-- Dependencies can be catkin packages or system dependencies -->
  24. <!-- Examples: -->
  25. <!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
  26. <!-- <depend>roscpp</depend> -->
  27. <!-- Note that this is equivalent to the following: -->
  28. <!-- <build_depend>roscpp</build_depend> -->
  29. <!-- <exec_depend>roscpp</exec_depend> -->
  30. <!-- Use build_depend for packages you need at compile time: -->
  31. <build_depend>message_generation</build_depend>
  32. <!-- Use build_export_depend for packages you need in order to build against this package: -->
  33. <!-- <build_export_depend>message_generation</build_export_depend> -->
  34. <!-- Use buildtool_depend for build tool packages: -->
  35. <!-- <buildtool_depend>catkin</buildtool_depend> -->
  36. <!-- Use exec_depend for packages you need at runtime: -->
  37. <exec_depend>message_runtime</exec_depend>
  38. <exec_depend>message_generation</exec_depend>
  39. <!-- Use test_depend for packages you need only for testing: -->
  40. <!-- <test_depend>gtest</test_depend> -->
  41. <!-- Use doc_depend for packages you need only for building documentation: -->
  42. <!-- <doc_depend>doxygen</doc_depend> -->
  43. <buildtool_depend>catkin</buildtool_depend>
  44. <!-- The export tag contains other, unspecified, tags -->
  45. <export>
  46. <!-- Other tools can request additional information be placed here -->
  47. </export>
  48. </package>

4.修改CMakeLists.txt内容

catkin_package中添加依赖

CATKIN_DEPENDS message_runtime

  1. #指定项目所需的最低 CMake 版本。
  2. cmake_minimum_required(VERSION 3.0.2)
  3. #定义项目的名称
  4. project(plugin_msg)
  5. #查找并导入外部依赖库。
  6. find_package(catkin REQUIRED COMPONENTS
  7. std_msgs
  8. message_generation #增加message编译时依赖模块到(message_generation)
  9. )
  10. #增加自定义的msg文件
  11. add_message_files(
  12. FILES
  13. ProgressBarMsg.msg
  14. )
  15. #生成msg需要依赖的消息以及服务
  16. generate_messages(
  17. DEPENDENCIES
  18. std_msgs
  19. )
  20. #这用于指定包的依赖关系,由依赖于这个包的其他软件包使用。
  21. catkin_package(
  22. # INCLUDE_DIRS include
  23. # LIBRARIES custom_msg
  24. CATKIN_DEPENDS message_runtime #增加message运行时依赖模块message_runtime
  25. # DEPENDS system_lib
  26. )

 三、添加自定义插件(rviz::Display类型)

1.创建插件包以及文件

右击【src】,选择【添加新文件...】。

 

 选择【ROS】,选择【Package】,点击【Choose..】按钮。

 写入【Name:】包名称,写入【Catkin:】依赖,点击【下一步】按钮。

 

 点击【完成】按钮。

 

右击【progressBar_display】包下的【src】 ,选择【添加新文件...】。

 

选择【C++】,选择【C++ Class】,点击【Choose...】按钮。

 写入【Class name:】类名称,点击【下一步】按钮。

 点击【完成】按钮。

同上述相同步骤添加C++类ProgressBar_Visual。

创建完成之后,手动将progressbar_visual.h和progressbar_display.h两个头文件移动到功能包下的include文件夹下的progressBar_display文件夹下。

此时目录结构如下:

2.添加类代码

progressbar_visual.h

  1. #ifndef PROGRESSBAR_VISUAL_H
  2. #define PROGRESSBAR_VISUAL_H
  3. #include <OGRE/OgreVector3.h>
  4. #include <OGRE/OgreSceneNode.h>
  5. #include <OGRE/OgreSceneManager.h>
  6. #include <OGRE/OgreBillboard.h>
  7. #include <OGRE/OgreBillboardSet.h>
  8. #include <rviz/properties/string_property.h>
  9. #include <rviz/ogre_helpers/movable_text.h>
  10. #include <rviz/ogre_helpers/shape.h>
  11. #include <rviz/display_context.h>
  12. #include "plugin_msg/ProgressBarMsg.h"
  13. namespace Ogre
  14. {
  15. class Vector3;
  16. class Quaternion;
  17. class BillboardSet;
  18. class SceneManager;
  19. class SceneNode;
  20. class ColourValue;
  21. }
  22. namespace rviz
  23. {
  24. class MovableText;
  25. class Shape;
  26. class IntProperty;
  27. }
  28. namespace progressBar_plugin {
  29. class ProgressBar_Visual
  30. {
  31. public:
  32. ProgressBar_Visual(Ogre::SceneManager* SceneManager, Ogre::SceneNode* ParentNode);
  33. virtual ~ProgressBar_Visual();
  34. void setMessage(const plugin_msg::ProgressBarMsg::ConstPtr& Msg);
  35. void createProgressBarShape(double PowerRatio);
  36. void setFramePosition(const Ogre::Vector3& Position);
  37. void setFrameOrientation(const Ogre::Quaternion& Orientation);
  38. void setTextColor(const Ogre::ColourValue& Color);
  39. void setTextColor(float Red, float Green, float Blue, float Alpha);
  40. void setBackgroundColor(float Red, float Green, float Blue, float Alpha);
  41. void setProgressBarColor(float Red, float Green, float Blue, float Alpha);
  42. void setHeaderColor(float Red, float Green, float Blue, float Alpha);
  43. void setTextSize(float Size);
  44. void setGraphSize(float Size);
  45. void setOffsets(const Ogre::Vector3& Offsets);
  46. void setOrientation(const Ogre::Vector3& Orientation);
  47. private:
  48. float size_{ 1.0 };
  49. std::shared_ptr<Ogre::Vector3> base_pose_{ nullptr };
  50. std::shared_ptr<Ogre::Vector3> offsets_{ nullptr };
  51. std::shared_ptr<Ogre::Vector3> orientation_{ nullptr };
  52. // the object implementing the actual text
  53. std::shared_ptr<rviz::MovableText> progressBar_info_{ nullptr };
  54. // the object of ProgressBar shape
  55. std::vector<std::shared_ptr<rviz::Shape>> ProgressBar_shape_;
  56. // a SceneNode whose pose is set to match the coordinate frame of the plugin_msg::ProgressBarMsg message header
  57. Ogre::SceneNode* frame_node_{ nullptr };
  58. // the SceneManager, kept here only so the destructor can ask it to destroy the `frame_node_`
  59. Ogre::SceneManager* scene_manager_{ nullptr };
  60. Ogre::ColourValue background_color;
  61. Ogre::ColourValue ProgressBar_color;
  62. Ogre::ColourValue header_color;
  63. };
  64. }
  65. #endif // PROGRESSBAR_VISUAL_H

progressbar_visual.cpp

  1. #include "progressBar_display/progressbar_visual.h"
  2. namespace progressBar_plugin
  3. {
  4. ProgressBar_Visual::ProgressBar_Visual(Ogre::SceneManager *SceneManager, Ogre::SceneNode *ParentNode)
  5. {
  6. scene_manager_ = SceneManager;
  7. frame_node_ = ParentNode->createChildSceneNode();
  8. progressBar_info_.reset(new rviz::MovableText("?\%"));
  9. progressBar_info_->setCharacterHeight(0.5);
  10. frame_node_->attachObject(progressBar_info_.get());
  11. //create shape of ProgressBar
  12. base_pose_ = std::make_shared<Ogre::Vector3>(Ogre::Vector3::ZERO);
  13. offsets_ = std::make_shared<Ogre::Vector3>(Ogre::Vector3::ZERO);
  14. orientation_ = std::make_shared<Ogre::Vector3>(Ogre::Vector3(float(0.0), float(90.0), float(0.0)));
  15. background_color = Ogre::ColourValue(1, 0.5, 0.5, 0.5);
  16. ProgressBar_color = Ogre::ColourValue(1, 1, 0.5, 1);
  17. header_color = Ogre::ColourValue(0.5, 1, 1, 1);
  18. createProgressBarShape(1.0);
  19. }
  20. ProgressBar_Visual::~ProgressBar_Visual()
  21. {
  22. scene_manager_->destroySceneNode(frame_node_);
  23. }
  24. void ProgressBar_Visual::setMessage(const plugin_msg::ProgressBarMsg::ConstPtr &Msg)
  25. {
  26. int h = 0;
  27. int v = 0;
  28. progressBar_info_->setTextAlignment((rviz::MovableText::HorizontalAlignment)h, (rviz::MovableText::VerticalAlignment)v);
  29. rviz::StringProperty text("text", (std::to_string(Msg->value) + "\%").c_str());
  30. progressBar_info_->setCaption(text.getStdString());
  31. progressBar_info_->setLineSpacing(0.5);
  32. }
  33. void ProgressBar_Visual::createProgressBarShape(double PowerRatio)
  34. {
  35. for (auto& it : ProgressBar_shape_)
  36. {
  37. it.reset();
  38. }
  39. ProgressBar_shape_.clear();
  40. ProgressBar_shape_.resize(3);
  41. Ogre::Matrix3 mat;
  42. mat.FromEulerAnglesXYZ(Ogre::Degree(orientation_->x), Ogre::Degree(orientation_->y), Ogre::Degree(orientation_->z));
  43. Ogre::Quaternion orientation;
  44. orientation.FromRotationMatrix(mat);
  45. //background
  46. ProgressBar_shape_[0].reset(new rviz::Shape(rviz::Shape::Cylinder,scene_manager_));
  47. ProgressBar_shape_[0]->setScale(Ogre::Vector3(float(0.5 * size_),float(3 * size_),float(0.5 * size_)));
  48. ProgressBar_shape_[0]->setPosition(Ogre::Vector3(base_pose_->x + offsets_->x,
  49. base_pose_->y + offsets_->y,
  50. base_pose_->z + offsets_->z));
  51. ProgressBar_shape_[0]->setOrientation(orientation);
  52. ProgressBar_shape_[0]->setColor(background_color);
  53. //ProgressBar
  54. float length = 2.8 * size_;
  55. //ProgressBar center pos
  56. Ogre::Vector3 ProgressBar_vec3(0.0,- float(0.5 * length *(1 - PowerRatio)),0.0);
  57. Ogre::Vector3 ProgressBar_pos = orientation * ProgressBar_vec3;
  58. ProgressBar_shape_[1].reset(new rviz::Shape(rviz::Shape::Cylinder,scene_manager_));
  59. ProgressBar_shape_[1]->setScale(Ogre::Vector3(float(0.3 * size_),length * PowerRatio,float(0.3 * size_)));
  60. ProgressBar_shape_[1]->setPosition(Ogre::Vector3(base_pose_->x + ProgressBar_pos.x + offsets_->x,
  61. base_pose_->y + ProgressBar_pos.y + offsets_->y,
  62. base_pose_->z + ProgressBar_pos.z + offsets_->z));
  63. ProgressBar_shape_[1]->setOrientation(orientation);
  64. ProgressBar_shape_[1]->setColor(ProgressBar_color);
  65. //header
  66. float head_length = 0.1 * size_ * 0.5;
  67. //header center pos
  68. Ogre::Vector3 head_vec3(0.0,- float(0.5 * length *(1 - 2 * PowerRatio)) + head_length * 0.5,0.0);
  69. Ogre::Vector3 head_pos = orientation * head_vec3;
  70. ProgressBar_shape_[2].reset(new rviz::Shape(rviz::Shape::Cube,scene_manager_));
  71. ProgressBar_shape_[2]->setScale(Ogre::Vector3(float(0.3 * size_),head_length,float(0.3 * size_)));
  72. ProgressBar_shape_[2]->setPosition(Ogre::Vector3(base_pose_->x + head_pos.x + offsets_->x,
  73. base_pose_->y + head_pos.y + offsets_->y,
  74. base_pose_->z + head_pos.z + offsets_->z));
  75. ProgressBar_shape_[2]->setOrientation(orientation);
  76. ProgressBar_shape_[2]->setColor(header_color);
  77. }
  78. void ProgressBar_Visual::setFramePosition(const Ogre::Vector3 &Position)
  79. {
  80. *base_pose_ = Position;
  81. frame_node_->setPosition(Position);
  82. }
  83. void ProgressBar_Visual::setFrameOrientation(const Ogre::Quaternion &Orientation)
  84. {
  85. frame_node_->setOrientation(Orientation);
  86. }
  87. void ProgressBar_Visual::setTextColor(const Ogre::ColourValue &Color)
  88. {
  89. progressBar_info_->setColor(Color);
  90. }
  91. void ProgressBar_Visual::setTextColor(float Red, float Green, float Blue, float Alpha)
  92. {
  93. setTextColor(Ogre::ColourValue(Red, Green, Blue, Alpha));
  94. }
  95. void ProgressBar_Visual::setBackgroundColor(float Red, float Green, float Blue, float Alpha)
  96. {
  97. background_color = Ogre::ColourValue(Red, Green, Blue, Alpha);
  98. }
  99. void ProgressBar_Visual::setProgressBarColor(float Red, float Green, float Blue, float Alpha)
  100. {
  101. ProgressBar_color = Ogre::ColourValue(Red, Green, Blue, Alpha);
  102. }
  103. void ProgressBar_Visual::setHeaderColor(float Red, float Green, float Blue, float Alpha)
  104. {
  105. header_color = Ogre::ColourValue(Red, Green, Blue, Alpha);
  106. }
  107. void ProgressBar_Visual::setTextSize(float Size)
  108. {
  109. progressBar_info_->setCharacterHeight(Size);
  110. }
  111. void ProgressBar_Visual::setGraphSize(float Size)
  112. {
  113. size_ = Size;
  114. }
  115. void ProgressBar_Visual::setOffsets(const Ogre::Vector3 &Offsets)
  116. {
  117. *offsets_ = Offsets;
  118. progressBar_info_->setLocalTranslation(Ogre::Vector3(-offsets_->y, offsets_->z, -offsets_->x));
  119. }
  120. void ProgressBar_Visual::setOrientation(const Ogre::Vector3 &Orientation)
  121. {
  122. *orientation_ = Orientation;
  123. }
  124. }

progressbar_display.h

  1. #ifndef PROGRESSBAR_DISPLAY_H
  2. #define PROGRESSBAR_DISPLAY_H
  3. #ifndef Q_MOC_RUN
  4. #include <boost/circular_buffer.hpp>
  5. #include <rviz/message_filter_display.h>
  6. #include <rviz/panel_dock_widget.h>
  7. #include "plugin_msg/ProgressBarMsg.h"
  8. #endif
  9. namespace Ogre
  10. {
  11. class SceneNode;
  12. class ColourValue;
  13. }
  14. namespace rviz
  15. {
  16. class ColorProperty;
  17. class FloatProperty;
  18. class IntProperty;
  19. class VectorProperty;
  20. class BoolProperty;
  21. class StringProperty;
  22. }
  23. namespace progressBar_plugin {
  24. class ProgressBar_Visual;
  25. class ProgressBar_Display: public rviz::MessageFilterDisplay<plugin_msg::ProgressBarMsg>
  26. {
  27. Q_OBJECT
  28. public:
  29. ProgressBar_Display();
  30. virtual ~ProgressBar_Display();
  31. protected:
  32. virtual void onInitialize();
  33. // a helper function to clear this display back to the initial state
  34. virtual void reset();
  35. private Q_SLOTS:
  36. // these Qt slots get connected to signals indicating changes in the user-editable properties
  37. void updateTextColorAndAlpha();
  38. void updateBackgroundrColor();
  39. void updateProgressBarColor();
  40. void updateHeaderColor();
  41. void updateHistoryLength();
  42. void updateTextSize();
  43. void updateGraphSize();
  44. void updateOffsets();
  45. void updateOrientation();
  46. private:
  47. // function to handle an incoming ROS message
  48. void processMessage(const plugin_msg::ProgressBarMsg::ConstPtr& Msg);
  49. private:
  50. // storage for the list of visuals. It is a circular buffer,
  51. // where data gets popped from the front (oldest) and pushed to the back (newest)
  52. boost::circular_buffer<std::shared_ptr<ProgressBar_Visual>> visuals_;
  53. // user-editable property variables
  54. rviz::ColorProperty* text_color_property_;
  55. rviz::FloatProperty* text_alpha_property_;
  56. rviz::ColorProperty* background_color_property_;
  57. rviz::ColorProperty* progressBar_color_property_;
  58. rviz::ColorProperty* header_color_property_;
  59. rviz::IntProperty* history_length_property_;
  60. rviz::FloatProperty* text_size_property_;
  61. rviz::FloatProperty* graph_size_property_;
  62. rviz::VectorProperty* offsets_property_;
  63. rviz::VectorProperty* orientation_property_;
  64. };
  65. }
  66. #endif // PROGRESSBAR_DISPLAY_H

progressbar_display.cpp

  1. #include "progressBar_display/progressbar_display.h"
  2. #include "progressBar_display/progressbar_visual.h"
  3. #include <OGRE/OgreSceneNode.h>
  4. #include <OGRE/OgreSceneManager.h>
  5. #include <rviz/window_manager_interface.h>
  6. #include <rviz/visualization_manager.h>
  7. #include <rviz/properties/color_property.h>
  8. #include <rviz/properties/float_property.h>
  9. #include <rviz/properties/int_property.h>
  10. #include <rviz/properties/vector_property.h>
  11. #include <rviz/properties/bool_property.h>
  12. #include <rviz/properties/string_property.h>
  13. #include <pluginlib/class_list_macros.h>
  14. namespace progressBar_plugin
  15. {
  16. ProgressBar_Display::ProgressBar_Display()
  17. {
  18. text_color_property_ = new rviz::ColorProperty("Text Color", QColor(138, 226, 52),
  19. "Color of progressBar info text.",
  20. this, SLOT(updateTextColorAndAlpha()));
  21. text_alpha_property_ = new rviz::FloatProperty("Text Alpha", 1.0,
  22. "0 is fully transparent, 1.0 is fully opaque.",
  23. this, SLOT(updateTextColorAndAlpha()));
  24. text_size_property_ = new rviz::FloatProperty("Text Size", 0.5,
  25. "Character size of progressBar info text.",
  26. this, SLOT(updateTextSize()));
  27. background_color_property_ = new rviz::ColorProperty("Background Color", QColor(255,128,128),
  28. "Color of progressBar background.",
  29. this, SLOT(updateBackgroundrColor()));
  30. progressBar_color_property_ = new rviz::ColorProperty("ProgressBar Color", QColor(255,255,128),
  31. "Color of progressBar.",
  32. this, SLOT(updateProgressBarColor()));
  33. header_color_property_ = new rviz::ColorProperty("Header Color", QColor(128,255,255),
  34. "Color of progressBar header.",
  35. this, SLOT(updateHeaderColor()));
  36. graph_size_property_ = new rviz::FloatProperty("Graph Size", 1.0,
  37. "Character size of progressBar graph.",
  38. this, SLOT(updateGraphSize()));
  39. history_length_property_ = new rviz::IntProperty("History Length", 1,
  40. "Number of prior measurements to display.",
  41. this, SLOT(updateHistoryLength()));
  42. history_length_property_->setMin(1);
  43. history_length_property_->setMax(100000);
  44. offsets_property_ = new rviz::VectorProperty("Offsets", Ogre::Vector3::ZERO,
  45. "Offsets to frame",
  46. this, SLOT(updateOffsets()));
  47. orientation_property_ = new rviz::VectorProperty("Orientation", Ogre::Vector3(float(0.0), float(90.0), float(0.0)),
  48. "Orientation of progressBar symbol",
  49. this, SLOT(updateOrientation()));
  50. }
  51. ProgressBar_Display::~ProgressBar_Display()
  52. {
  53. }
  54. // after the top-level rviz::Display::initialize() does its own setup,
  55. // it calls the subclass's onInitialize() function
  56. // this is where all the workings of the class is instantiated
  57. // make sure to also call the immediate super-class's onInitialize() function,
  58. // since it does important stuff setting up the message filter
  59. //
  60. // note that "MFDClass" is a typedef of `MessageFilterDisplay<message type>`,
  61. // to save typing that long templated class name every time the superclass needs to be refered
  62. void ProgressBar_Display::onInitialize()
  63. {
  64. MFDClass::onInitialize();
  65. updateTextColorAndAlpha();
  66. updateHistoryLength();
  67. updateTextSize();
  68. updateGraphSize();
  69. updateOffsets();
  70. updateOrientation();
  71. }
  72. // clear the visuals by deleting their objects
  73. void ProgressBar_Display::reset()
  74. {
  75. MFDClass::reset();
  76. visuals_.clear();
  77. }
  78. // set the current color and alpha values for each visual
  79. void ProgressBar_Display::updateTextColorAndAlpha()
  80. {
  81. float alpha = text_alpha_property_->getFloat();
  82. Ogre::ColourValue color = text_color_property_->getOgreColor();
  83. for (size_t i = 0; i < visuals_.size(); ++i)
  84. {
  85. visuals_[i]->setTextColor(color.r, color.g, color.b, alpha);
  86. }
  87. }
  88. void ProgressBar_Display::updateBackgroundrColor()
  89. {
  90. Ogre::ColourValue color = background_color_property_->getOgreColor();
  91. for (size_t i = 0; i < visuals_.size(); ++i)
  92. {
  93. visuals_[i]->setBackgroundColor(color.r, color.g, color.b, 0.5);
  94. }
  95. }
  96. void ProgressBar_Display::updateProgressBarColor()
  97. {
  98. Ogre::ColourValue color = progressBar_color_property_->getOgreColor();
  99. for (size_t i = 0; i < visuals_.size(); ++i)
  100. {
  101. visuals_[i]->setProgressBarColor(color.r, color.g, color.b, 1);
  102. }
  103. }
  104. void ProgressBar_Display::updateHeaderColor()
  105. {
  106. Ogre::ColourValue color = header_color_property_->getOgreColor();
  107. for (size_t i = 0; i < visuals_.size(); ++i)
  108. {
  109. visuals_[i]->setHeaderColor(color.r, color.g, color.b, 1);
  110. }
  111. }
  112. // set the number of past visuals to show
  113. void ProgressBar_Display::updateHistoryLength()
  114. {
  115. visuals_.rset_capacity(history_length_property_->getInt());
  116. }
  117. void ProgressBar_Display::updateTextSize()
  118. {
  119. for (size_t i = 0; i < visuals_.size(); ++i)
  120. {
  121. visuals_[i]->setTextSize(text_size_property_->getFloat());
  122. }
  123. }
  124. void ProgressBar_Display::updateGraphSize()
  125. {
  126. for (size_t i = 0; i < visuals_.size(); ++i)
  127. {
  128. visuals_[i]->setGraphSize(graph_size_property_->getFloat());
  129. }
  130. }
  131. void ProgressBar_Display::updateOffsets()
  132. {
  133. for (size_t i = 0; i < visuals_.size(); ++i)
  134. {
  135. visuals_[i]->setOffsets(offsets_property_->getVector());
  136. }
  137. }
  138. void ProgressBar_Display::updateOrientation()
  139. {
  140. for (size_t i = 0; i < visuals_.size(); ++i)
  141. {
  142. visuals_[i]->setOrientation(orientation_property_->getVector());
  143. }
  144. }
  145. void ProgressBar_Display::processMessage(const plugin_msg::ProgressBarMsg::ConstPtr& Msg)
  146. {
  147. // call the rviz::FrameManager to get the transform from the fixed frame to the frame in the header of this progressBar message
  148. // if it fails, do nothing and return
  149. Ogre::Quaternion orientation;
  150. Ogre::Vector3 position;
  151. if (!context_->getFrameManager()->getTransform(Msg->header.frame_id,Msg->header.stamp, position, orientation))
  152. {
  153. ROS_DEBUG("error transforming from frame '%s' to frame '%s'",
  154. Msg->header.frame_id.c_str(), qPrintable(fixed_frame_));
  155. return;
  156. }
  157. // keeping a circular buffer of visual pointers
  158. // this gets the next one, or creates and stores it if the buffer is not full
  159. std::shared_ptr<ProgressBar_Visual> visual;
  160. if (visuals_.full())
  161. {
  162. visual = visuals_.front();
  163. }
  164. else
  165. {
  166. visual.reset(new ProgressBar_Visual(context_->getSceneManager(), scene_node_));
  167. }
  168. // set or update the contents of the chosen visual
  169. float alpha = text_alpha_property_->getFloat();
  170. Ogre::ColourValue color = text_color_property_->getOgreColor();
  171. visual->setTextColor(color.r, color.g, color.b, alpha);
  172. color = background_color_property_->getOgreColor();
  173. visual->setBackgroundColor(color.r, color.g, color.b, 0.5);
  174. color = progressBar_color_property_->getOgreColor();
  175. visual->setProgressBarColor(color.r, color.g, color.b, 1);
  176. color = header_color_property_->getOgreColor();
  177. visual->setHeaderColor(color.r, color.g, color.b, 1);
  178. visual->createProgressBarShape(Msg->value / 100.0);
  179. visual->setMessage(Msg);
  180. visual->setFramePosition(position);
  181. visual->setFrameOrientation(orientation);
  182. // send it to the end of the circular buffer
  183. visuals_.push_back(visual);
  184. }
  185. #include <pluginlib/class_list_macros.h>
  186. PLUGINLIB_EXPORT_CLASS(progressBar_plugin::ProgressBar_Display, rviz::Display)
  187. }
注册插件

#include <pluginlib/class_list_macros.h>

PLUGINLIB_EXPORT_CLASS(progressBar_plugin::ProgressBar_Display, rviz::Display)

3.添加plugin_description.xml文件

内容如下:

  1. <library path="lib/libprogressBar_display">
  2. <class name="progressBar_plugin/ProgressBar"
  3. type="progressBar_plugin::ProgressBar_Display"
  4. base_class_type="rviz::Display">
  5. <description>
  6. display progressBar information
  7. </description>
  8. </class>
  9. </library>

plugin_description.xml文件各字段含义 :

path:动态链接库路径
name:插件名称
type:插件的完整类型
base_class_type:插件完整类型父类
description:功能描述

4.修改package.xml文件

修改内容如下:

  1. <?xml version="1.0"?>
  2. <package format="2">
  3. <name>progressBar_display</name>
  4. <version>0.1.0</version>
  5. <description>The progressBar_display package</description>
  6. <!-- One maintainer tag required, multiple allowed, one person per tag -->
  7. <!-- Example: -->
  8. <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  9. <maintainer email="root@todo.todo">root</maintainer>
  10. <!-- One license tag required, multiple allowed, one license per tag -->
  11. <!-- Commonly used license strings: -->
  12. <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  13. <license>Apache 2.0</license>
  14. <!-- Url tags are optional, but multiple are allowed, one per tag -->
  15. <!-- Optional attribute type can be: website, bugtracker, or repository -->
  16. <!-- Example: -->
  17. <!-- <url type="website">http://wiki.ros.org/progressBar_display</url> -->
  18. <!-- Author tags are optional, multiple are allowed, one per tag -->
  19. <!-- Authors do not have to be maintainers, but could be -->
  20. <!-- Example: -->
  21. <!-- <author email="jane.doe@example.com">Jane Doe</author> -->
  22. <!-- The *depend tags are used to specify dependencies -->
  23. <!-- Dependencies can be catkin packages or system dependencies -->
  24. <!-- Examples: -->
  25. <!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
  26. <!-- <depend>roscpp</depend> -->
  27. <!-- Note that this is equivalent to the following: -->
  28. <!-- <build_depend>roscpp</build_depend> -->
  29. <!-- <exec_depend>roscpp</exec_depend> -->
  30. <!-- Use build_depend for packages you need at compile time: -->
  31. <!-- <build_depend>message_generation</build_depend> -->
  32. <!-- Use build_export_depend for packages you need in order to build against this package: -->
  33. <!-- <build_export_depend>message_generation</build_export_depend> -->
  34. <!-- Use buildtool_depend for build tool packages: -->
  35. <!-- <buildtool_depend>catkin</buildtool_depend> -->
  36. <!-- Use exec_depend for packages you need at runtime: -->
  37. <!-- <exec_depend>message_runtime</exec_depend> -->
  38. <!-- Use test_depend for packages you need only for testing: -->
  39. <!-- <test_depend>gtest</test_depend> -->
  40. <!-- Use doc_depend for packages you need only for building documentation: -->
  41. <!-- <doc_depend>doxygen</doc_depend> -->
  42. <buildtool_depend>catkin</buildtool_depend>
  43. <build_depend>qtbase5-dev</build_depend>
  44. <build_depend>rviz</build_depend>
  45. <exec_depend>libqt5-core</exec_depend>
  46. <exec_depend>libqt5-gui</exec_depend>
  47. <exec_depend>libqt5-widgets</exec_depend>
  48. <exec_depend>rviz</exec_depend>
  49. <build_depend>plugin_msg</build_depend>
  50. <build_export_depend>plugin_msg</build_export_depend>
  51. <exec_depend>plugin_msg</exec_depend>
  52. <!-- The export tag contains other, unspecified, tags -->
  53. <export>
  54. <!-- Other tools can request additional information be placed here -->
  55. <rviz plugin="${prefix}/plugin_description.xml"/>
  56. </export>
  57. </package>

5.修改CMakeLists.txt文件

修改内容如下:

  1. #指定项目所需的最低 CMake 版本。
  2. cmake_minimum_required(VERSION 3.0.2)
  3. #定义项目的名称
  4. project(progressBar_display)
  5. #查找并导入外部依赖库
  6. find_package(catkin REQUIRED COMPONENTS
  7. rviz
  8. plugin_msg
  9. )
  10. ## This plugin includes Qt widgets, so we must include Qt like so:
  11. find_package(Qt5 REQUIRED Core Widgets)
  12. set(QT_LIBRARIES Qt5::Widgets)
  13. #添加头文件搜索路径,编译器使用这些目录来查找头文件,第一个参数“include”表示包中的include/目录也是路径的一部分。
  14. include_directories(
  15. include
  16. ${catkin_INCLUDE_DIRS}
  17. )
  18. ## I prefer the Qt signals and slots to avoid defining "emit", "slots",
  19. ## etc because they can conflict with boost signals, so define QT_NO_KEYWORDS here.
  20. add_definitions(-DQT_NO_KEYWORDS)
  21. # 设置相关变量
  22. # 自动添加当前目录至路径中
  23. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  24. # 自动生成moc文件,自动运行moc
  25. set(CMAKE_AUTOMOC ON)
  26. # 自动运行uic
  27. #set(CMAKE_AUTOUIC ON)
  28. # 自动运行rcc
  29. set(CMAKE_AUTORCC ON)
  30. #用来匹配指定路径下所有符合通配符条件的文件的命令。具体来说,GLOB_RECURSE 是递归查找目录下的所有文件,file() 命令则可以用来获取文件列表。
  31. file(GLOB_RECURSE SOURCE_CPP
  32. "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
  33. )
  34. file(GLOB_RECURSE SOURCE_H
  35. "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/*.h"
  36. )
  37. #生成库
  38. add_library(${PROJECT_NAME}
  39. ${SOURCE_H}
  40. ${SOURCE_CPP}
  41. )
  42. #在定义消息类型时,编译的库依赖这些动态生成的代码
  43. add_dependencies(${PROJECT_NAME} plugin_msg_generate_messages_cpp)
  44. #设置链接库,需要用到系统或者第三方库函数时候进行配置,第一个参数是可执行文件名,后面依次写入需要链接的库
  45. #设置生成库依赖的库
  46. target_link_libraries(${PROJECT_NAME}
  47. ${catkin_LIBRARIES}
  48. ${QT_LIBRARIES}
  49. )

四、添加自定义插件(rviz::Panel类型)

1.创建插件包以及文件

创建名为progressBar_panel的插件包,以及名为ProgressBar_Panel的c++类,步骤同上。

创建带有UI界面的类步骤如下:

选择【Qt】,选择【Qt设计师界面类】,点击【Choose...】按钮。

 选择【Widget】,点击【下一步】按钮

 输入【类名:】,点击【下一步】按钮。

 点击【完成】按钮。

 同上将.h文件移到include下的progressBar_panel文件夹下。在src和include的同级目录下创建ui文件夹,将.ui文件移到ui文件夹下。

此时目录结构如下:

 2.添加类代码

ui界面

界面如下:

 panel_widget.h

  1. #ifndef PANEL_WIDGET_H
  2. #define PANEL_WIDGET_H
  3. #include <QWidget>
  4. namespace Ui {
  5. class Panel_Widget;
  6. }
  7. namespace progressBar_panel {
  8. class Panel_Widget : public QWidget
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit Panel_Widget(QWidget *parent = 0);
  13. ~Panel_Widget();
  14. Q_SIGNALS:
  15. void sigToUpdateTopicAndProgressBarValue(QString topic,float value);
  16. private:
  17. Ui::Panel_Widget *ui;
  18. };
  19. }
  20. #endif // PANEL_WIDGET_H

panel_widget.cpp

  1. #include "progressBar_panel/panel_widget.h"
  2. #include "ui_panel_widget.h"
  3. namespace progressBar_panel {
  4. Panel_Widget::Panel_Widget(QWidget *parent) :
  5. QWidget(parent),
  6. ui(new Ui::Panel_Widget)
  7. {
  8. ui->setupUi(this);
  9. connect(ui->topic_name,&QLineEdit::editingFinished,this,[=](){
  10. Q_EMIT sigToUpdateTopicAndProgressBarValue(ui->topic_name->text(),ui->progressBar_value->text().toFloat());
  11. });
  12. connect(ui->progressBar_value,&QLineEdit::editingFinished,this,[=](){
  13. Q_EMIT sigToUpdateTopicAndProgressBarValue(ui->topic_name->text(),ui->progressBar_value->text().toFloat());
  14. });
  15. connect(ui->pushButton_add,&QPushButton::clicked,this,[=](){
  16. ui->progressBar_value->setText(QString::number(ui->progressBar_value->text().toFloat() + 5));
  17. Q_EMIT sigToUpdateTopicAndProgressBarValue(ui->topic_name->text(),ui->progressBar_value->text().toFloat());
  18. if(ui->progressBar_value->text().toFloat() == 100)
  19. ui->progressBar_value->setText("0");
  20. });
  21. }
  22. Panel_Widget::~Panel_Widget()
  23. {
  24. delete ui;
  25. }
  26. }

progressbar_panel.h

  1. #ifndef PROGRESSBAR_PANEL_H
  2. #define PROGRESSBAR_PANEL_H
  3. #include <rviz/panel.h>
  4. #include <ros/ros.h>
  5. #include <rviz/panel.h>
  6. #include "panel_widget.h"
  7. #include "plugin_msg/ProgressBarMsg.h"
  8. namespace progressBar_panel {
  9. class ProgressBar_Panel: public rviz::Panel
  10. {
  11. public:
  12. ProgressBar_Panel(QWidget* parent = 0 );
  13. virtual void load( const rviz::Config& config );
  14. virtual void save( rviz::Config config ) const;
  15. public Q_SLOTS:
  16. void updateTopicAndProgressBarValue(QString topic,float value);
  17. private:
  18. Panel_Widget *panel_widget;
  19. // The current name of the output topic.
  20. QString output_topic_;
  21. // The ROS publisher for the command velocity.
  22. ros::Publisher progressBar_publisher_;
  23. // The ROS node handle.
  24. ros::NodeHandle nh_;
  25. };
  26. }
  27. #endif // PROGRESSBAR_PANEL_H

progressbar_panel.cpp

  1. #include "progressBar_panel/progressbar_panel.h"
  2. #include <rviz/properties/bool_property.h>
  3. #include <rviz/properties/float_property.h>
  4. #include <rviz/properties/string_property.h>
  5. #include <rviz/window_manager_interface.h>
  6. #include <rviz/display_context.h>
  7. #include <QVBoxLayout>
  8. #include <QDebug>
  9. #include <QDateTime>
  10. namespace progressBar_panel
  11. {
  12. ProgressBar_Panel::ProgressBar_Panel(QWidget* parent): rviz::Panel( parent )
  13. {
  14. panel_widget = new Panel_Widget;
  15. connect(panel_widget,&Panel_Widget::sigToUpdateTopicAndProgressBarValue,this,&ProgressBar_Panel::updateTopicAndProgressBarValue);
  16. QVBoxLayout* layout = new QVBoxLayout;
  17. layout->addWidget(panel_widget);
  18. setLayout(layout);
  19. }
  20. void ProgressBar_Panel::load(const rviz::Config &config)
  21. {
  22. rviz::Panel::load( config );
  23. }
  24. void ProgressBar_Panel::save(rviz::Config config) const
  25. {
  26. rviz::Panel::save( config );
  27. }
  28. void ProgressBar_Panel::updateTopicAndProgressBarValue(QString topic, float value)
  29. {
  30. if( topic != output_topic_ )
  31. {
  32. output_topic_ = topic;
  33. // If the topic is the empty string, don't publish anything.
  34. if( output_topic_ == "" )
  35. {
  36. progressBar_publisher_.shutdown();
  37. }
  38. else
  39. {
  40. // The old ``velocity_publisher_`` is destroyed by this assignment,
  41. // and thus the old topic advertisement is removed. The call to
  42. // nh_advertise() says we want to publish data on the new topic
  43. // name.
  44. progressBar_publisher_ = nh_.advertise<plugin_msg::ProgressBarMsg>( output_topic_.toStdString(), 1 );
  45. }
  46. // rviz::Panel defines the configChanged() signal. Emitting it
  47. // tells RViz that something in this panel has changed that will
  48. // affect a saved config file. Ultimately this signal can cause
  49. // QWidget::setWindowModified(true) to be called on the top-level
  50. // rviz::VisualizationFrame, which causes a little asterisk ("*")
  51. // to show in the window's title bar indicating unsaved changes.
  52. Q_EMIT configChanged();
  53. }
  54. if( ros::ok() && progressBar_publisher_ )
  55. {
  56. plugin_msg::ProgressBarMsg msg;
  57. msg.header.frame_id = "map";//output_topic_.toStdString();
  58. msg.header.stamp = ros::Time(QDateTime::currentSecsSinceEpoch());
  59. msg.value = value;
  60. progressBar_publisher_.publish( msg );
  61. //qDebug()<<"publisher msg";
  62. }
  63. }
  64. }
  65. // 声明此类是一个rviz的插件
  66. #include <pluginlib/class_list_macros.h>
  67. PLUGINLIB_EXPORT_CLASS(progressBar_panel::ProgressBar_Panel,rviz::Panel )

 3.添加plugin_description.xml文件

内容如下:

  1. <library path="lib/libprogressBar_panel">
  2. <class name="progressBar_panel/ProgressBarPanel"
  3. type="progressBar_panel::ProgressBar_Panel"
  4. base_class_type="rviz::Panel">
  5. <description>
  6. panel progressBar information
  7. </description>
  8. </class>
  9. </library>

4.修改package.xml文件

修改内容如下:

  1. <?xml version="1.0"?>
  2. <package format="2">
  3. <name>progressBar_panel</name>
  4. <version>0.1.0</version>
  5. <description>The progressBar_panel package</description>
  6. <!-- One maintainer tag required, multiple allowed, one person per tag -->
  7. <!-- Example: -->
  8. <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  9. <maintainer email="root@todo.todo">root</maintainer>
  10. <!-- One license tag required, multiple allowed, one license per tag -->
  11. <!-- Commonly used license strings: -->
  12. <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  13. <license>Apache 2.0</license>
  14. <!-- Url tags are optional, but multiple are allowed, one per tag -->
  15. <!-- Optional attribute type can be: website, bugtracker, or repository -->
  16. <!-- Example: -->
  17. <!-- <url type="website">http://wiki.ros.org/progressBar_panel</url> -->
  18. <!-- Author tags are optional, multiple are allowed, one per tag -->
  19. <!-- Authors do not have to be maintainers, but could be -->
  20. <!-- Example: -->
  21. <!-- <author email="jane.doe@example.com">Jane Doe</author> -->
  22. <!-- The *depend tags are used to specify dependencies -->
  23. <!-- Dependencies can be catkin packages or system dependencies -->
  24. <!-- Examples: -->
  25. <!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
  26. <!-- <depend>roscpp</depend> -->
  27. <!-- Note that this is equivalent to the following: -->
  28. <!-- <build_depend>roscpp</build_depend> -->
  29. <!-- <exec_depend>roscpp</exec_depend> -->
  30. <!-- Use build_depend for packages you need at compile time: -->
  31. <!-- <build_depend>message_generation</build_depend> -->
  32. <!-- Use build_export_depend for packages you need in order to build against this package: -->
  33. <!-- <build_export_depend>message_generation</build_export_depend> -->
  34. <!-- Use buildtool_depend for build tool packages: -->
  35. <!-- <buildtool_depend>catkin</buildtool_depend> -->
  36. <!-- Use exec_depend for packages you need at runtime: -->
  37. <!-- <exec_depend>message_runtime</exec_depend> -->
  38. <!-- Use test_depend for packages you need only for testing: -->
  39. <!-- <test_depend>gtest</test_depend> -->
  40. <!-- Use doc_depend for packages you need only for building documentation: -->
  41. <!-- <doc_depend>doxygen</doc_depend> -->
  42. <buildtool_depend>catkin</buildtool_depend>
  43. <build_depend>qtbase5-dev</build_depend>
  44. <build_depend>rviz</build_depend>
  45. <exec_depend>libqt5-core</exec_depend>
  46. <exec_depend>libqt5-gui</exec_depend>
  47. <exec_depend>libqt5-widgets</exec_depend>
  48. <exec_depend>rviz</exec_depend>
  49. <build_depend>custom_msg</build_depend>
  50. <build_export_depend>custom_msg</build_export_depend>
  51. <exec_depend>custom_msg</exec_depend>
  52. <!-- The export tag contains other, unspecified, tags -->
  53. <export>
  54. <!-- Other tools can request additional information be placed here -->
  55. <rviz plugin="${prefix}/plugin_description.xml"/>
  56. </export>
  57. </package>

5.修改CMakeLists.txt文件

修改内容如下:

  1. #指定项目所需的最低 CMake 版本。
  2. cmake_minimum_required(VERSION 3.0.2)
  3. #定义项目的名称
  4. project(progressBar_panel)
  5. #查找并导入外部依赖库
  6. find_package(catkin REQUIRED COMPONENTS
  7. rviz
  8. plugin_msg
  9. )
  10. ## This plugin includes Qt widgets, so we must include Qt.
  11. ## We'll use the version that rviz used so they are compatible.
  12. if(rviz_QT_VERSION VERSION_LESS "5")
  13. message(STATUS "Using Qt4 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")
  14. find_package(Qt4 ${rviz_QT_VERSION} EXACT REQUIRED QtCore QtGui)
  15. ## pull in all required include dirs, define QT_LIBRARIES, etc.
  16. include(${QT_USE_FILE})
  17. macro(qt_wrap_ui)
  18. qt4_wrap_ui(${ARGN})
  19. endmacro()
  20. else()
  21. message(STATUS "Using Qt5 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")
  22. find_package(Qt5 ${rviz_QT_VERSION} EXACT REQUIRED Core Widgets)
  23. ## make target_link_libraries(${QT_LIBRARIES}) pull in all required dependencies
  24. set(QT_LIBRARIES Qt5::Widgets)
  25. macro(qt_wrap_ui)
  26. qt5_wrap_ui(${ARGN})
  27. endmacro()
  28. endif()
  29. #添加头文件搜索路径,编译器使用这些目录来查找头文件,第一个参数“include”表示包中的include/目录也是路径的一部分。
  30. include_directories(
  31. include
  32. ${catkin_INCLUDE_DIRS}
  33. )
  34. ## I prefer the Qt signals and slots to avoid defining "emit", "slots",
  35. ## etc because they can conflict with boost signals, so define QT_NO_KEYWORDS here.
  36. add_definitions(-DQT_NO_KEYWORDS)
  37. ## I prefer the Qt signals and slots to avoid defining "emit", "slots",
  38. ## etc because they can conflict with boost signals, so define QT_NO_KEYWORDS here.
  39. add_definitions(-DQT_NO_KEYWORDS)
  40. # 设置相关变量
  41. # 自动添加当前目录至路径中
  42. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  43. # 自动生成moc文件,自动运行moc
  44. set(CMAKE_AUTOMOC ON)
  45. # 自动运行uic
  46. #set(CMAKE_AUTOUIC ON)
  47. # 自动运行rcc
  48. set(CMAKE_AUTORCC ON)
  49. qt_wrap_ui(UIC_FILES
  50. ui/panel_widget.ui
  51. )
  52. #用来匹配指定路径下所有符合通配符条件的文件的命令。具体来说,GLOB_RECURSE 是递归查找目录下的所有文件,file() 命令则可以用来获取文件列表。
  53. file(GLOB_RECURSE SOURCE_CPP
  54. "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
  55. )
  56. file(GLOB_RECURSE SOURCE_H
  57. "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/*.h"
  58. )
  59. #生成库
  60. add_library(${PROJECT_NAME}
  61. ${SOURCE_H}
  62. ${SOURCE_CPP}
  63. ${UIC_FILES}
  64. )
  65. #在定义消息类型时,编译的库依赖这些动态生成的代码
  66. add_dependencies(${PROJECT_NAME} plugin_msg_generate_messages_cpp)
  67. #设置链接库,需要用到系统或者第三方库函数时候进行配置,第一个参数是可执行文件名,后面依次写入需要链接的库
  68. #设置生成库依赖的库
  69. target_link_libraries(${PROJECT_NAME}
  70. ${catkin_LIBRARIES}
  71. ${QT_LIBRARIES}
  72. )

五、编译

在工作空间下打开终端,输入命令

catkin_make

六 、运行

在终端输入命令,设置环境

source devel/setup.bash

在打开rviz之前需另开一个终端打开ros环境

roscore

 输入命令打开rviz可视化工具

rviz

七 、rviz的使用

1.打开Panel类型插件

点击菜单栏的【Panel】选项,点击【Add New Panel】按钮。

 选择【progressBar_panel】下的【ProgressBarPanel】插件,点击【OK】按钮。

此时在rviz中显示出该插件。

 

 2.添加Display类型插件

点击【Displays】视口的【Add】按钮。

选择【progressBar_display】下的【ProgressBar】插件,点击【OK】按钮。

 此时在rviz的Displays视口显示该插件。

 

3.插件的使用

 首先在Panel插件中输入一个topic name(推送的话题名称)。

 在Display插件中选择订阅的话题,如下图:

 

 此时修改slider value的值即可看到并修改中间部分的进度条。

需要注意的是:

推送的消息中会设置frame id,本次设置的为map,所以不需修改此值,如果推送的消息中不为map,需要一致。

 

资源链接

https://download.csdn.net/download/m0_67254672/88225745?spm=1001.2014.3001.5501

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/623689
推荐阅读
相关标签
  

闽ICP备14008679号