Skip to content
wngjs3 edited this page Mar 15, 2018 · 6 revisions

Overview

Gazebo GUI 오버레이는 렌더링 윈도우의 꼭대기에있는 투명한 2D 레이어로 생각할 수 있습니다. QT 위젯은 플러그인 인터페이스를 통해이 레이어에 추가 할 수 있습니다. 메인 Gazebo 메뉴 바에서 View-> GUI Overlays를 클릭하여 모든 GUI 오버레이를 보이거나 감출 수 있습니다. 이 자습서에서는 GUI 오버레이 플러그인을 만들고 사용하여 Gazebo의 사용자 인터페이스를 만드는 방법을 설명합니다.

GUI 오버레이 기능을 보여주기 위해 두 가지 예가 사용됩니다. 첫 번째 예제에서는 구를 생성하는 버튼을 만들고 두 번째 예제에서는 현재 시뮬레이션 시간을 표시합니다. 이 두 예제는 Gazebo로 데이터를 보내고 Gazebo에서 데이터를 수신하는 방법을 보여줍니다.

Example 1: Spawn spheres

https://bitbucket.org/osrf/gazebo/src/gazebo9/examples/plugins/gui_overlay_plugin_spawn/ 소스코드는 여기서 찾을 수 있습니다.

1.최신 Gazebo 버전을 설치하십시오.

2.설치 페이지의 지시 사항을 따르십시오.

mkdir ~/gazebo_gui_spawn
cd ~/gazebo_gui_spawn
  1. GUI 오버레이 플러그인의 소스 코드 다운로드 (OsX에서 wget은 curl -OL로 바꿀 수 있음)

    wget https://bitbucket.org/osrf/gazebo/raw/gazebo9/examples/plugins/gui_overlay_plugin_spawn/GUIExampleSpawnWidget.hh wget https://bitbucket.org/osrf/gazebo/raw/gazebo9/examples/plugins/gui_overlay_plugin_spawn/GUIExampleSpawnWidget.cc wget https://bitbucket.org/osrf/gazebo/raw/gazebo9/examples/plugins/gui_overlay_plugin_spawn/CMakeLists.txt

4.헤더 파일을 살펴보십시오.

gedit GUIExampleSpawnWidget.hh

   GUI 오버레이 플러그인은 GUIPlugin 클래스를 상속 받아 Qt의 Q_OBJECT 매크로를 사용해야합니다.

        class GAZEBO_VISIBLE GUIExampleSpawnWidget : public GUIPlugin
        {
          Q_OBJECT

    나머지 플러그인에는 사용자의 필요에 맞게 플러그인을 작성하는 데 필요한 코드가 포함될 수 있습니다. 이 예에서는 QT 슬롯을 사용하여 버튼을 누릅니다.

          /// \brief Callback trigged when the button is pressed.
          protected slots: void OnButton()

    Gazebo의 공장 기능을 사용하여 SDF 스폰 메시지를 gzserver로 전송합니다.:

          /// \brief Node used to establish communication with gzserver.
          private: transport::NodePtr node;

          /// \brief Publisher of factory messages.
          private: transport::PublisherPtr factoryPub;

5.소스 파일을 살펴보십시오.

gedit GUIExampleSpawnWidget.cc

    이 파일의 생성자는 QT를 사용하여 버튼을 만들고이를 OnButton 콜백에 연결합니다.:

      // Create a push button, and connect it to the OnButton function
      QPushButton *button = new QPushButton(tr("Spawn Sphere"));
      connect(button, SIGNAL(clicked()), this, SLOT(OnButton()));

    그 생성자는 또한 Gazebo의 전송 메커니즘에 연결하고 공장 게시자를 만듭니다:

      // Create a node for transportation
      this->node = transport::NodePtr(new transport::Node());
      this->node->Init();
      this->factoryPub = this->node->Advertise<msgs::Factory>("~/factory");

    OnButton 콜백은 새로운 구형 SDF 문자열을 만듭니다.:

      std::ostringstream newModelStr;
      newModelStr << "<sdf version='" << SDF_VERSION << "'>"
        << msgs::ModelToSDF(model)->ToString("")
        << "</sdf>";

    그리고 가제보에게 문자열을 보냅니다.:

      msgs::Factory msg;
      msg.set_sdf(newModelStr.str());
      this->factoryPub->Publish(msg);
    }

6.플러그인 컴파일

cd ~/gazebo_gui_spawn
mkdir build
cd build
cmake ../
make

7.이제 우리는 Gazebo가 플러그인을 찾을 수 있도록해야합니다. 빌드 디렉토리를 GAZEBO_PLUGIN_PATH 환경 변수에 추가하여이 작업을 수행 할 수 있습니다.

cd ~/gazebo_gui_spawn/build
export GAZEBO_PLUGIN_PATH=`pwd`:$GAZEBO_PLUGIN_PATH

위의 명령은 현재 쉘에서만 작동합니다. 새 터미널을 열 때 플러그인이 작동하는지 확인하려면 플러그인을 / usr / local / lib와 같은 일반적인 검색 경로 나 GAZEBO_PLUGIN_PATH 라이브러리에 지정된 경로 중 하나에 설치하십시오.

