๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

SW/ROS2 & Linux

ROS2) bashrc ํŒŒ์ผ๋กœ alias ๋ช…๋ น์–ด ๋งŒ๋“ค์–ด๋ณด๊ธฐ

23.10.04   ์ง‘ํ•„

24.02.25   1์ฐจ ์ˆ˜์ •

25.07.15   2์ฐจ ์ˆ˜์ •

 

--- INDEX ---

0. ์žก ์„œ๋ก 
1. .bashrcํŒŒ์ผ
2. alias ์„ค์ •
3. ROS2 ๊ธฐ๋ณธ .bashrc

--- --- ---

 

0. ์žก ์„œ๋ก 

.bashrc ํŒŒ์ผ

์ด๊ฒŒ ๋ญ˜๊นŒ? ๋ญ”๋ฐ ROS๋ฅผ ๋งŒ์ง€๋Š”๋ฐ ๊ฐ‘์ž๊ธฐ ๋œฌ๊ธˆ์—†์ด ๊ฑด๋“ค์ผ๊นŒ..?

์‚ฌ์‹ค ROS๋ž‘์€ ํฐ ์ƒ๊ด€์€ ์—†๋Š”๋ฐ, ROS๋ฅผ ์กฐ๋ชฐ๋”ฑ ๊ฑฐ๋ฆฌ๋Š”๋ฐ์— ์žˆ์–ด์„œ bashrc๋ฅผ ๊ฑด๋“œ๋Š”๊ฒŒ ํŽธ๋ฆฌํ•˜๊ธฐ๋•Œ๋ฌธ์— ๋งŒ์ง€์ž‘ ๊ฑฐ๋ ค๋ดค๋‹ค.

 

 

1. .bashrc ํŒŒ์ผ?

bashrc๋Š” ์‚ฌ์šฉ์ž๋งˆ๋‹ค run command๋“ค์„ ๋ชจ์•„๋‘๋Š” ํŒŒ์ผ์ธ๋ฐ, ์—ฌ๊ธฐ์— ๋‹ค์–‘ํ•œ ๋‹จ์ถ•ํ‚ค(alias)๊ฐ™์€๊ฒŒ ๋“ฑ๋ก๋˜์–ด์žˆ๋‹ค.

bash๊ฐ€ ์ผœ์งˆ ๋•Œ ๋งˆ๋‹ค ์ด ํŒŒ์ผ์„ ํ•œ๋ฒˆ ์ฝ๊ณ  ์ผœ์ง€๋ฏ€๋กœ, ์‹คํ–‰ํ•  ํŒŒ์ผ์ด ๋งŽ์€ ROS์—์„œ๋Š”, bashrc์— ๊ธฐ๋ณธ์ ์œผ๋กœ ์‹คํ–‰ ๋ช…๋ น์–ด๋“ค์„ ๋„ฃ์–ด๋‘๋ฉด, bash๋ฅผ ์ƒˆ๋กœ ์—ฌ๋Š” ๊ฒƒ ๋งŒ์œผ๋กœ๋„ ์‹คํ–‰ ๋ช…๋ น์–ด๋“ค์„ ๋ชจ์กฐ๋ฆฌ ํ•œ๋ฒˆ์”ฉ ์ฝ๊ณ  ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™๋‹ค.

 

๊ทธ๋Ÿฌ๋‹ˆ๊นŒ, ์งง๊ฒŒ ๋งํ•˜๋ฉด.. RPG๊ฒŒ์ž„์—์„œ ๊ธฐ๋ณธ๋Šฅ๋ ฅ์น˜ ๊ฐ•ํ™”ํ•˜๋Š” ์Šคํ‚ฌ์ด ์žˆ์—ˆ๋Š”๋ฐ, ์ด๋ฅผ ํŒจ์‹œ๋ธŒ๋กœ ๋ฐ”๊พผ ๋А๋‚Œ์ด๋‹ค.

 

๋‹ค์–‘ํ•œ ํŽธ์ง‘๊ธฐ๋“ค์„ ์ด์šฉํ•ด ์—ฌ๊ธฐ์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ์œผ๋‚˜(vi, gefit, vim ๋“ฑ), ํ•„์ž๋Š” vscode๋ฅผ ๊น”์•„๋’€์œผ๋ฏ€๋กœ vscode๋ฅผ ์ด์šฉํ•ด๋ณด์ž.

 

$ cd
$ code .

ํ™ˆ์—์„œ vscode๋ฅผ ์—ด๋ฉด 

