ROS 2.0 Bouncy 설치 방법

|

ROS 2.0 Bouncy 버전 설치 방법입니다. 기존에 Ardent 버전이 있었는데, 이번 여름에 Ubuntu 18.04를 지원하면서 Bouncy 버전이 새로 나왔습니다. 설치 과정이 조금 달라졌기 때문에 설치 과정을 다시 포스팅합니다.

  • Ardent 버전: Ubuntu 16.04 지원
  • Bouncy 버전: Ubuntu 16.04 / Ubuntu 18.04 지원

여기서는 Ubuntu 18.04 기준으로 설명합니다. 하지만, 16.04에서도 설치 과정은 동일합니다. 공식 페이지는 여기를 보시면 되는데, 아래 포스팅과 조금 차이가 있습니다.


Locale 설정

sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8


vcs-tool 설치

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 0xB01FA116
sudo apt-get update
sudo apt-get install python3-vcstool


기본 컴포넌트들 설치

sudo apt update && sudo apt install -y \
  build-essential \
  cmake \
  git \
  python3-colcon-common-extensions \
  python3-pip \
  wget

sudo apt install -y libpython3-dev

sudo apt install -y python-rosdep

여기에서 맨 아래에 있는 python-rosdep 항목 설치가 실패한다면 python-rosdep2로 이름 변경해서 설치를 시도해보세요.


Test를 위한 pip Package 설치

sudo -H python3 -m pip install -U \
  argcomplete \
  flake8 \
  flake8-blind-except \
  flake8-builtins \
  flake8-class-newline \
  flake8-comprehensions \
  flake8-deprecated \
  flake8-docstrings \
  flake8-import-order \
  flake8-quotes \
  pytest-repeat \
  pytest-rerunfailures

python3 -m pip install -U \
  pytest \
  pytest-cov \
  pytest-runner \
  setuptools


Fast-RTPS 라이브러리 설치

sudo apt install --no-install-recommends -y \
  libasio-dev \
  libtinyxml2-dev

ROS2 설치 파일 다운로드

여기에서 필요한 바이너리 설치 파일을 다운로드합니다. 자신의 Ubuntu 버전에 따라서 선택하시면 됩니다. 참고로 bionic가 18.04, xenial이 16.04 입니다.


다운로드한 ROS2 파일 설치

mkdir -p ~/ros2_install
cd ~/ros2_install
tar xf ~/Downloads/ros2-bouncy-linux-bionic-x86_64.tar.bz2


ROS2 Dependency 설치

sudo apt install -y python-rosdep
sudo rosdep init
sudo rosdep update

sudo rosdep install --from-paths ros2-linux/share --ignore-src --rosdistro bouncy -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 osrf_testing_tools_cpp poco_vendor rti-connext-dds-5.3.1 tinyxml_vendor tinyxml2_vendor urdfdom urdfdom_headers"


RTI Connext 설정

export RTI_LICENSE_FILE=path/to/rti_license.dat

sudo apt update && sudo apt install -q -y \
        rti-connext-dds-5.3.1

여기서 주의할 점은 RTI Connext 설치 도중 긴 스크롤 메시지를 읽고 yes를 타이핑해야 하는 절차가 있다는 점입니다.


예제 파일 실행

창 2개를 띄워놓고 다음 명령어 실행해서 잘 동작하는지 확인해봅니다.

. ~/ros2_install/ros2-linux/setup.bash
ros2 run demo_nodes_cpp talker

. ~/ros2_install/ros2-linux/setup.bash
ros2 run demo_nodes_cpp listener

Tkinter 기본 Sample Window

|

Tkinter를 이용해서 Empty Window 만들어보기

tkinter를 이용해서 빈 Window를 만들어보는 예제입니다.

만약 tkinter가 설치되어 있지 않으면 다음 명령어를 이용해서 설치할 수 있습니다. (Ubuntu 기준)

sudo apt install python-tk


예제

import tkinter as tk


def initWindow():
    window = tk.Tk()
    window.title("Simple Window")
    window.resizable(False, False)
    window.geometry("1024x768")

    window.mainloop()


def main(args=None):
    initWindow()


if __name__ == '__main__':
    main()


버튼 추가해보기

import tkinter as tk


def initWindow():
    window = tk.Tk()
    window.title("Simple Window")
    window.resizable(False, False)
    window.geometry("1024x768")

    button = tk.Button(master=window, text="Test Button", command=callback_button_clicked)
    button.pack()

    window.mainloop()


def callback_button_clicked():
    print("Button Clicked !!")


def main(args=None):
    initWindow()


if __name__ == '__main__':
    main()


간단한 이미지 출력해보기

import tkinter as tk


window = tk.Tk()
window.title("Simple Window")
window.resizable(False, False)
window.geometry("1024x768")

canvas = tk.Canvas(window, width=1024, height=768)
canvas.pack(expand=tk.YES, fill=tk.BOTH)

