ROS - RQt ui 파일 분석

남생이·2024년 10월 19일

ROS

목록 보기
24/28
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>examples_widget</class>
 <widget class="QWidget" name="examples_widget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>640</width>
    <height>480</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>RQT Example</string>
  </property>
  <widget class="QGroupBox" name="group_box_ur">
   <property name="geometry">
    <rect>
     <x>330</x>
     <y>30</y>
     <width>300</width>
     <height>300</height>
    </rect>
   </property>
   <property name="title">
    <string>Topic Subscriber Example</string>
   </property>
   <widget class="QSlider" name="slider_x">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>30</y>
      <width>31</width>
      <height>211</height>
     </rect>
    </property>
    <property name="minimum">
     <number>-1000</number>
    </property>
    <property name="maximum">
     <number>1000</number>
    </property>
    <property name="singleStep">
     <number>10</number>
    </property>
    <property name="orientation">
     <enum>Qt::Vertical</enum>
    </property>
   </widget>
   <widget class="QDial" name="dial_yaw">
    <property name="geometry">
     <rect>
      <x>130</x>
      <y>40</y>
      <width>151</width>
      <height>181</height>
     </rect>
    </property>
    <property name="tabletTracking">
     <bool>false</bool>
    </property>
    <property name="minimum">
     <number>-50</number>
    </property>
    <property name="maximum">
     <number>50</number>
    </property>
    <property name="value">
     <number>0</number>
    </property>
    <property name="invertedAppearance">
     <bool>false</bool>
    </property>
    <property name="invertedControls">
     <bool>false</bool>
    </property>
    <property name="wrapping">
     <bool>false</bool>
    </property>
    <property name="notchTarget">
     <double>10.000000000000000</double>
    </property>
    <property name="notchesVisible">
     <bool>true</bool>
    </property>
   </widget>
   <widget class="QLCDNumber" name="lcd_number_x">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>250</y>
      <width>101</width>
      <height>41</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="label_x">
    <property name="geometry">
     <rect>
      <x>115</x>
      <y>273</y>
      <width>30</width>
      <height>17</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>12</pointsize>
      <weight>75</weight>
      <italic>true</italic>
      <bold>true</bold>
     </font>
    </property>
    <property name="text">
     <string>m/s</string>
    </property>
   </widget>
   <widget class="QLCDNumber" name="lcd_number_yaw">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>250</y>
      <width>101</width>
      <height>41</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="label_yaw">
    <property name="geometry">
     <rect>
      <x>255</x>
      <y>273</y>
      <width>50</width>
      <height>17</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>12</pointsize>
      <weight>75</weight>
      <italic>true</italic>
      <bold>true</bold>
     </font>
    </property>
    <property name="text">
     <string>rad/s</string>
    </property>
   </widget>
  </widget>
  <widget class="QGroupBox" name="group_box_dr">
   <property name="geometry">
    <rect>
     <x>330</x>
     <y>350</y>
     <width>300</width>
     <height>120</height>
    </rect>
   </property>
   <property name="title">
    <string>Service Server Example</string>
   </property>
   <widget class="QLabel" name="label_led_status">
    <property name="geometry">
     <rect>
      <x>100</x>
      <y>30</y>
      <width>91</width>
      <height>30</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>12</pointsize>
      <weight>75</weight>
      <italic>true</italic>
      <bold>true</bold>
     </font>
    </property>
    <property name="text">
     <string>LED Status</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QPushButton" name="push_button_led_status">
    <property name="geometry">
     <rect>
      <x>100</x>
      <y>60</y>
      <width>91</width>
      <height>41</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <weight>75</weight>
      <bold>true</bold>
     </font>
    </property>
    <property name="autoFillBackground">
     <bool>false</bool>
    </property>
    <property name="styleSheet">
     <string notr="true"/>
    </property>
    <property name="text">
     <string>On/Off</string>
    </property>
   </widget>
  </widget>
  <widget class="QGroupBox" name="group_box_dl">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>350</y>
     <width>300</width>
     <height>120</height>
    </rect>
   </property>
   <property name="title">
    <string>Service Client Example</string>
   </property>
   <widget class="QRadioButton" name="radio_button_led_on">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>50</y>
      <width>100</width>
      <height>22</height>
     </rect>
    </property>
    <property name="text">
     <string>LED ON</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="radio_button_led_off">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>50</y>
      <width>100</width>
      <height>22</height>
     </rect>
    </property>
    <property name="text">
     <string>LED OFF</string>
    </property>
    <property name="iconSize">
     <size>
      <width>16</width>
      <height>16</height>
     </size>
    </property>
   </widget>
   <widget class="QLabel" name="label_shortcut_key_2">
    <property name="geometry">
     <rect>
      <x>52</x>
      <y>80</y>
      <width>190</width>
      <height>21</height>
     </rect>
    </property>
    <property name="text">
     <string>( o key: LED On / f key: LED Off )</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
  </widget>
  <widget class="QGroupBox" name="group_box_ul">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>30</y>
     <width>300</width>
     <height>300</height>
    </rect>
   </property>
   <property name="title">
    <string>Topic Publisher Example</string>
   </property>
   <widget class="QWidget" name="grid_layout_widget">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>40</y>
      <width>299</width>
      <height>191</height>
     </rect>
    </property>
    <layout class="QGridLayout" name="grid_layout">
     <item row="1" column="2">
      <widget class="QPushButton" name="push_button_d">
       <property name="font">
        <font>
         <pointsize>20</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="text">
        <string>d</string>
       </property>
      </widget>
     </item>
     <item row="0" column="1">
      <widget class="QPushButton" name="push_button_w">
       <property name="font">
        <font>
         <pointsize>20</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="text">
        <string>w</string>
       </property>
      </widget>
     </item>
     <item row="1" column="1">
      <widget class="QPushButton" name="push_button_s">
       <property name="enabled">
        <bool>true</bool>
       </property>
       <property name="font">
        <font>
         <pointsize>20</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="text">
        <string>s</string>
       </property>
      </widget>
     </item>
     <item row="2" column="1">
      <widget class="QPushButton" name="push_button_x">
       <property name="font">
        <font>
         <pointsize>20</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="text">
        <string>x</string>
       </property>
      </widget>
     </item>
     <item row="1" column="0">
      <widget class="QPushButton" name="push_button_a">
       <property name="font">
        <font>
         <pointsize>20</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="text">
        <string>a</string>
       </property>
      </widget>
     </item>
    </layout>
   </widget>
   <widget class="QLabel" name="label_shortcut_key_1">
    <property name="geometry">
     <rect>
      <x>20</x>
      <y>237</y>
      <width>250</width>
      <height>50</height>
     </rect>
    </property>
    <property name="text">
     <string>w/x key: increase/decrease linear velocity