์ˆจ์–ด์žˆ๋˜ ํŒŒ์ผ๋“ค์ด ๋ณด์ธ๋‹ค. Linux๊ธฐ๋ฐ˜์˜ OS์—์„œ " . "(๋งˆ์นจํ‘œ)๋กœ ์‹œ์ž‘ํ•˜๋Š” ํŒŒ์ผ์€ ์ˆจ๊น€ํŒŒ์ผ์ด๊ธฐ ๋•Œ๋ฌธ์— ls๋ช…๋ น์œผ๋กœ ๋ณด์ด์ง€ ์•Š์•˜์„ ๊ฒƒ์ด๋‹ค.

์ด์—, .bashrc๋ฅผ ํด๋ฆญํ•ด์ฃผ๋ฉด,

๋”๋ณด๊ธฐ
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

์ด๋Ÿฐ ์ฝ”๋“œ๊ฐ€ ์žˆ์„ํ…๋ฐ, ์ œ์ผ ๋งˆ์ง€๋ง‰์— ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

echo "ROS2 humble has been activated"
source /opt/ros/humble/setup.bash

setup.bash๋Š” ros2๋ฅผ ์“ฐ๋ฉด์„œ ํ•ญ์ƒ ๋Œ๋ ค์•ผ๋˜๋Š” ์ฝ”๋“œ์ด๊ธฐ์—, ์œ„์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ–ˆ๋‹ค.

.bashrcํŒŒ์ผ์ด ๋ณ€๊ฒฝ๋˜์—ˆ์œผ๋ฏ€๋กœ, 

source ~/.bashrc

์„ ์ž…๋ ฅํ•˜์—ฌ bashrc๋ฅผ ๋‹ค์‹œ ์ฝํ˜€์ค˜์•ผ ํ•œ๋‹ค.

 

์ด์ œ, ํ„ฐ๋ฏธ๋„์„ ์ผค ๋•Œ ๋งˆ๋‹ค "ROS2 humble has been activated"๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๊ณ„์† ๋œจ๊ฒŒ ๋œ๋‹ค.

 

 

2. alias ์„ค์ •

bashrcํŒŒ์ผ์— souce๋กœ ์ง์ ‘์ ์œผ๋กœ ๋„ฃ์–ด๋‘๋ฉด, ํ„ฐ๋ฏธ๋„์ด ์ผœ์งˆ๋•Œ๋งˆ๋‹ค ์ž๋™์œผ๋กœ ros์˜ setupํŒŒ์ผ์ด ์ผœ์ง€์ง€๋งŒ,

๋‚ด๊ฐ€ ๋”ฐ๋กœ ๋ช…๋ น์–ด๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‹คํ–‰ํ•˜๊ณ  ์‹ถ์„๋•Œ๋งŒ ๊ฐ„ํŽธํ•˜๊ฒŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์œ„์˜ 1๋ฒˆ์—์„œ ์ถ”๊ฐ€ํ–ˆ๋˜ ์ฝ”๋“œ ์—†์ด ์•„๋ž˜์˜ ์ฝ”๋“œ๋งŒ ๋„ฃ์–ด๋ณด์ž.

alias qwe="source /opt/ros/humble/setup.bash; echo \" activbated \""

๊ทธ๋Ÿฌ๊ณ ๋‚˜์„œ ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ๋„ˆ๋ฏธ๋„์ฐฝ์— ์ž…๋ ฅํ•ด์•ผ ์ ์šฉ๋œ๋‹ค.

source ~/.bashrc

 

 

์ด์ œ qwe๋ผ๋Š” ๋Œ€์ถฉ๋งŒ๋“  "๋ช…๋ น์–ด"๊ฐ€ ์ƒ๊ธด๊ฑฐ๋‹ค.

์ผ์ผ€ ๋œ๋‹ค.

 

 

3. ROS ๊ธฐ๋ณธ .bashrc

๋„ค์ด๋ฒ„ ์นดํŽ˜ "์˜ค๋กœ์นด"์˜ ํ‘œ์œค์„๋ฐ•์‚ฌ๋‹˜ bashrc๋‚ด์šฉ์„ ๊ฐ€์ ธ์™”๋‹ค.

์ผ๋‹จ ์ถœ์ฒ˜๊ณ  ๋ญ๊ณ  ๋‹ค ์ ์–ด๋†“๊ฒ ์ง€๋งŒ ๋‚ด๊ฐ€ ๋ณผ๋ ค๊ณ  ๊ฐ€์ ธ์˜จ๊ฑฐ๋ผ... ๋ฌธ์ œ์‹œ ์‚ญ์ œํ•จ ใ… 

 

https://cafe.naver.com/openrt/25288

 

001 ROS 2 ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ•

