zoukankan      html  css  js  c++  java
  • Learning ROS: Ubuntu16.04下kinetic开发环境安装和初体验 Install + Configure + Navigating(look around) + Creating a Package(catkin_create_pkg) + Building a Package(catkin_make) + Understanding Nodes

    本文主要部分来源于ROS官网的Tutorials.

    Ubuntu install of ROS Kinetic

    # Setup your sources.list
    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
    # Set up your keys
    sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
    # Installation
    sudo apt-get update
    sudo apt-get install ros-kinetic-desktop-full  # Desktop-Full Install: (Recommended)
    # Initialize rosdep
    sudo rosdep init
    rosdep update
    # Environment setup, so ROS environment variables are automatically added to your bash session every time a new shell is launched
    echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    # Install this tool and other dependencies for building ROS packages
    sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

    Configuring Your ROS Environment

    #  check to ensure that environment variables like ROS_ROOT and ROS_PACKAGE_PATH are set 
    printenv | grep ROS
    source /opt/ros/kinetic/setup.bash # if no ROS variable are set, run this command
    
    # Create a ROS Workspace (use the recommended catkin)
    mkdir -p ~/catkin_ws/src
    cd ~/catkin_ws/
    catkin_make
    
    # source your new setup.*sh file when a new shell is launched
    echo 'source /home/youruser/catkin_ws/devel/setup.bash' >> ~/.bashrc source ~/.bashrc echo $ROS_PACKAGE_PATH # you will see /home/youruser/catkin_ws/src:/opt/ros/kinetic/share

    Navigating the ROS Filesystem

    sudo apt-get install ros-kinetic-ros-tutorials
    rospack find roscpp # rospack find [package_name], returns the path to package
    
    roscd roscpp
    pwd # You can see that YOUR_INSTALL_PATH/share/roscpp is the same path that rospack find gave in the previous example
    
    echo $ROS_PACKAGE_PATH #  ROS_PACKAGE_PATH should contain a list of directories where you have ROS packages separated by colons
    
    roscd roscpp/cmake # roscd can also move to a subdirectory of a package or stack
    pwd
    
    roscd log # take you to the folder where ROS stores log files
                   # Note that if you have not run any ROS programs yet, this will yield an error saying that it does not yet exist.
    
    rosls roscpp_tutorials # rosls is part of the rosbash suite. It allows you to ls directly in a package by name rather than by absolute path. 
    
    # Tab Completion
    roscd roscpp_tut<<< now push the TAB key >>>

    Creating a ROS Package

    cd ~/catkin_ws/src
    # catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
    catkin_create_pkg beginner_tutorials std_msgs rospy roscpp #  create a new package called 'beginner_tutorials' which depends on std_msgs, roscpp, and rospy
    
    # build the packages in the catkin workspace
    cd ~/catkin_ws
    catkin_make
    # To add the workspace to your ROS environment you need to source the generated setup file
    . ~/catkin_ws/devel/setup.bash
    
    rospack depends1 beginner_tutorials # First-order dependencies
    
    roscd beginner_tutorials
    cat package.xml # These dependencies for a package are stored in the package.xml file
    
    rospack depends beginner_tutorials # Indirect dependencies, rospack can recursively determine all nested dependencies

    Building a ROS Package

    cd ~/catkin_ws/
    ls src
    catkin_make # build all catkin projects found in the src folder.
    catkin_make install  # (optionally)
    ls

    Understanding ROS Nodes

    sudo apt-get install ros-kinetic-ros-tutorials # install a lightweight simulator
    roscore # the first thing you should run when using ROS
    rosnode list # lists active nodes
    rosnode info /rosout # display information about a specific node

    # in a new terminal:
    rosrun turtlesim turtlesim_node # You will see the turtlesim window

    # in a new termina
    rosnode list # lists active nodes
    rosrun turtlesim turtlesim_node __name:=my_turtle # change the node's name to my_turtle
    rosnode list # lists active nodes
    rosnode ping my_turtle # test that it's up

    Review

    • Nodes: A node uses ROS to communicate with other nodes. A node really isn't much more than an executable file within a ROS package.
    • Messages: ROS data type used when subscribing or publishing to a topic.
    • Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
    • Master: Name service for ROS (i.e. helps nodes find each other)
    • rosout: ROS equivalent of stdout/stderr
    • roscore: Master + rosout + parameter server (parameter server will be introduced later)

    You may have noticed a pattern with the naming of the ROS tools,This naming pattern holds for many of the ROS tools.

    • rospack = ros + pack(age)
    • roscd = ros + cd
    • rosls = ros + ls
    • roscore = ros+core : master (provides name service for ROS) + rosout (stdout/stderr) + parameter server (parameter server will be introduced later)
    • rosnode = ros+node : ROS tool to get information about a node.
    • rosrun = ros+run : runs a node from a given package.
  • 相关阅读:
    AcWing 852. spfa判断负环 边权可能为负数。
    面试题 02.01. 移除重复节点
    1114. 按序打印
    剑指 Offer 38. 字符串的排列
    557. 反转字符串中的单词 III
    645. 错误的集合
    面试题 05.03. 翻转数位
    1356. 根据数字二进制下 1 的数目排序
    748. 最短完整词
    剑指 Offer 32
  • 原文地址:https://www.cnblogs.com/xbit/p/8457098.html
Copyright © 2011-2022 走看看