a/d key: increase/decrease angular velocity
space key, s key: force stop</string>
    </property>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

위 파일은 RQt 플러그인 인터페이스를 정의하는 ui파일로 XML 태그를 이용합니다.

  • 위젯 별 설명

1) main widget - examples_widget : 창의 크기와 제목 지정

2) group_box_ur

nametypeposition/sizetitle
group_box_urQgroupBox(330,30), 300x300Topic Subscriber Example

2-1) Child widegets

nametypeposition/sizesetting
slider_xQSlider(50,30), 31x211Orientation: 세로 (Qt::Vertical)
Range: -1000 ~ 1000, 단위 스텝: 10
dial_yawQDial(130, 40), 151x181Range: -50 ~ 50, 초기값은 0
Notch Visibility: true (눈금 표시)
lcd_number_xQLCDNumber(10, 250), 101x41슬라이더(slider_x)의 값을 표시하는 LCD 디스플레이.
label_xQLabel(115, 273), 30x17Text: "m/s" (속도 단위)
Font: 크기 12, 굵게, 기울임.
lcd_number_yawQLCDNumber(150, 250), 101x41Role: 다이얼(dial_yaw)의 값을 표시하는 LCD 디스플레이.
label_yawQLabelPosition/Size: (255, 273), 50x17Text: "rad/s" (각속도 단위)Font: 크기 12, 굵게, 기울임.

이 코드는 RQT(ROS Qt) 플러그인 인터페이스를 정의하는 XML 파일입니다. RQT는 ROS(로봇 운영 시스템)에서 시각적인 사용자 인터페이스를 제공하는 도구입니다. 이 XML 파일은 Qt Designer에서 만든 UI 레이아웃을 표현하며, 위젯과 레이아웃의 위치, 크기, 속성 등을 지정합니다. QWidget, QGroupBox, QSlider, QDial 등 여러 위젯들을 포함하며, 각 위젯은 다음과 같은 역할을 합니다:

