마우스 오른 버튼 메뉴에 New Document 항목 생성하기

|

New Document 옵션 살리기 on Ubuntu 18.04

Ubuntu 16.04 까지는 마우스 오른 버튼 메뉴에 New Document 항목이 있었는데 Ubuntu 18.04에서는 이 항목이 사라졌습니다. 다음 방법을 이용해서 New Document 항목을 살릴 수 있습니다.

터미널을 열고 다음 명령어를 입력한다.

touch ~/Templates/"Empty Document.txt"

디렉토리 명에서 알 수 있듯이, 위에서 생성한 문서 안에 특정 문구들을 저장해놓으면 새로운 문서를 생성할 때마다 해당 내용들을 템플릿처럼 사용할 수 있습니다.

Git 브랜치를 Master 브랜치로 변경하는 방법

|

Git 브랜치를 Master 브랜치로 변경하는 법

  • 참고 : https://code.i-harness.com/ko/q/2a28fe

그 전에 모든 수정 사항이 원격 저장소에 push 되어 있는지 확인해야 합니다.

그 이후 다음 명령어를 입력합니다.

git checkout master

masterbetter_branch로 덮어 씁니다.

git reset --hard better_branch

그 이후 강제로 원격 저장소에 push 해 줍니다.

git push -f origin master

Oreo 버전 이후 Foreground Service 사용 방법

|

Oreo 버전 이후 Foreground Service 사용 방법

안드로이드 Oreo 버전 이후부터는 Foreground Service를 사용하는 방법이 약간 변경되었습니다. Foreground Service를 만들기 위한 조건은 다음과 같습니다.

  • 상태바에Notification을 등록해서 사용자가 인지할 수 있게 해야 한다.
  • Notification의 id는 0이 아니어야 한다.

예제 코드는 다음과 같습니다. Notification을 클릭하면 MainActivity로 이동하도록 PendingIntent를 등록했으며, 사용자 정의 Notification을 보여주도록 했습니다.


SnowDeerService.java

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.widget.RemoteViews;

public class SnowDeerService extends Service {

  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }

  @Override
  public void onCreate() {
    super.onCreate();

    startForegroundService();
  }

  void startForegroundService() {
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_service);

    NotificationCompat.Builder builder;
    if (Build.VERSION.SDK_INT >= 26) {
      String CHANNEL_ID = "snwodeer_service_channel";
      NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
          "SnowDeer Service Channel",
          NotificationManager.IMPORTANCE_DEFAULT);

      ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
          .createNotificationChannel(channel);

      builder = new Builder(this, CHANNEL_ID);
    } else {
      builder = new Builder(this);
    }
    builder.setSmallIcon(R.mipmap.ic_launcher)
        .setContent(remoteViews)
        .setContentIntent(pendingIntent);

    startForeground(1, builder.build());
  }
}

Oreo 버전 부터는 Notification에 채널 ID를 지정해줘야 합니다. 그리고 Notification을 등록하기 위해서는 아이콘, 제목, 내용이 전부 있어야 가능합니다.

서비스를 호출하는 방법도 변경이 있습니다. 기존의 startService() 대신 startForegroundService() 라는 메소드를 이용해서 서비스를 시작해야 합니다.


MainFragment.java

저는 Fragment 내부의 버튼을 이용해서 서비스 시작을 했지만, Actvity의 경우에도 동일합니다.

@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_main, container, false);

    view.findViewById(R.id.start_service_button).setOnClickListener(view1 -> {
      Intent intent = new Intent(getContext(), SnowDeerService.class);
      if (Build.VERSION.SDK_INT >= 26) {
        getContext().startForegroundService(intent);
      }
      else {
        getContext().startService(intent);
      }
    });

    view.findViewById(R.id.stop_service_button).setOnClickListener(view12 -> {
      Intent intent = new Intent(getContext(), SnowDeerService.class);
      getContext().stopService(intent);
    });

    return view;
  }

Visual Studio Code 자동 줄바꿈 옵션 켜기

|

Visual Studio Code 자동 줄바꿈 켜기

File > Preferences > Settings 메뉴에 들어갑니다. 단축키로는 Ctrl + , 입니다.

실행 후, 오른 편의 사용자 정의 세팅에서

"editor.wordWrap": "on",

항목을 추가해주면 됩니다.

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