ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • _ROS1_설치_환경설정_기본실습
    ROS/ROS1 2023. 10. 1. 23:49

    이번에 설치할 ROS는 melodic 버전으로 ubuntu 18.04에서 설치할 수 있다.

    ubuntu 18.04버전은 다른 사이트들을 보고 참고해서 설치하면 된다.

    ubuntu는 공식 사이트 혹은 mirror.kakao에서 설치하면 된다.

    https://mirror.kakao.com/ubuntu-releases/

     

    Ubuntu Releases

    There are 2 types of Ubuntu releases: Interim and LTS. Each Ubuntu LTS is maintained for 10 years total: 5 years of standard support + 5 years of ESM. Interim releases are maintained for 9 months. For the Ubuntu release cycle please see: The Ubuntu lifecyc

    mirror.kakao.com

    ROS melodic 설치 참고할 사이트

    http://wiki.ros.org/melodic/Installation/Ubuntu

     

    melodic/Installation/Ubuntu - ROS Wiki

    We are building Debian packages for several Ubuntu platforms, listed below. These packages are more efficient than source-based builds and are our preferred installation method for Ubuntu. Note that there are also packages available from Ubuntu upstream. P

    wiki.ros.org


    ROS Melodic Installation

    위의 melodic 참고 사이트에서 필요한 코드만 cmd에 복사하면 편하게 설치할 수 있다.

    이번에 설치된 가상머신에 한번 melodic을 설치해보려고 한다.

     

    1. ROS를 제공하는 Software Repository 등록

    $ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

    만약 bad substitution이라는 오류가 나오면 ${lsb_release-sc}를 bionic으로 바꿔서 명령어를 입력하면 된다.

    제대로 적용이 되었는지 확인하려면 아래의 명령어를 입력해본다.

    cat '/etc/apt/sources.list.d/ros-latest.list'

    정상적으로 적용이 되었다면, "deb http://packages.ros.org/ros/ubuntu bionic main"이 출력된다.

     

    2. Set up Keys

    $ sudo apt install curl # if you haven't already installed curl
    $ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

    Key가 정삭적으로 적용이 되었다면 OK라고 나온다.

     

    3. Installation

    key를 입력했다면 다음과 같이 진행을 한다.

    ## 1. update 진행
    $ sudo apt update
    
    ## 2. ros-melodic설치
    # Full version
    $ sudo apt install ros-melodic-desktop-full
    
    # 일반버전(ROS, rqt, rviz, robot-generic libraries 설치)
    $ sudo apt install ros-melodic-desktop
    
    # ROS-base 설치(Package, build, communication lib만 제공. GUI tool은 제공하지 않음)
    $ sudo apt install ros-melodic-ros-base

    입맞에 맞게 설치하면 되는데 만약 ROS를 학습용도로 사용한다면 Full version을 추천한다.

    맞는 버전이 설치되었다면 패키치 구축 및 rosdep 초기화를 진행한다.

    rosdep은 컴파일 하려는 소스에 대해 시스템 종속성을 쉽게 설치할 수 있도록 도와주며 일부 핵심 구성 요소를 실행하는데 필요하다.

    # full version 이 아닐경우
    $ sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
    
    # full version일 경우
    $ sudo apt install python-rosdep
    
    # 아래는 동일하게 순서대로 명령어 입력
    $ sudo rosdep init
    $ rosdep update

    다음의 명령어가 나오면 rosdep update를 입력하면 된다.

     

    Environment setup

    ROS설치가 완료된다면, 나의 기본위치의 .bashrc 파일에 다음의 명령어를 추가한다.

    echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc # .bashrc에 명령어추가
    source ~/.bashrc # 명령어 적용

    .bashrc를 열어보면 다음과 같이 추가된 것을 볼 수 있다.

    ros가 제대로 설치되었다면 roscore를 명령창에 입력해보자.

    다음과 같이 나온다면 정상적으로 설치가 된 것이다.

    roscore 명령어 입력된 모습

    종료는 'Ctrl + C'버튼을 누르면 된다.

     

    ROS Workspace

    ROS를 코딩할 수 있는 workspace를 만들어보려고 한다.

    참고 사이트

    http://wiki.ros.org/catkin/Tutorials/create_a_workspace

     

    catkin/Tutorials/create_a_workspace - ROS Wiki

    Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. Creating a workspace for catkin Description: T

    wiki.ros.org

    주로 catkin_ws를 명칭으로 만들지만, 이번에는 xycar_ ws를 사용할 것이다.

    자신의 home 폴더에서 다음의 명령어를 입력해보자.

    $ mkdir -p ~/xycar_ws/src # 서브 폴더 생성
    $ cd xycar_ws             # xycar_ws로 이동
    $ catkin_make             # ROS 코딩 환경 셋업 및 정리(빌드)

    catkin_make가 끝나면 xycar_sw에 build와 devel폴더가 생긴 것을 볼 수 있다.

    폴더의 구조는 다음과 같다.

    xycar_ws에서 ROS의 코딩작업을 진행하면 되고 소스코드는 src폴더에 넣으면 된다.

    이번에는 ROS작업에 필요한 환경변수를 설정하는 방법인데 이전에 .bashrc에 내가 원하는 환경변수를 넣어주면 된다.

    필자는 다음과 같이 설정이 되어있다.

    # SET ROS Melodic
    source /opt/ros/melodic/setup.bash
    source /home/blue/catkin_ws/devel/setup.bash
    source /home/blue/xycar_ws/devel/setup.bash
    
    # SET ROS NETWORK
    export ROS_HOSTNAME=localhost
    #export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
    export ROS_MASTER_URI=http://localhost:11311
    
    #SET ROS alias command
    alias cw='cd /home/blue/catkin_ws'
    alias cs='cd /home/blue/catkin_ws/src'
    alias cm='cd /home/blue/catkin_ws && catkin_make && source devel/setup.bash'
    alias xw='cd /home/blue/xycar_ws'
    alias xs='cd /home/blue/xycar_ws/src'
    alias xm='cd /home/blue/xycar_ws && catkin_make && source devel/setup.bash'

    설정을 변경하였다면, 항상 source ~/.bashrc를 입력하여 적용하도록 하자.

    설정된 환경변수를 확인하고 싶다면, 다음 명령어 "printenv | grep ROS"를 입력해보면 된다.

     

    Teleop_key_node & Tutlesim_node

    이번에는 여러개의 창을 사용하여 teleop_key_node로 tutlesim_node에 명령어를 전달하는 간단한 예제를 해보려고 한다.

    각 노드에 대한 설명은 다음과 같다.

    • turtle_teleop_key_node: keyboard로 거북이 로봇의 방향을 제어할 수 있는 노드
    • tutlesim_node: 2D 거북이 로봇이 있는 시뮬레이션

    4개의 터미널 창을 사용할 것이며 각각 다음 명령어를 입력해주면 된다.

    # Terminal 1
    $ roscore
    
    # Terminal 2
    $ rosnode list
    
    # Terminal 3
    $ rosrun turtlesim turtlesim_node
    
    # Terminal 4
    $ rosrun turtlesim turtle_teleop_key

    각 터미널에서 실행중인 명령어

    또한, rostopic list 명령어로 어떠한 토픽을 주고 받는지, rostopic echo로 어떤 값을 주고받는지 알 수 있다.

    토픽을 조금 더 자세히 보고 싶다면 rostopic list -v 명령어를 입력하면 된다.

    rostopic list

    rostopic list -v

     

    rostopic echo /turtle1/cmd_vel

     

    또한 rqt_graph로 노드와 토픽의 관계를 볼 수 있다. 터미널에 rqt_graph명령어를 입력하면 된다.

    토픽에서 메시지를 주고받을때, 메시지 마다 타입이 있는데 이를 알기 위해서 터미널에 다음의 명령어를 입력한다.

    $ rostopic type /turtle1/cmd_vel #/turtle1/cmd_vel의 메시지 타입을 알려주는 명령어
    $ rosmsg show geometry_msgs/Twist #geometry_msgs/Twist의 구성을 알려주는 명령어

    rostopic type /turtle1/cmd_vel

    rosmsg show geometry_msgs/Twist

    geometry_msgs외에도 수많은 메시지 타입이 있으며, 본인이 커스텀해서 사용할 수도 있다.

    만약, 다른 메시지 타입이 궁금하다면 ROS공식 사이트에서 찾아보면 된다.

     

    내가 turtle_teleop_key외에도 토픽을 발행할 수 있는데 이는 rostopic pub 명령어를 사용하면 된다.

    # 1번만 발행
    $ rostopic pub -1 /turtle/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
    # 1초에 한번씩 발행
    $ rostopic pub /turtle/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'

     

    'ROS > ROS1' 카테고리의 다른 글

    _ROS1_node_communication  (0) 2023.10.04
    _ROS1_roslaunch  (0) 2023.10.03
    _ROS1_package_pub&sub  (0) 2023.10.02
    _ROS1_기본 내용  (1) 2023.10.01
    _ROS1_Robot Operating System  (0) 2023.09.27
Designed by Tistory.