Created Date: 2020.07.13 Modified Date: 2022.02.03 revision 34 * ๋กœ๋ด‡ ์šด์˜์ฒด์ œ ROS ๊ฐ•์ขŒ ๋ชฉ์ฐจ: https://cafe...

cafe.naver.com

source /opt/ros/humble/setup.bash
source ~/robot_ws/install/local_setup.bash

source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash
source /usr/share/vcstool-completion/vcs.bash
source /usr/share/colcon_cd/function/colcon_cd.sh
export _colcon_cd_root=~/robot_ws

export ROS_DOMAIN_ID=7
export ROS_NAMESPACE=robot1

export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
# export RMW_IMPLEMENTATION=rmw_connext_cpp
# export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
# export RMW_IMPLEMENTATION=rmw_gurumdds_cpp

# export RCUTILS_CONSOLE_OUTPUT_FORMAT='[{severity} {time}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})'
export RCUTILS_CONSOLE_OUTPUT_FORMAT='[{severity}]: {message}'
export RCUTILS_COLORIZED_OUTPUT=1
export RCUTILS_LOGGING_USE_STDOUT=0
export RCUTILS_LOGGING_BUFFERED_STREAM=1

alias cw='cd ~/robot_ws'
alias cs='cd ~/robot_ws/src'
alias ccd='colcon_cd'

alias cb='cd ~/robot_ws && colcon build --symlink-install'
alias cbs='colcon build --symlink-install'
alias cbp='colcon build --symlink-install --packages-select'
alias cbu='colcon build --symlink-install --packages-up-to'
alias ct='colcon test'
alias ctp='colcon test --packages-select'
alias ctr='colcon test-result'

alias rt='ros2 topic list'
alias re='ros2 topic echo'
alias rn='ros2 node list'

alias killgazebo='killall -9 gazebo & killall -9 gzserver  & killall -9 gzclient'

alias af='ament_flake8'
alias ac='ament_cpplint'

alias testpub='ros2 run demo_nodes_cpp talker'
alias testsub='ros2 run demo_nodes_cpp listener'
alias testpubimg='ros2 run image_tools cam2image'
alias testsubimg='ros2 run image_tools showimage'
[์ถœ์ฒ˜] 001 ROS 2 ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ• (์˜คํ”ˆ์†Œ์Šค ์†Œํ”„ํŠธ์›จ์–ด & ํ•˜๋“œ์›จ์–ด: ๋กœ๋ด‡ ๊ธฐ์ˆ  ๊ณต์œ  ์นดํŽ˜ (์˜ค๋กœ์นด)) | ์ž‘์„ฑ์ž ํ‘œ์œค์„

 

 

4. ์ฃผ์˜์‚ฌํ•ญ

๊ธฐ์กด์˜ .bashrc์˜ ๋‚ด์šฉ์„ ์ง€์šฐ๊ณ  ์˜ฎ๊ธฐ์ง€ ์•Š๋Š”๊ฒƒ์„ ๋งค์šฐ ๊ฐ•๋ ฅํžˆ ๊ถŒ๊ณ ํ•œ๋‹ค.

๊ธฐ์กด์— ์šฐ๋ฆฌ๊ฐ€ CLIํ™˜๊ฒฝ์—์„œ ์ปค๋ฉ˜๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด์„œ ์ƒ‰๊น”์ด ๋ณ€ํ•˜๋˜ ๊ฒƒ๋“ค๋„ ๋‹ค .bashrc์— ๋“ฑ๋ก๋˜์–ด์žˆ๋Š” ๊ฒƒ์ด๊ธฐ์—,,,

๊ธฐ์กด์˜ ๋‚ด์šฉ์„ ์ง€์šฐ๋ฉด "๊ต‰์žฅํžˆ ๋ถˆํŽธํ•œ", ํฐ์ƒ‰๊ณผ ๊ฒ€์€์ƒ‰๋ฐ–์— ๋ณผ ์ˆ˜ ์—†๋Š” ์„๊ธฐ์‹œ๋Œ€๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.

 

ํ•„์ž๋„ ์‚ฌ์‹ค ์•Œ๊ณ ์‹ถ์ง€ ์•Š์•˜๋‹ค.. ํŠนํžˆ WSLํ™˜๊ฒฝ์—์„œ ์ด๊ฑธ ์ง€์› ๋‹ค๋ฉด, ์•ˆ๊ทธ๋ž˜๋„ ์ชผ๋„๋งŒ ํ™˜๊ฒฝ์—์„œ ๋ณด์ด์ง€๋„ ์•Š๋Š” ๊ฒ€ํฐํ™”๋ฉด์— ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์•ผํ•œ๋‹ค.