-
Notifications
You must be signed in to change notification settings - Fork 0
Home
์ฐ๋ฆฌ๋ ROS_dev_template๋ผ๋ ํจํค์ง๋ฅผ ์ฌ์ฉํด์ ํ๋ก์ ํธ๋ฅผ ์งํํ๊ฒ ๋ฉ๋๋ค.
ํด๋น ํจํค์ง๋ฅผ ์ข ๋ ์ ์ฌ์ฉํ๊ณ ๋ถํ์ํ ์์ ์ ์ค์ด๊ธฐ ์ํด์ ์ฐ๋ฆฌ๋ ๋ค์ํ ์ํํธ์จ์ด ํ๋ก๊ทธ๋จ์ ์ฌ์ฉํฉ๋๋ค.
๋ฐ๋ผ์, ๊ทธ๋ฌํ ํ์ ์์ ์ฌ์ฉํ๊ณ ์๋ ์ํํธ์จ์ด ํ๋ก๊ทธ๋จ์ ์๊ฐํ๊ณ , ๊ทธ๋ฌํ ํ๋ก๊ทธ๋จ์ ์ฌ์ฉํด์ ์ด๋ ํ ์์ผ๋ก ํ๋ก์ ํธ๋ฅผ ๊ด๋ฆฌํ๊ณ ๊ตฌ์ฑํ๋ฉด ์ข์์ง์ ๋ํ ๋ด์ฉ์ ๊ณต์ ํ๋ ค๊ณ ํฉ๋๋ค.
๋๋ถ๋ถ์ ์ํํธ์จ์ด ํ๋ก๊ทธ๋จ๋ค์ ๊ธฐ๋ณธ์ ์ผ๋ก Web & App ๊ฐ๋ฐ์๋ค์ด ์ฃผ๋ก ๋ง๋ค์๊ธฐ์, nodejs ๋ฑ Web&app ๊ด๋ จ ํ๋ ์์ํฌ๋ฅผ ์ฝ๊ฒ ์ฌ์ฉํ๊ธฐ ์ํด ๊ตฌ์ฑ๋์ด์์ต๋๋ค. ์ฐ๋ฆฌ๋ ๊ทธ๋ฌํ ํ๋ก๊ทธ๋จ๋ค์ ROS2 ๊ฐ๋ฐ์ ์ฝ๊ฒ ํ๊ธฐ ์ํด ์ฌ์ฉํ ์์ ์ด๊ณ , ๊ทธ์ ๋ง๊ฒ ์ปค์คํฐ๋ง์ด์ง ํ์ฌ ์ฌ์ฉํ๋ ค ํฉ๋๋ค.
Coding Style Guide๋ ๋ฐ๋ก ์์ฑ๋ ๊ธ์ ๋ณด๋ฉด ์ข๋ ์์ธํ ์ฌ์ฉ์ ๋ํ ๋ด์ฉ์ ์ป์ ์ ์์ต๋๋ค.
์ด ๊ธ์์๋ ์ฃผ๋ก docker, git hook, vscode extension, branch์ ๋ต์ ๋ํ ๋ด์ฉ์ ์ข๋ ์์ธํ ๋ค๋ฃจ๊ฒ ์ต๋๋ค.
์ง๋ฅํ๋ก๋ด์ฌ์ ๋จ Git & Docker ์คํฐ๋
๊ธฐ๋ณธ์ ์ธ Docker์ ๋ํ ๋ด์ฉ์ ํด๋น ์คํฐ๋ ๋ด์ฉ์ ์์ธํ๊ฒ ๋ด์ ๋์์ผ๋, ์ฐ๋ฆฌ๋ ์ฐ๋ฆฌ ํ๋ก์ ํธ์ ์ ์ฉ๋์ด์๋ dockerfile, docker-compose.yaml ์ ๋ํด์ ๋ค๋ฃจ๊ณ ์ ํฉ๋๋ค.
# ROS distribution to use
ARG ROS_DISTRO=humble
########################################
# Base Image for gole Simulation #
########################################
FROM osrf/ros:${ROS_DISTRO}-desktop-full as base
ARG REPO
ENV ROS_DISTRO=${ROS_DISTRO}
SHELL ["/bin/bash", "-c"]
ARG DEBIAN_FRONTEND=noninteractive
# Install basic apt packages
RUN --mount=type=cache,target=/var/cache/apt,id=apt \
apt-get update && apt-get upgrade -y \
&& apt-get install -q -y --no-install-recommends \
build-essential \
ccache \
cmake \
lld \
python3-colcon-common-extensions \
python3-colcon-coveragepy-result \
python3-colcon-mixin \
git libcanberra-gtk-module libcanberra-gtk3-module fuse3 libqt5svg5-dev \
python3-pip python3-opencv python3-tk python3-pyqt5.qtwebengine \
&& rm -rf /var/lib/apt/lists/*
# Install additional Python modules
RUN pip3 install matplotlib transforms3d \
pytest pytest-cov pytest-mock pytest-xdist
# Use Cyclone DDS as middleware and install ros2 packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-${ROS_DISTRO}-rmw-cyclonedds-cpp \
ros-${ROS_DISTRO}-navigation2 \
ros-${ROS_DISTRO}-nav2-bringup
ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
# Create Colcon workspace with external dependencies
RUN mkdir -p /upstream_ws/src
WORKDIR /upstream_ws/src
COPY dependencies.repos .
RUN vcs import < dependencies.repos
# Build the base Colcon workspace, installing dependencies first.
WORKDIR /upstream_ws
RUN source /opt/ros/${ROS_DISTRO}/setup.bash \
&& rosdep update && apt-get update -y \
&& rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y \
&& rm -rf /var/lib/apt/lists/* \
&& colcon build --mixin release lld
# Download Groot2 AppImage and place it in the home folder.
# WORKDIR /root/
# RUN curl -o Groot2.AppImage https://s3.us-west-1.amazonaws.com/download.behaviortree.dev/groot2_linux_installer/Groot2-v1.0.1-x86_64.AppImage \
# && chmod a+x Groot2.AppImage
# Remove display warnings
RUN mkdir /tmp/runtime-root
ENV XDG_RUNTIME_DIR "/tmp/runtime-root"
RUN chmod -R 0700 /tmp/runtime-root
ENV NO_AT_BRIDGE 1
# Set up the entrypoint
WORKDIR /upstream_ws
COPY ./docker/entrypoint.sh /
ENTRYPOINT [ "/entrypoint.sh" ]
###########################################
# Overlay Image for gole Simulation #
###########################################
FROM base AS overlay
# Create an overlay Colcon workspace
RUN mkdir -p /overlay_ws/src
WORKDIR /overlay_ws
COPY ./${REPO}/ ./src/${REPO}/
RUN source /upstream_ws/install/setup.bash \
&& rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y
# && colcon build --symlink-install
# Copy the VSCode settings
COPY ./.vscode /overlay_ws/.vscode
# Set up the entrypoint
COPY ./docker/entrypoint.sh /
ENTRYPOINT [ "/entrypoint.sh" ]
#####################
# Development Image #
#####################
FROM overlay as dev
# Dev container arguments
ARG USERNAME=devuser
ARG UID=${UID}
ARG GID=${GID}
# Install extra tools for development
RUN --mount=type=cache,target=/var/cache/apt,id=apt \
apt-get update && apt-get install -y --no-install-recommends \
gdb gdbserver nano \
git \
openssh-client \
python3-pip \
vim \
wget \
&& rm -rf /var/lib/apt/lists/*
# install developer tools
RUN python3 -m pip install --no-cache-dir \
pre-commit==3.0.4
# Create new user and home directory
RUN groupadd --gid $GID $USERNAME \
&& useradd --uid ${GID} --gid ${UID} --create-home ${USERNAME} \
&& echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \
&& chmod 0440 /etc/sudoers.d/${USERNAME} \
&& mkdir -p /home/${USERNAME} \
&& chown -R ${UID}:${GID} /home/${USERNAME}
# Set the ownership of the overlay workspace to the new user
RUN chown -R ${UID}:${GID} /overlay_ws/
# Set the user and source entrypoint in the user's .bashrc file
USER ${USERNAME}
RUN echo "source /entrypoint.sh" >> /home/${USERNAME}/.bashrc
๊ธฐ๋ณธ์ ์ผ๋ก ์ฐ๋ฆฌ๊ฐ ์ฌ์ฉํ docker๋ ์ด๋ฌํ ํํ๋ฅผ ๋๊ณ ์์ต๋๋ค.
์ฐ๋ฆฌ๋ ์ด dockerfile๋ฅผ ์ธ๊ฐ์ stage(Base, overlay, dev)๋ก ๋๋์ด์ ๊ด๋ฆฌํ ์์ ์ ๋๋ค.
multi-stage์ ๊ด๋ จ๋ ๊ธ : docker multi-stage์ ๊ด๋ จ๋ ๋ด์ฉ์ ์ด ๋ด์ฉ์ ์ฐธ๊ณ ๋ฐ๋๋๋ค.
Base stage๋ ROS2 ํ๊ฒฝ setting์ ๊ด๋ จ๋ ์ค์น๊ฐ ์ ๋ถ ๋ด๊ฒจ์ ธ์๋ stage์ ๋๋ค. ์ด ๋จ๊ณ์์ ํ๋ ์ผ์ listํ ํ๊ฒ ์ต๋๋ค.
- ๊ธฐ๋ณธ์ ์ธ apt package ์ค์น
- ๊ธฐ๋ณธ์ ์ธ python package ์ค์น
- ROS2์ ๊ด๋ จ๋ ์ถ๊ฐ์ ์ธ package ์ค์น
- upstream_ws์ ์ถ๊ฐ์ ์ธ ros2 package์ค์น(์ด๋ ํด๋น ros2 package์ ๊ด๋ จ๋ ๋ด์ฉ์
[dependencies.repos](https://github.com/Kim-JeongHan/ROS_dev_template/blob/master/dependencies.repos)์ ๋ด๊ฒจ์์ต๋๋ค.) - display ๊ณต์ ๋ ๋ฐ์ํ๋ warning์ ๊ฑฐ
- source๋ฑ๋ก(?)
์ด๋ ๊ฒ 6๊ฐ์ง๊ฐ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
๐ก ์ถ๊ฐ์ ์ธ ํ๋ก์ ํธ ์งํ์ด ์์๋, ์ด 6๊ฐ์ง ํด๋น ์ฌํญ์ด ์๋ ๊ฒฝ์ฐ dockerfile์ ์ถ๊ฐํ ๋ค `feat/architecture` branch๋ฅผ ํตํด์ pull request๋ฅผ ๋ณด๋ด์ฃผ์๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค.์ฌ๊ธฐ๋ ์ฐ๋ฆฌ๊ฐ ์ฃผ๋ก ์ฌ์ฉํ๋ overlay_ws์ ๊ด๋ จ๋ ๋ด์ฉ์ด ๋ด๊ฒจ์ ธ ์์ต๋๋ค.
์ฐ๋ฆฌ๋ develop์์ ์ ์ฃผ๋ก overlay_ws์ ์งํํ๊ฒ ๋ ํ ๋ฐ ์ด๋ฅผ buildํ๊ณ ํ๋ ์์ ์ด ์ฃผ๋ก ์ฌ๊ธฐ์ ๋ค์ด๊ฐ์๋ค๊ณ ์๊ฐํ๋ฉด ๋ฉ๋๋ค.
์๋ง ํ๋ก์ ํธ๋ฅผ ์งํํจ์ ์์ด์ ์ด ๋ถ๋ถ์ ๋ํ ์์ ์ ๊ฑฐ์ ์์ ๋ฏ ์ถ์ต๋๋ค.
- overlay_ws ๊ตฌ์ฑ ๋ฐ build
๋ณดํต ์ฐ๋ฆฌ๊ฐ ๊ฐ๋ฐ์ ์งํํ ๋ ์ฌ์ฉํ ๋ด์ฉ์ด ๋ด๊ฒจ์์ต๋๋ค. ํน์ ๊ฐ๋ฐ testing์ ํ๊ณ ์ถ๋ค. ์๋ฅผ ๋ค์ด, apt package, python package, **์ผ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ**๋ฅผ ํ
์คํธ ํ๊ณ ์ถ์ ๊ฒฝ์ฐ ์ฌ๊ธฐ์ ๋จผ์ ๋ฑ๋กํด์ build test๋ฅผ ์งํํ์๋ฉด ๋ฉ๋๋ค.
์ฌ๊ธฐ์ ์ถ๊ฐํ์ฌ testing์ ์งํํ๊ณ ๊ผญ ํ์ํ๊ฑฐ๋, ํด๋น ์์ ์ด ์์ผ๋ก๋ ํ์ํ๋ค๋ฉด base ๋จ๊ณ๋ก ์ฌ๋ ค์ฃผ์๋ฉด ๋ฉ๋๋ค.
๋ณดํต ๊ฐ๋ฐ์ ํ์ํ apt, pip3์ ๋ํ ๋ด์ฉ์ด ์ฌ๊ธฐ์ ๋ด๊ฒจ์ ธ ์์ต๋๋ค.
- container arguement
- ๊ฐ๋ฐ์ ํ์ํ ์ถ๊ฐ์ ์ธ tool
- ๊ฐ๋ฐ์ ํ์ํ python ํจํค์ง
- ๊ฐ๋ฐ์ ํ์ํ home directory group์ค์ ๋ฐ ๊ถํ ์ค์
- ๊ฐ๋ฐ์ ํ์ํ bashrc ์ค์
docker-compose.yaml์ docker์์ docker build, docker run๋ฑ GUI์ฐจ์์์ ์ง์ํ๋ ๊ธฐ๋ฅ์ ๋ ์ฝ๊ฒ ์ฌ์ฉํ๊ธฐ ์ํด ๋ง๋ ์ถ๊ฐ ๊ธฐ๋ฅ ์ ๋๋ค.
๊ด๋ จ๋ ๋ด์ฉ์ด ๊ถ๊ธํ์๋ค๋ฉด ํด๋น ๋งํฌ๋ค์ ์ฝ์ด๋ณด๊ธธ ๋ฐ๋๋๋ค.
docker compose build : https://engineer-mole.tistory.com/221
docker compose : https://docs.docker.com/compose/
# Usage:
#
# To build the images:
# docker compose build
#
# To start up a specific service by name:
# docker compose up <service_name>
#
# To open an interactive shell to a running container:
# docker exec -it <container_name> bash
version: "3.9"
services:
# Base image containing dependencies.
base:
build:
context: .
dockerfile: docker/Dockerfile
args:
- REPO=${REPO}
- ROS_DISTRO=${ROS_DISTRO}
target: base
image: ${REPO}-base:${ROS_DISTRO}
# Interactive shell
stdin_open: true
tty: true
# Networking and IPC for ROS 2
network_mode: host
ipc: host
# Needed to display graphical applications
privileged: True
environment:
# Allows graphical programs in the container.
- DISPLAY=${DISPLAY}
- QT_X11_NO_MITSHM=1
- NVIDIA_DRIVER_CAPABILITIES=all
# Needed to run ROS 2 nodes
- ROS_DOMAIN_ID=${ROS_DOMAIN_ID:-0}
- TERM=xterm-256color
volumes:
# Allows graphical programs in the container.
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority
# Mount devices and configuration files
- /dev:/dev
# Mount ssh keys and git config
- ~/.ssh:${HOME}/.ssh:ro
- ~/.gitconfig:${HOME}/.gitconfig:ro
# Mount group and passwd files for user permissions
- /etc/group:/etc/group:ro
- /etc/passwd:/etc/passwd:ro
- /etc/shadow:/etc/shadow:ro
# Overlay image containing the example source code.
overlay:
extends: base
image: ${REPO}-overlay:${ROS_DISTRO}
build:
context: .
dockerfile: docker/Dockerfile
target: overlay
# Developer container
dev:
extends: overlay
image: ${REPO}-dev:${ROS_DISTRO}
build:
context: .
dockerfile: docker/Dockerfile
target: dev
args:
- UID=${UID:-1000}
- GID=${UID:-1000}
- USERNAME=${USERNAME:-devuser}
volumes:
# Mount the source code
- ./${REPO}:/overlay_ws/src/${REPO}:rw
# Mount colcon build artifacts for faster rebuilds
- ./.colcon/build/:/overlay_ws/build/:rw
- ./.colcon/install/:/overlay_ws/install/:rw
- ./.colcon/log/:/overlay_ws/log/:rw
# Mount docker directory for faster edits to Dockerfile
- ./docker:/overlay_ws/docker:rw
# Mount .devcontainer directory for faster edits to devcontainer.json
- ./.devcontainer:/overlay_ws/.devcontainer:rw
user: ${USERNAME:-devuser}
container_name: ${USER}-${REPO}-dev
command: bash -c "bash"์๊น๋ ๋น์ทํ ๋๋์ ๋๋ค. ์ฌ๊ธฐ๋ base, overlay, dev ์ธ ๊ฐ์ง๋ก ํฌ๊ฒ ๊ตฌ์ฑํ์ต๋๋ค.
์ฃผ์ ๊น๊ฒ ์๊ฐ ํด์ผ ๋ ๋ถ๋ถ์ base์ ๋ด์ฉ์ overlay๋ ์์์ ๋ฐ๊ณ ์๊ณ , dev๋ overlay๋ฅผ ์์ ๋ฐ๊ณ ์๋ค๋ ๊ฒ์ ๋๋ค.
dockerfile base stage๋ฅผ buildํ๊ณ ์์ต๋๋ค.
์ฌ์ค ์ฌ๊ธฐ๋ dockerfile์์ ์ถ๊ตฌํ๋ ๋ฐฉํฅ์ฑ๊ณผ ๋๊ฐ์ต๋๋ค. base, overlay,dev์์ ๊ณตํต์ ์ผ๋ก ์ ์ฉ ๋์ด์ผ ํ๋ ๊ฒ๋ค์ ์ ๋ถ base์ชฝ์ ๋ค์ด๊ฐ ์์ต๋๋ค.
- ํต์ ์ ์ํ setting
- volume mount
- display๋ฅผ ์ํ mount
- permission๊ณต์ ๋ฅผ ์ํ mount
- device ๊ณต์ ๋ฅผ ์ํ mount
๋ณ ๋ด์ฉ์ ์์ต๋๋ค. dockerfile overlay stage๋ฅผ buildํ๊ณ ์์ต๋๋ค.
dockerfile dev stage๋ฅผ buildํ๊ณ ์์ต๋๋ค.
volume mount๊ด๋ จ๋ ๋ด์ฉ์ ์ฐ๋ฆฌ๊ฐ ํ๋ก์ ํธ๋ฅผ ์งํํ๊ธฐ ์ํ ๋ด์ฉ์ ์ฃผ๋ก ๋ค๋ฃจ๊ณ ์์ต๋๋ค. container์ local ํ๊ฒฝ์ mount์์ผ์ ์ข ๋ ์ฝ๊ฒ ํ๋ก์ ํธ๋ฅผ ์งํํ ์ ์๊ฒ ๋์์ค๋๋ค.
- volume mount
- source code
- .colcon์์ ์๋ build, install, logํ์ผ์ container์์ ์๋ workspace์ mountํ์ฌ container๋ฅผ ๋๊ฐ๋๋ผ๋ ๋น๋ํ ํจํค์ง๋ฅผ ์ฌ ๋น๋ํ ํ์๊ฐ ์์ต๋๋ค.
- dockerfile๋ฅผ mountํ์ฌ ๋ด๋ถ container์์ dockerfile๋ฅผ ์ฝ๊ฒ ์์ ํ ์ ์๊ฒ ํด์ค๋๋ค.
- .devcontainer๋ฅผ mountํ์ฌ ๋ด๋ถ container์์ dockerfile๋ฅผ ์ฝ๊ฒ ์์ ํ ์ ์๊ฒ ํด์ค๋๋ค.
- ์ถ๊ฐ์ ์ผ๋ก ์์ ์ด ์์ ์์ ์ ๋๋ค.
์ด ํ์ผ์ docker-compose๊ธฐ๋ฅ์ ์ํํ ๋ ๋งค๊ฐ๋ณ์๋ก ๋ฃ์ด์ค ์ ์์ต๋๋ค.
๋ํ vscode extension์๋ ๊ด๋ จ์ด ์์ต๋๋ค.
REPO=gole
ROS_DISTRO=humble
PYTHONPATH=src:install/lib/python3.10/site-packages.pre-commit-config๊ด๋ จํ ๋ด์ฉ์ ๋๋ค. ์ฌ์ค ์ด ๋ถ๋ถ์ ์์ธํ๊ฒ ํ ๋ด์ฉ์ด ๋ฐ๋ก ์๊ณ ์ธ๋ฏธ๋ ํ๋ ๋ด์ฉ์ ์ฐธ๊ณ ํ๋ฉด ๋ฉ๋๋ค.
์ค์ํ ๊ฒ์ git clone์ ์งํํ ๋ค์์ pre-commit install ๋ฐ๋์ ํด์ค์ผ ํ์ฑํ ๋๋ค๋ ๊ฒ ์
๋๋ค.
์ด๋ vscode๋ฅผ ํด๋น directory์์ ํค๋ฉด ์๋์ผ๋ก docker-composeํ์ผ์ ๋ฐ๋ผ build๋ฅผ ์งํํ๊ณ , ๊ฐ๋ฐ container๋ฅผ ๊ตฌ์ฑํ ์ ์๊ฒ ํด์ฃผ๋ jsonํ์ผ์ ๋๋ค. ์ด๋ local vscode extension์ค ์ ํ์ ์ผ๋ก ๊ผญ ํ์ํ ๋ถ๋ถ์ ๊ณต์ ํ ์ ์๊ฒ extension์ถ๊ฐ๋ฅผ ํด ๋์์ต๋๋ค.
์ด ์ธ์ ์ถ๊ฐํ์ผ๋ฉด ํ๋ vscode extension๊ฐ์ ๊ฒฝ์ฐ updateํด์ฃผ์๋ฉด pull-request๋ฅผ ํตํด updateํ๊ณ ์ฌ๊ธฐ์ ๊ณต์ ํด์ฃผ์์ผ๋ฉด ํฉ๋๋ค.
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"dockerComposeFile": "../docker-compose.yaml",
"service": "dev",
"workspaceFolder" : "/overlay_ws",
// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"extensions": [
"althack.ament-task-provider",
"betwo.b2-catkin-tools",
"DotJoshJohnson.xml",
"ms-azuretools.vscode-docker",
"ms-iot.vscode-ros",
"ms-python.python",
"ms-vscode.cpptools",
"redhat.vscode-yaml",
"smilerobotics.urdf",
"streetsidesoftware.code-spell-checker",
"twxs.cmake",
"yzhang.markdown-all-in-one",
"zachflower.uncrustify"
]
}
}
}์ ๋ ํ๋ํ๋์ extension์ ๋ํ ๋ด์ฉ์ ์์ง ๋ชปํ์ฌ ์ค๋ช ์ ์๋ตํ๊ฒ ์ต๋๋ค.
๐ก ๋ง์ฝ ํ๋ก์ ํธ๋ฅผ ์งํํ๋ค ๊ณต์ ํ๊ณ ์ถ์ extension์ด ์์ผ๋ฉด ์ถ๊ฐํ ๋ค ๊ฐ๋จํ ์ค๋ช ์ ์จ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.debug๋ฐ ์คํํ์ผ์ ์คํ์ ์ํด settingํด๋์ ๋ถ๋ถ์ ๋๋ค.
F5๋ฅผ ํตํด ์ฝ๊ฒ debugํ ์ ์์ต๋๋ค.

- python : python debug์ด๋ค. ์ด๋ ํ์ฌ ๋ด๊ฐ ํค๊ณ ์๋ python file์ debuggingํ๋ค.
- gdb launch (merge-install) : [gdb debug์ ๋ํ ์ฌ์ฉ๋ฐฉ๋ฒ](https://jangpd007.tistory.com/54)
- ROS launch (merge-install) : launch.py์ ๋ํ debug
์ ํฌ๊ฐ ์ฃผ๋ก ์ฌ์ฉํ debug์ ๋๋ค.
๋ฐ๋ก ์๊ฐ์ด ์๊ธด๋ค๋ฉด vscode extension debugging๋ฅผ ์ฐธ๊ณ ํ์ฌ ์ถ๊ฐ์ ์ผ๋ก ์ค๋ช ํ๊ฒ ์ต๋๋ค.
์ด ๋ถ๋ถ์ ๊ฐ๋ฐ container์์ python, yaml, xml, c++๋ฑ์ ํธ์งํ ๋ ์ข ๋ ํธ๋ฆฌํ๊ฒ ๋ณผ ์ ์๊ฒ ํ๋ ์ค์ ์ ๋ณด๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค. ํด๋น ๋ถ๋ถ์ด ๋ง์์ ๋ค์ง ์๋๋ค๋ฉด ์์ ํ๊ฑฐ๋ ํด๋ ๋ฉ๋๋ค.
{
"editor.tabSize": 8,
"editor.rulers": [
100
],
"files.associations": {
"*.repos": "yaml",
"*.world": "xml",
"*.xacro": "xml"
},
///////////////////////////////////////////////////////
//if you don't use humble, comment out the next line
"python.analysis.extraPaths": [
"/opt/ros/humble/lib/python3.10/site-packages/"
],
// // Autocomplete from ros python packages
"python.autoComplete.extraPaths": [
"/opt/ros/humble/lib/python3.10/site-packages/"
],
// // Environment file lets vscode find python files within workspace
"python.envFile": "${workspaceFolder}/.env",
// Use the system installed version of autopep8
"python.formatting.autopep8Path": "/usr/bin/autopep8",
"python.formatting.autopep8Args": [
"--max-line-length=100"
],
"C_Cpp.default.intelliSenseMode": "linux-gcc-x86",
"C_Cpp.formatting": "disabled",
"uncrustify.configPath.linux": "/opt/ros/humble/lib/python3.10/site-packages/ament_uncrustify/configuration/ament_code_style.cfg",
"[cpp]": {
"editor.defaultFormatter": "zachflower.uncrustify"
},
//comment out this line if you don't use humble
///////////////////////////////////////////////////////
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"**/build": true,
"**/install": true,
"**/log": true
},
"cSpell.words": [
"RTPS",
"athackst",
"autopep",
"cmake",
"cppcheck",
"cpplint",
"DCMAKE",
"deque",
"devcontainer",
"ints",
"noqa",
"pytest",
"rclcpp",
"rclpy",
"repos",
"rosdep",
"rosdistro",
"rosidl",
"RTPS",
"uncrustify",
"Wextra",
"Wpedantic",
"xmllint"
],
"cSpell.allowCompoundWords": true,
"cSpell.ignorePaths": [
"**/package-lock.json",
"**/node_modules/**",
"**/vscode-extension/**",
"**/.git/objects/**",
".vscode",
".vscode-insiders",
".devcontainer/devcontainer.json"
]
}๋๋ง์ custom ๊ณต์์ ๋ง๋๋ ๊ณณ ์ ๋๋ค.
.vscode์ tasks.json ์ดํดํด๋ณด๊ธฐ
Ctrl+alt+p ๋ฅผ ๋๋ฅด๊ณ tasks๋ฅผ ๊ฒ์ํ๋ฉด ๋ณธ์ธ์ด ์ถ๊ฐํด๋์ tasks์ ๊ด๋ จ๋ ์ถ๊ฐ์ ์ธ ์๋ ๋จ์ถํค๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.

