zeta2 autonomous

목표: 로봇이 자율주행 할 수 있게 한다.

이 과정에서는 로봇을 사용하여 mapping 하고 navigation 하는 것 까지 해보겠습니다.

mapping 의 방법으론 slam_tool_box 패키지와 cartographer 패키지 두개를 사용해서 해보도록 하겠습니다.

이 과정은 우분투 PC 에서 진행을 해야합니다. 패키지 또한 로봇에 설치하는 것이 아닌 PC에서 새로 만들 것입니다.

앞서 WiFi Setting을 했기 때문에 우리는 문제 없이 로봇과 연결 할 수 있습니다.

전제조건

zeta2_bringup 을 먼저 완료해야 합니다.

1 필요한 패키지들 설치

slam_tool_box 패키지와 cartographer, navigation 관련 패키지는 아래의 명령어로 설치할 수 있습니다.

sudo apt update

# slam_toolbox
sudo apt install ros-humble-slam-toolbox -y

# cartographer
sudo apt install ros-humble-cartographer -y
sudo apt install ros-humble-cartographer-ros -y

# navigation
sudo apt install ros-humble-xacro -y
sudo apt install ros-humble-navigation2 -y
sudo apt install ros-humble-nav2-bringup -y

다음으론 zeta2_autonomous 패키지를 설치하겠습니다.

Note

소스 해주기 전

과거 과정에서 소스 자동화를 하지 않았다면 여기서 해주는게 편합니다.

PC의 터미널을 열고

echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc

source ~/.bashrc

이 명령어를 입력합니다.

한 번만 입력해 두면 다음부터 새로운 터미널을 열 때 마다 자동으로 소스가 진행 됩니다.

source /opt/ros/humble/setup.bash // 위의 note 과정을 진행했으면 생략 가능

mkdir -p ~/zeta_ws/src

cd ~/zeta_ws/src
git clone https://github.com/zetabank-devteam/zeta2_edu_autonomous.git
cd ~/zeta_ws
colcon build --packages-select zeta2_navigation zeta2_slam_toolbox zeta2_cartographer
source ~/zeta_ws/install/setup.bash

Note

방금 만든 워크스페이스 소스 하는 법

우리가 만든 워크스페이스에서도 자동으로 소스를 할 수 있게 만들 수 있습니다.

PC의 터미널을 열고

echo "source  ~/zeta_ws/install/setup.bash" >> ~/.bashrc

source ~/.bashrc

이 명령어를 입력합니다.

한 번만 입력해 두면 다음부터 새로운 터미널을 열 때 마다 자동으로 소스가 진행 됩니다.

이제 필요한 패키지들은 설치가 완료 되었습니다.

2 slam tool box 매핑

먼저 로봇에 접속해 zeta2_bringup 을 실행합니다.

../../_images/1_common.png
ssh zeta@{ROBOT_IP}

ros2 launch zeta2_bringup zeta2_bringup.launch.py # if, mc, control, odom, making tf, scan, joy

새로운 터미널을 열고 이번엔 로봇에 접속하지 않고 zeta_slam_toolbox를 실행한다. (zeta_ws 를 계속 source 해줘야 합니다.)

source ~/zeta_ws/install/setup.bash

ros2 launch zeta2_slam_toolbox zeta2_slam_toolbox.launch.py
../../_images/3_toolbox.png ../../_images/4_toolbox.png

조이스틱으로 조작하며 맵을 확장해나간다.

../../_images/5_toolbox.png

rviz 화면을 보고 지도를 다 그리면 지도를 저장한다. ‘Map saved successfully’가 나오면 성공

## ros2 run nav2_map_server map_saver_cli -f {원하는 지도 이름}
## 예시

ros2 run nav2_map_server map_saver_cli -f slam_toolbox_seongsu
../../_images/6_toolbox.png

Note

실패가 나오더라도 당황하지 않고 다시 실행하면 저장 된다.

# 1차 시도

ros2 run nav2_map_server map_saver_cli -f office

[INFO] [1707357911.897409677] [map_saver]:
      map_saver lifecycle node launched.
      Waiting on external lifecycle transitions to activate
      See https://design.ros2.org/articles/node_lifecycle.html for more information.
[INFO] [1707357911.897945562] [map_saver]: Creating
[INFO] [1707357911.898317319] [map_saver]: Configuring
[INFO] [1707357911.912723324] [map_saver]: Saving map from 'map' topic to 'office' file
[WARN] [1707357911.913061451] [map_saver]: Free threshold unspecified. Setting it to default value: 0.250000
[WARN] [1707357911.913144432] [map_saver]: Occupied threshold unspecified. Setting it to default value: 0.650000
[ERROR] [1707357913.919701158] [map_saver]: Failed to spin map subscription
[INFO] [1707357913.925887446] [map_saver]: Destroying
[ros2run]: Process exited with failure 1

# 2차 시도

ros2 run nav2_map_server map_saver_cli -f office

[INFO] [1707357917.178735050] [map_saver]:
      map_saver lifecycle node launched.
      Waiting on external lifecycle transitions to activate
      See https://design.ros2.org/articles/node_lifecycle.html for more information.
[INFO] [1707357917.180127725] [map_saver]: Creating
[INFO] [1707357917.181631380] [map_saver]: Configuring
[INFO] [1707357917.192101730] [map_saver]: Saving map from 'map' topic to 'office' file
[WARN] [1707357917.192336839] [map_saver]: Free threshold unspecified. Setting it to default value: 0.250000
[WARN] [1707357917.192414894] [map_saver]: Occupied threshold unspecified. Setting it to default value: 0.650000
[WARN] [map_io]: Image format unspecified. Setting it to: pgm
[INFO] [map_io]: Received a 245 X 162 map @ 0.05 m/pix
[INFO] [map_io]: Writing map occupancy data to office.pgm
[INFO] [map_io]: Writing map metadata to office.yaml
[INFO] [map_io]: Map saved
[INFO] [1707357917.726928492] [map_saver]: Map saved successfully
[INFO] [1707357917.732879393] [map_saver]: Destroying

3 cartographer 매핑

먼저 로봇에 접속해 zeta2_bringup 을 실행합니다.

../../_images/1_common.png
ssh zeta@{ROBOT_IP}

ros2 launch zeta2_bringup zeta2_bringup.launch.py # if, mc, control, odom, making tf, scan, joy

새로운 터미널을 열고 이번엔 로봇에 접속하지 않고 zeta_cartographer를 실행한다.

ros2 launch zeta2_cartographer zeta2_cartographer.launch.py
../../_images/3_carto.png ../../_images/4_carto.png

조이스틱으로 조작하며 맵을 확장해나간다.

../../_images/5_carto.png

rviz 화면을 보고 지도를 다 그리면 지도를 저장한다. ‘Map saved successfully’가 나오면 성공

## ros2 run nav2_map_server map_saver_cli -f {원하는 지도 이름}
## 예시
ros2 run nav2_map_server map_saver_cli -f carto_seongsu
../../_images/6_carto.png

요약

slam toolboxcartographer 를 사용하여 매핑 하는 법을 배웠습니다.

navigation2 를 사용하여 자율주행 하는 법을 배웠습니다.

구체적이고 자세한 설명은 각각의 패키지들에 대한 설명사이트를 참고하시길 바랍니다.(slam_toolbox, cartographer, navigation2)

다음 단계

다음 과정에선 자율주행할 때 사용한 파라미터들에 대해서 알아보겠습니다.