1. examples_widget

  • Type: QWidget
  • Role: RQT 플러그인의 메인 위젯입니다. 창의 크기는 640x480이고, 제목은 "RQT Example"입니다.

2. group_box_ur (Topic Subscriber Example)

  • Type: QGroupBox
  • Position/Size: (330, 30), 300x300
  • Title: "Topic Subscriber Example"
  • Child Widgets:
    • slider_x:
      • Type: QSlider
      • Position/Size: (50, 30), 31x211
      • Orientation: 세로 (Qt::Vertical)
      • Range: -1000 ~ 1000, 단위 스텝: 10
    • dial_yaw:
      • Type: QDial
      • Position/Size: (130, 40), 151x181
      • Range: -50 ~ 50, 초기값은 0
      • Notch Visibility: true (눈금 표시)
    • lcd_number_x:
      • Type: QLCDNumber
      • Position/Size: (10, 250), 101x41
      • Role: 슬라이더(slider_x)의 값을 표시하는 LCD 디스플레이.
    • label_x:
      • Type: QLabel
      • Position/Size: (115, 273), 30x17
      • Text: "m/s" (속도 단위)
      • Font: 크기 12, 굵게, 기울임.
    • lcd_number_yaw:
      • Type: QLCDNumber
      • Position/Size: (150, 250), 101x41
      • Role: 다이얼(dial_yaw)의 값을 표시하는 LCD 디스플레이.
    • label_yaw:
      • Type: QLabel
      • Position/Size: (255, 273), 50x17
      • Text: "rad/s" (각속도 단위)
      • Font: 크기 12, 굵게, 기울임.

3. group_box_dr (Service Server Example)

  • Type: QGroupBox
  • Position/Size: (330, 350), 300x120
  • Title: "Service Server Example"
  • Child Widgets:
    • label_led_status:
      • Type: QLabel
      • Position/Size: (100, 30), 91x30
      • Text: "LED Status"
      • Font: 크기 12, 굵게, 기울임.
      • Alignment: 가운데 정렬.
    • push_button_led_status:
      • Type: QPushButton
      • Position/Size: (100, 60), 91x41
      • Text: "On/Off"
      • Font: 굵게.
      • Role: LED의 상태를 토글하는 버튼.

4. group_box_dl (Service Client Example)

  • Type: QGroupBox
  • Position/Size: (10, 350), 300x120
  • Title: "Service Client Example"
  • Child Widgets:
    • radio_button_led_on:
      • Type: QRadioButton
      • Position/Size: (60, 50), 100x22
      • Text: "LED ON"
    • radio_button_led_off:
      • Type: QRadioButton
      • Position/Size: (150, 50), 100x22
      • Text: "LED OFF"
    • label_shortcut_key_2:
      • Type: QLabel
      • Position/Size: (52, 80), 190x21
      • Text: "( o key: LED On / f key: LED Off )"
      • Alignment: 가운데 정렬.

5. group_box_ul (Topic Publisher Example)

  • Type: QGroupBox
  • Position/Size: (10, 30), 300x300
  • Title: "Topic Publisher Example"
  • Child Widgets:
    • grid_layout_widget:
      • Type: QWidget with QGridLayout
      • Position/Size: (0, 40), 299x191
      • Layout: QGridLayout 사용하여 아래의 버튼 배치:
        • push_button_w: 위쪽 (w 키, 전진)
        • push_button_s: 아래쪽 (s 키, 정지)
        • push_button_a: 왼쪽 (a 키, 좌회전)
        • push_button_d: 오른쪽 (d 키, 우회전)
        • push_button_x: 아래 (x 키, 후진)
        • 각 버튼은 20포인트 폰트로 설정.
    • label_shortcut_key_1:
      • Type: QLabel
      • Position/Size: (20, 237), 250x50
      • Text:
        w/x key: increase/decrease linear velocity
        a/d key: increase/decrease angular velocity
        space key, s key: force stop
      • Role: 각 버튼에 해당하는 키보드 단축키 안내.