8.또한 오버레이 플러그인을로드해야한다고 Gazebo에 알릴 필요가 있습니다.

이 작업을 수행하는 데는 두 가지 방법이 있습니다.

    1.SDF world file : GUI 플러그인을 포함하도록 world SDF 파일을 수정하십시오. 예 :

    <?xml version="1.0" ?>
    <sdf version="1.5">
      <world name="default">

        <gui>
          <plugin name="sample" filename="libgui_example_spawn_widget.so"/>
        </gui>

        <!-- A global light source -->
        <include>
          <uri>model://sun</uri>
        </include>
        <!-- A ground plane -->
        <include>
          <uri>model://ground_plane</uri>
        </include>
      </world>
    </sdf>

    Tip: Download the world file above:

    cd ~/gazebo_gui_spawn
    wget https://bitbucket.org/osrf/gazebo/raw/gazebo9/examples/plugins/gui_overlay_plugin_spawn/spawn_widget_example.world

    2.GUI INI 파일 : Gazebo가 실행될 때마다 플러그인이로드되도록 ~ / .gazebo / gui.ini 파일을 수정하십시오.

    gedit ~/.gazebo/gui.ini

    Add the following lines:

    [overlay_plugins]
    filenames=libgui_example_spawn_widget.so
  1. 이제 Gazebo를 실행하면 렌더링 윈도우의 왼쪽 상단에 버튼이 나타납니다.

GUI 플러그인으로 사용자 정의 SDF 월드 파일을 생성 한 경우 :

gazebo spawn_widget_example.world

또는 ~ / .gazebo / gui.ini를 수정 한 경우

gazebo

Click on the button to spawn spheres.

Example 2: Display Simulation Time

The source code for this example is found here.

Start by creating a working directory

mkdir ~/gazebo_gui_time
cd ~/gazebo_gui_time

Download the source code for the GUI overlay plugin

wget https://bitbucket.org/osrf/gazebo/raw/gazebo9/examples/plugins/gui_overlay_plugin_time/GUIExampleTimeWidget.hh
wget https://bitbucket.org/osrf/gazebo/raw/gazebo9/examples/plugins/gui_overlay_plugin_time/GUIExampleTimeWidget.cc
wget https://bitbucket.org/osrf/gazebo/raw/gazebo9/examples/plugins/gui_overlay_plugin_time/CMakeLists.txt

Take a look at the header file.

gedit GUIExampleTimeWidget.hh

    Just as in the first example, this plugin inherits from the GUIPlugin class, and use Qt's Q_OBJECT macro.

      class GAZEBO_VISIBLE GUIExampleTimeWidget : public GUIPlugin
      {
        Q_OBJECT

    We use SetSimTime signal as a thread safe mechanism to update the displayed simulation time.

        /// \brief A signal used to set the sim time line edit.
        /// \param[in] _string String representation of sim time.
        signals: void SetSimTime(QString _string);

    An OnStats callback is used to receive information from Gazebo.

        /// \brief Callback that received world statistics messages.
        /// \param[in] _msg World statistics message that is received.
        protected: void OnStats(ConstWorldStatisticsPtr &_msg);

    We will also use Gazebo's transport mechanism to receive messages from Gazebo.

        /// \brief Node used to establish communication with gzserver.
        private: transport::NodePtr node;

        /// \brief Subscriber to world statistics messages.
        private: transport::SubscriberPtr statsSub;

Take a look at the source file.

gedit GUIExampleTimeWidget.cc

    In the constructor, we create a QLabel to display the time, and connect it to the SetSimeTime signal.

      // Create a time label
      QLabel *timeLabel = new QLabel(tr("00:00:00.00"));

      // Add the label to the frame's layout
      frameLayout->addWidget(label);
      frameLayout->addWidget(timeLabel);
      connect(this, SIGNAL(SetSimTime(QString)),
          timeLabel, SLOT(setText(QString)), Qt::QueuedConnection);

    The constructor also connects to Gazebo's ~/world_stats topic.

      // Create a node for transportation
      this->node = transport::NodePtr(new transport::Node());
      this->node->Init("default");
      this->statsSub = this->node->Subscribe("~/world_stats",
          &GUIExampleTimeWidget::OnStats, this);

    When a message is received, the OnStats function is called and the displayed time is updated.

    void GUIExampleTimeWidget::OnStats(ConstWorldStatisticsPtr &_msg)
    {
      this->SetSimTime(QString::fromStdString(
            this->FormatTime(_msg->sim_time())));

Follow the same steps as the previous tutorial to compile the plugin, tell Gazebo where to find it and load it via gui.ini or an SDF world file.

    Tip: You can add both plugins to gui.ini as follows:

     gedit ~/.gazebo/gui.ini

    Change the [overlay_plugins] section to be:

     [overlay_plugins]
     filenames=libgui_example_spawn_widget.so:libgui_example_time_widget.so

    This will load both the spawn sphere plugin from the previous example and the time plugin from this example.

When Gazebo is run, a new text box to the right of the spawn button should show the simulation time.

gazebo

Table of Contents




Clone this wiki locally