当前位置:网站首页>ROS QT environment construction

ROS QT environment construction

2022-06-22 07:05:00 Ice cream

download Qt

  • S1:sudo apt-get install qtcreator The installed version may be too long , So the official website is installed :https://download.qt.io/archive/qt/
  • S2: Choose the version https://download.qt.io/archive/qt/5.9/5.9.9/: qt-opensource-linux-x64-5.9.9.run
  • S3: Enter the installation directory , Change execution permission :chmod a+x qt-opensource-linux-x64-5.9.9.run
  • S4: Double click installation , always next, Installation component selection Desktop gcc 64-bit that will do , Other on-demand installations
  • S5: Then double-click... Under the installation directory Qtreator It's ready to run , But for convenience , So add to the environment variable sudo nano /usr/bin/qtcreator
    Add the following :
    #!/bin/sh
    export QT_HOME=/home/guyue/Qt5.9.9/Tools/QtCreator/bin
    $QT_HOME/qtcreator $*
    
    ctrl+o write in ,ctrl+x sign out
  • S6: Add execute permission :sudo chmod a+x /usr/bin/qtcreator
  • S7: Terminal operation :qtcreator

ROS rely on

  • S1: Installation dependency

    sudo apt-get install ros-melodic-qt-create
    
    sudo apt-get install ros-melodic-qt-build
    
    # sudo apt-get install qtmultimedia5-dev
    
  • S2: establish Qt Function pack

    catkin_create_qt_pkg  Function package name   rely on 1  rely on 2
    
    #  Example :
    cd ~/am_ws/src
    catkin_create_qt_pkg class1_ros_qt_demo roscpp rviz
    
  • S3.1: here catkin_make Will report a mistake , Make the following changes :
     Insert picture description here

    # 1/  Settings include the current directory :
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    
    # 2/  add to qt library :
    find_package(Qt5 REQUIRED Core Widgets)
    set(QT_LIBRARIES Qt5::Widgets)
    
    
    # 3/  Delete :
    
    rosbuild_prepare_qt4(QtCore QtGui)
    
    
    # 4/  change 
    # QT4_ADD_RESOURCES(QT_RESOURCES_CPP) ${QT_RESOURCES})
    # QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
    # QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})
    
    #  Change it to :
    QT5_ADD_RESOURCES(QT_RESOURCES_CPP) ${QT_RESOURCES})
    QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
    QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})
    

    Specific in CMakeList.txt Refer to the following figure for the changes in :

     Insert picture description here

  • S3.2: An error will be reported when compiling again , You need to change ~/am_ws/src/class1_ros_qt_demo/include/class1_ros_qt_demo/main_window.hpp file , take :#include <QtGui/QMainWindow>, Change it to :#include <QtWidgets/QMainWindow>

  • S4: Then everything is normal and the test can be carried out

test

  • S1: Run the following commands , The screen appears :

    rosrun class1_ros_qt_demo class1_ros_qt_demo
    

     Insert picture description here

  • S2: function roscore, Click... On the above interface connect, Connect

Qt compile ROS engineering

  • S1: To configure Qt Of ROS Environmental Science
    Use Qt Open workspace /src Under the CmakeList.txt;
    To configure build The directory is a workspace /build;
    And then click Configure Project
    Note that the workspace is open src Under the CmakeList, Not the feature pack
     Insert picture description here

  • S1.2: If the project does not open properly
     Insert picture description here
     Insert picture description here

  • S1.3: Header files are in <Headers> Inside , Click to open the header file , Press F4 Key to switch between the header file and the corresponding cpp file

  • S2: Run configuration
    Click on project, And then choose run, stay run configure Settings that need to be run , If it is empty , You can click on the add Button to add
     Insert picture description here

  • S3: Then click the green icon to run


Reference resources

原网站

版权声明
本文为[Ice cream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220700379160.html