Run task์ build, clean, debug๋ฑ ๋ค์ํ ๊ธฐ๋ฅ์ ์ถ๊ฐํด๋์์ต๋๋ค. ํด๋ฆญํ๊ฒ ๋๋ฉด ์๋์ผ๋ก ํด๋น๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋ฐ์์ ์ํํ๋ ๊ธฐ๋ฅ์๋ํ ์ค๋ช ์ ํ๋์ฉ ์ค๋ช ํ๊ฒ ์ต๋๋ค.
./docker/build.sh๋ฅผ ์คํ์ํต๋๋ค.
#!/bin/bash
set -e
# Choose build
# --symlink-install : symlink the package into the install space
# --merge-install : merge all packages into one install space
# Set the default build type
BUILD_TYPE=RelWithDebInfo
colcon build \
--symlink-install \
--cmake-args "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DCMAKE_EXPORT_COMPILE_COMMANDS=On" \
-Wall -Wextra -Wpedanticbuild --symlink-install๊ณผ --merge-install ๋ฐฉ์์ค ์ ํํ ์ ์์ต๋๋ค.
์ ํฌ๋ ์ฃผ๋ก --symlink-install ๋ฐฉ์์ ์ฃผ๋ก ์ ํํด์ ์ฌ์ฉํ ์์ ์
๋๋ค.
DCMAKE_BUILD_TYPE๋ฅผ build๋ก ์ ํํฉ๋๋ค.
๋น๋๋ ํ์ผ์ ์ ๋ฆฌํ๊ณ ์ด๊ธฐ ์ํ๋ก ๋๋๋ฆฌ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. **colcon**์ ์ฌ์ฉํ์ฌ ๋น๋๋ ํ์ผ์ ์ ๊ฑฐํจ์ผ๋ก์จ ๋ค์ ๋น๋ํ ๋ ๊น๋ํ๊ฒ ์ฌ ๋น๋ํ ์ ์์ต๋๋ค. "clean" ์์
์ ์คํํ๋ฉด ํ๋ก์ ํธ์ ์์ ๋ฐ ์์ฑ๋ ํ์ผ์ ์ ๋ฆฌํ์ฌ ์ฝ๋๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ข ๋ ์ฝ๊ฒ ๋ง๋ญ๋๋ค.
colcon build --cmake-target clean./docker/build.sh๋ฅผ ์คํ์ํต๋๋ค.
DCMAKE_BUILD_TYPE๋ฅผ debug๋ก ์ ํํฉ๋๋ค.
colcon test๋ฅผ ์๋์ํต๋๋ค.
ํด๋น ๋ช
๋ น์ overlay_ws์์ ์๋์ํค๋ ๊ฒ์ ์ถ์ฒํฉ๋๋ค.
์ฐ๋ฆฌ๋ uncrustify์์ ์ ์๋ ๋ฐฉ์์ formatting๋ฐฉ์์ ์ฌ์ฉํ ์์ ์ ๋๋ค.
https://github.com/uncrustify/uncrustify
"uncrustify"๋ ์ฝ๋ ์คํ์ผ์ ์ฌ์ ๋ ฌํ๊ณ ์ผ๊ด์ฑ ์๊ฒ ์ ์งํ๊ธฐ ์ํ code formatter ๋ฐ linter์ ๋๋ค. ์ฝ๋ ํ์ผ์ ๋ค์ฌ์ฐ๊ธฐ, ๊ณต๋ฐฑ, ์ค ๋ฐ๊ฟ ๋ฑ์ ์ผ๊ด์ฑ ์๊ฒ ๋ณ๊ฒฝํ์ฌ ์ผ๊ด๋ ์ฝ๋ ๊ท์น์ ์ ์งํ๊ฒ ํฉ๋๋ค.
linter์ ๊ฐ๋ ์ ๋ํ ๊ด๋ จ๊ธ์ ์ฒจ๋ถํ์ต๋๋ค.
linter๋ฅผ ์ด์ฉํ ์ฝ๋ฉ์คํ์ผ๊ณผ ์๋ฌ ์ฒดํฌํ๊ธฐ
ROSํ๋ก๊ทธ๋๋ฐ ๊ท์น์ ๋ํ ๊ฐ๋จํ ์๋ฃ๋ฅผ ์ฒจ๋ถํ์ต๋๋ค.
fix ์ฃผ๋ก ์ฝ๋๋ฅผ ์ฌ์ ๋ ฌ ๋ฐ ๊ฐ๋ ์ฑ์ ๋์ด๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
uncrustify ์ฃผ๋ก ์ฝ๋ style ๊ฒ์ฌ ๋ฐ code linting์ ํตํด์ ์ฝ๋ ํ์๋ฌธ์ ๋ฅผ ์ฐพ์๋ ๋๋ค.
๋๋ค optionalํ ๋ถ๋ถ์ ๋๋ค.
๋ณธ์ธ์ด ์์ ํ๊ณ ์๋ c++, python ๋จ์ผ ํ์ผ์ ๊ฒ์ฌํ๊ณ ์ถ์ ๋ ์ฌ์ฉํฉ๋๋ค. code linting์ ํตํด์ ํ์๋ฌธ์ ๋ฅผ ์ฐพ์์ ์์ ํด์ค๋๋ค.
ํด๋น package๋ฅผ ์ฌ์ฉํ๊ธฐ์ํ dependencies๋ฅผ ์๋์ผ๋ก ์ฐพ์์ ์ค์นํด์ค๋๋ค. ์ด๋ฅผ ํตํด์ ์ค์น๋๋ ํ์ผ๋ค์ /opt/ros/humble ์์์ ์ฐพ์๋ณด๋ฉด ์์ต๋๋ค.
์๋ก์ด python์ด๋ c++ ํจํค์ง๋ฅผ ๋ง๋ค๋ ์ฌ์ฉํฉ๋๋ค.
์์น๋ src/gole์ ์๋์ผ๋ก ์์ฑ๋ฉ๋๋ค.
๋ณด๋ค๋ ํจ๊ณผ์ ์ธ c++๊ฐ๋ฐ์ ์ํ ํ๊ฒฝ์ค์ ์ ๋๋ค.