img = tk.PhotoImage(file="01.png")
canvas.create_image(20, 20, anchor=tk.NW, image=img)

window.mainloop()

Terminator 사용자 정의 세팅하는 방법

|

Terminator Config

terminator는 개인적으로 많이 애용하고 있는 터미널 프로그램입니다. 사용자 정의 세팅을 하는 방법은 다음과 같습니다.

만약 ~/.config/terminator/config 파일이 없으면 새로 만들어주면 됩니다.


~/.config/terminator/config

[global_config]
  handle_size = 0
  focus = system
[keybindings]
[layouts]
  [[default]]
    [[[child1]]]
      parent = window0
      type = Terminal
    [[[window0]]]
      parent = ""
      size = 1200, 600
      type = Window
[plugins]
[profiles]
  [[default]]
    scrollbar_position = hidden
    scrollback_infinite = True
    use_system_font = False
    background_darkness = 0.9
    background_type = transparent
    background_image = None
    show_titlebar = False
    font = D2Coding 12

저는 스크롤바가 화면에 있는게 더 편해서 위 설정에서 scrollbar_position = hidden 항목은 제외합니다.


Terminator 단축키

  • 위/아래로 화면 나누기 : Ctrl + Shift + O
  • 좌/우로 화면 나누기 : Ctrl + Shift + E
  • 현재 화면 닫기 : Ctrl + Shift + W

  • 화면간 이동 : Alt + 방향키

  • 스크롤바 Toggle : Ctrl + Shift + S

  • 검색 : Ctrl + Shift + F
  • 화면 Clear : Ctrl + Shift + G

Git Submodule 삭제 방법

|

Git Submodule 삭제 방법

먼저 git submodule deinit -f 명령어를 통해서 해당 모듈을 deinit 해줍니다.

git submodule deinit -f test_app

그 다음 .git/modules 폴더에 들어가서 해당 폴더를 삭제합니다.

rm -rf .git/modules/test_app

마지막으로 git에서 해당 폴더를 제거해주면 됩니다.

git rm -f test_app

curl 사용법

|

CURL 사용방법

참고 : https://gist.github.com/subfuzion/08c5d85437d5d4f00e58

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

-d, --data <data> Send specified data in POST request. Details provided below.

-f, --fail Fail silently (don’t output HTML error form if returned).

-F, --form <name=content> Submit form data.

-H, --header <header> Headers to supply with request.

-i, --include Include HTTP headers in the output.

-I, --head Fetch headers only.

-k, --insecure Allow insecure connections to succeed.

-L, --location Follow redirects.

-o, --output <file> Write output to . Can use `--create-dirs` in conjunction with this to create any directories specified in the `-o` path.

-O, --remote-name Write output to file named like the remote file (only writes to current directory).

-s, --silent Silent (quiet) mode. Use with -S to force it to show errors.

-v, --verbose Provide more information (useful for debugging).

-w, --write-out <format> Make curl display information on stdout after a completed transfer. See man page for more details on available variables. Convenient way to force curl to append a newline to output: -w "\n" (can add to ~/.curlrc).

-X, --request The request method to use.

POST

When sending data via a POST or PUT request, two common formats (specified via the Content-Type header) are:

  • application/json
  • application/x-www-form-urlencoded

Many APIs will accept both formats, so if you’re using curl at the command line, it can be a bit easier to use the form urlencoded format instead of json because

  • the json format requires a bunch of extra quoting
  • curl will send form urlencoded by default, so for json the Content-Type header must be explicitly set

This gist provides examples for using both formats, including how to use sample data files in either format with your curl requests.

curl usage

For sending data with POST and PUT requests, these are common curl options:

  • request type
    • -X POST
    • -X PUT
  • content type header
  • -H "Content-Type: application/x-www-form-urlencoded"
  • -H "Content-Type: application/json"

  • data
    • form urlencoded: -d "param1=value1&param2=value2" or -d @data.txt
    • json: -d '{"key1":"value1", "key2":"value2"}' or -d @data.json


Examples

POST application/x-www-form-urlencoded

application/x-www-form-urlencoded is the default:

curl -d "param1=value1&param2=value2" -X POST http://localhost:3000/data

explicit:

curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/data

with a data file

curl -d "@data.txt" -X POST http://localhost:3000/data

POST application/json

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

with a data file

curl -d "@data.json" -X POST http://localhost:3000/data

data.json

{
  "key1":"value1",
  "key2":"value2"
}

data.txt

param1=value1&param2=value2

package.json

{
  "name": "postdemo",
  "version": "1.0.0",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "body-parser": "^1.15.0",
    "express": "^4.13.4"
  }
}

server.js

var app = require('express')();
var bodyParser = require('body-parser');

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

app.post('/data', function (req, res) {
  console.log(req.body);
  res.end();
});

app.listen(3000);