이 XML 파일을 통해 만든 UI는 RQT 플러그인으로, 토픽을 구독하고 퍼블리싱하며, 서비스 서버와 클라이언트를 다루는 인터페이스를 제공합니다. 각 위젯은 로봇의 이동 속도 조절, 방향 제어, LED 상태 변경 등을 위한 인터페이스를 제공하며, 이를 통해 사용자는 쉽게 로봇의 동작을 제어할 수 있습니다.

group_box_ur는 Qt Designer에서 사용된 이름으로, 해당 위젯의 역할을 나타내기 위한 식별자입니다. 이름 자체는 사용자가 지정할 수 있으며, 구체적으로 어떤 의미를 가지는지는 코드 작성자의 의도에 따라 다릅니다. 여기서 ur는 "upper right"의 약자로, 위젯이 사용자 인터페이스의 오른쪽 위에 위치하고 있다는 것을 암시할 수 있습니다.

위 코드에서 사용된 XML 문법 설명

이 코드는 Qt Designer로 생성된 .ui 파일의 내용으로, XML 형식으로 작성되었습니다. XML은 데이터 구조를 정의하고 표현하기 위해 사용되는 마크업 언어입니다. 여기서 사용된 XML은 PyQt나 PySide 같은 라이브러리에서 사용할 수 있는 사용자 인터페이스를 정의합니다. 각 태그와 속성은 UI의 레이아웃, 위젯, 속성 등을 지정하는 데 사용됩니다.

XML 구조 설명

  • 루트 노드 (<ui>):

    • version="4.0": Qt 버전을 지정합니다.
    • 이 안에서 UI의 구성 요소들이 정의됩니다.
  • <class>:

    • UI 클래스의 이름을 정의합니다. 여기서는 examples_widget이라는 이름으로 정의되었습니다.
  • <widget>:

    • UI에 포함된 개별 위젯을 정의합니다.
    • class 속성은 위젯의 종류를 지정하고, name 속성은 해당 위젯의 식별자를 지정합니다. 예를 들어:
      • class="QWidget"은 기본 위젯을 의미합니다.
      • name="examples_widget"은 이 위젯의 이름입니다.
  • <property>:

    • 각 위젯의 속성을 설정합니다. 예를 들어:
      • geometry는 위젯의 위치와 크기를 정의하며, <rect> 요소를 사용해 x, y, width, height를 지정합니다.
      • windowTitle은 윈도우의 제목을 정의합니다.
  • 위젯 정의 (<widget> 태그 내):

    • 각 위젯은 속성(geometry, text, title 등)을 포함하고 있으며, 위젯의 타입과 이름을 지정합니다.
    • <widget> 내부에 다른 위젯을 포함할 수 있어, 그룹 박스나 레이아웃 구조를 정의할 때 사용됩니다.
  • <layout>:

    • 위젯들의 배치를 정의하는 데 사용됩니다. 이 코드에서는 QGridLayout을 사용해 그리드 형식으로 위젯들을 배치하고 있습니다.
    • <item> 요소로 레이아웃의 특정 위치에 위젯을 추가할 수 있습니다.

group_box_ur 내부 위젯 설명

  • QGroupBox (group_box_ur):
    • "Topic Subscriber Example"이라는 제목을 가진 그룹 박스로, 주제 구독과 관련된 UI 요소들을 포함합니다.
  • 내부 위젯들:
    • QSlider (slider_x):
      • 세로 방향의 슬라이더로, 최소값은 -1000, 최대값은 1000으로 설정되어 있습니다. 사용자가 값을 조정할 수 있습니다.
    • QDial (dial_yaw):
      • 회전형 다이얼로, 각도를 조절하는 데 사용됩니다. 최소값은 -50, 최대값은 50입니다.
    • QLCDNumber (lcd_number_xlcd_number_yaw):
      • slider_xdial_yaw의 값을 표시할 수 있는 LCD 스타일 디스플레이입니다.
    • QLabel (label_xlabel_yaw):
      • 각각 "m/s"와 "rad/s"의 단위를 표시합니다.

이 XML 구조를 통해 .ui 파일을 Qt 기반 Python 코드로 변환하면, PyQt나 PySide에서 해당 UI를 활용할 수 있습니다. group_box_ur와 같은 이름은 UI 코드에서 해당 위젯을 참조할 때 사용됩니다.

profile
공부하는 거북이

0개의 댓글