카테고리 없음2022. 7. 19. 22:24

전체 구성

 

1. 라즈베리파이 설정

개발환경 : Ubiquity Robotics 우분투 이미지 (우분투 16.04(Xenial) + ROS1 (kinetic))

라즈베리파이용 이미지 다운로드 : https://learn.ubiquityrobotics.com/noetic_pi_image_downloads

                                                       (중요) 2020-02-10-ubiquity-xenial-lxde 를 설치할것

 

~/catkin_ws/src 폴더에서

git clone -b v0.0.3 https://github.com/CygLiDAR-ROS/cyglidar_d1.git 

catkin_make로 시그라이다 빌드

라이다 토픽이 보이지 않는다면 USB 드라이버 설치 : https://belitino.tistory.com/140

internal compile error : Killed (program ccplus) -> swap 메모리를 확보한다 : https://changun516.tistory.com/m/105d

PL2303 드라이버가 정상 동작 하는지 확인 : $dmesg

 

2. iRobot Create3 설정

개발환경 설명서 : https://edu.irobot.com/learning-library?robotValue=Advanced%20Create%203%20Robot&toggle=lessons 

로봇에 와이파이 패스워드를 알려줘야 함 

https://edu.irobot.com/learning-library/create-3-getting-started

로봇 상태를 액세스 포인트 모드로 바꿈

로봇에 접속하고, 웹브라우저에서 192.168.10.1 주소로 접속해서

와이파이 찾고 패스워드 알려주면 로봇이 와이파이에 접속함

펌웨어는 업데이트 되어 있음

 

로봇을 재부팅하면 로봇이 와이파이 라우터에서 할당받은 192.168.0.xx 주소로 접속 가능

 

Application 메뉴에서 

로봇이름을 정해주면 해당 이름으로 토픽이 publish 됨

ROS2_DOMAIN_ID 값은 기본 '0'임. 노트북에서도 DOMAIN_ID를 같은 걸로 해야 통신이 됨.

Application restart 하면 변경 사항이 적용됨

 

노트북에서 ros2 topic list 하면 CREATE3가 보내온 토픽을 볼 수 있다

ROS2는 roscore가 없이 DDS 방식으로 노드끼리 토픽을 주고 받을 수 있다

단 ROS2_DOMAIN_ID가 동일한 장치끼리만 주고 받을 수 있으니 주의한다.

 

ros2 topic list 하면

앗 아래 캡처 그림을 보니 ROS1 명령인 rostopic list 로 CREATE3 토픽이 보이네??

ROS1에서도 로봇 토픽을 받을 수 있으면 굳이 ROS2용 cartographer를 안해도 되나??

 

노트북에서 

ros2 action send_goal /cygbot/dock irobot_create_msgs/action/DockServo "{}" 

이렇게 액션 명령을 보내면 CREATE3가 충전데크에서 분리되는 동작을 한다.

/cygbot은 Application 메뉴에서 설정한 CREATE3의 이름이다

 

3. 노트북 설정

노트북 : 우분투 20.04 (focal) + ROS1 (noetic) + ROS2 (foxy)

노트북 ROS 설치 방법 : https://docs.ros.org/ 에서 해당 버전 install 설명 참고

혹시 다른 버전을 설치 했다면, ROS 삭제 방법 ↓

더보기

ROS 버전 확인

rosversion -d

printenv ROS_DISTRO

 

ROS 패키지 삭제 (아래에서 취사 선택)

sudo apt-get purge --auto-remove ros-foxy-desktop

sudo apt-get purge --auto-remove ros-foxy-*

sudo apt-get purge ros-*

sudo apt-get autoremove

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

sudo apt update 

sudo apt autoremove 

sudo apt upgrade

 

4. 라즈베리파이에 연결된 시그라이다 토픽을 노트북에서 수신 

ROS1은 HOST에서 roscore가 동작해야 한다.

라즈베리파이에 설치한 Ubiquity 이미지는 부팅하면 자동으로 roscore가 실행된다.

따라서 라즈베리파이 ip 주소를 HOST로 등록해야 한다.

 

노트북 bash에 다음 문구를 넣어준다 (ip 주소는 라즈베리파이 주소)

export ROS_HOSTNAME=192.168.0.xx

export ROS_MASTER_URI=http://192.168.0.xx:11311 

 

노트북에서 rostopic list 를 실행하면 라즈베리파이에 연결된 cyglidar가 보낸 토픽을 볼 수 있다.

/opt/ros/noetic/setup.bash   #ROS1 환경을 로딩해야 ROS1 명령이 동작한다

rostopic list -v 

 

>> Published topics:

>> * /scan_2D [sensor_msgs/PointCloud2] 1 publisher 

 

 

5. ROS1_bridge 설치 및 빌드

라즈베리파이에 연결된 시그라이다 토픽을 ROS2 로 변경해야함

 

노트북에서 ROS2 용 워크스페이스 폴더와 소스 폴더를 만든다

mkdir ~/ros2_ws/src

 

src 폴더에서 git clone https://github.com/ros2/ros1_bridge.git 

 

bash 파일에 아래 문장을 추가해 준다. ROS1 환경과 ROS2 환경을 필요에 맞게 로딩해야 동작한다

alias로 r1, r2 를 만들어서 ROS1, ROS2 환경을 로딩하도록 만든다.

 

export ROS1_INSTALL_PATH=/opt/ros/noetic 

export ROS2_INSTALL_PATH=~/ros2_ws/install 

source ${ROS1_INSTALL_PATH}/setup.bash 

source ${ROS2_INSTALL_PATH}/setup.bash 

alias r1='source ${ROS1_INSTALL_PATH}/setup.bash'

alias r2='source ${ROS2_INSTALL_PATH}/setup.bash '

 

빌드하기 전에 src 폴더에 있는 static_bridge.cpp 를 수정한다

ROS1으로 퍼블리쉬되는 /scan_2D 토픽을 ROS2용 type로 바꿔줌

// bridge one example topic 

std::string topic_name = "scan_2D"; 

std::string ros1_type_name = "sensor_msgs/PointCloud2";

std::string ros2_type_name = "sensor_msgs/msg/PointCloud2"; 

 

소스코드를 수정하고 ~/ros2_ws 폴더에서 아래 명령을 실행해서 빌드한다

colcon build --symlink-install --packages-skip ros1_bridge

colcon build --symlink-install --packages-select ros1_bridge --cmake-force-configure

 

이유는 모르겠지만 빌드하는데 30분 이상 걸린다.

 

ROS2 galactic 에서는 빌드 에러가 없지만, foxy에서는 에러가 나므로 추가 작업을 해줘야 한다.

 

관련 패키지 디펜던시 에러가 나면 해당 패키지를 설치해 줘야 한다.

[0.561s] WARNING:colcon.colcon_core.shell:The following packages are in the workspace but haven't been built: 

- turtlebot3_msgs 

- xmlrpcpp

 

sudo apt install xmlrpcpp

 

 

만약 아래 같은 에러가 난다면

더보기

--- stderr: ros1_bridge                                                                                  
/usr/bin/ld: libros1_bridge.so: undefined reference to `ros1_bridge::Factory<controller_manager_msgs::ControllerState_<std::allocator<void> >, 

controller-manager-msgs 패키지가 문제가 되므로 일단 해당 패키지를 삭제 하고 ROS1_Bridge를 빌드한뒤 다시 설치.

관련 해결책 : https://github.com/ros2/ros1_bridge/issues/329

 

sudo apt remove ros-noetic-controller-manager-msgs   #ROS1 noetic 해당 패키지 삭제

sudo apt remove ros-foxy-controller-manager-msgs   #ROS2 foxy 해당 패키지 삭제

colcon build

sudo apt install ros-foxy-controller-manager-msgs  #재설치 (이건 안해도 동작은 하더라)

 

에러가 없다면 아래와 같이 31분에 걸쳐 빌드가 성공한다

[Processing: ros1_bridge]                                            
Finished <<< ros1_bridge [31min 17s]                                 
Summary: 15 packages finished [31min 27s]

 

아래 명령으로 static_bridge 노드를 실행하면 라즈베리파이가 보낸 ROS1 scan_2D 토픽을 받아서 ROS2로 바꿔준다

ros2 run ros1_bridge static_bridge

 

[INFO] [1657369620.191703541] [ros_bridge]: create bidirectional bridge for topic scan_2D
[INFO] [1657369620.881221371] [ros_bridge]: Passing message from ROS 1 sensor_msgs/PointCloud2 to ROS 2 sensor_msgs/msg/PointCloud2 (showing msg only once per type)

 

아래 명령으로 ROS2로 수신된 토픽을 확인 할 수 있다

ros2 topic list 

 

 

6. ROS2용 cartogrpher 를 설치

이 소스가 ROS2 galctic 버전에 설치하면 에러가 난다. 그래서 ROS2 foxy 버전을 깔아야 함.

 

https://www.theconstructsim.com/ros2-qa-223-how-to-get-robot-position-using-transforms-in-ros2/

 

위 싸이트에 나온 turtlebot SLAM cartographer를 참고했다

 

cd ~/ros2_ws/src

git clone -b foxy-devel https://github.com/ROBOTIS-GIT/turtlebot3

git clone -b foxy-devel https://github.com/ROBOTIS-GIT/turtlebot3_msgs

git clone -b foxy-devel https://github.com/ROBOTIS-GIT/turtlebot3_simulations

cd ~/ros2_ws/

colcon build

 

이렇게 하면 패키지 dependancy 에러가 몇개 뜨므로 관련 패키지를 설치해 준다.

gazebo 패키지 에러가 나면 :  sudo apt install ros-foxy-gazebo*

 

dynamixel_sdk _패키지 에러가 나면 

https://github.com/robotis-ros2-release/dynamixel_sdk-release/tree/debian/foxy/dynamixel_sdk%EF%BB%BF

의 싸이트에서 foxy용 dynamixel_sdk ZIP 파일을 다운받고 ~/ros2_ws/src 폴더에 압축을 해제한다.

src폴더 밑에 압축해제한 폴더 이름을 dunamixel_sdk 로 수정해야 빌드 된다.

colcon build --packages-select dynamixel_sdk-release

 

xmlrpcpp 에러가 나면 설치해 준다

git clone https://github.com/bpwilcox/xmlrpcpp

colcon build --packages-select xmlrpcpp

 

더보기

#ERROR
Could not find a package configuration file provided by "gazebo" with any
   of the following names:

     gazeboConfig.cmake
     gazebo-config.cmake

   Add the installation prefix of "gazebo" to CMAKE_PREFIX_PATH or set
   "gazebo_DIR" to a directory containing one of the above files.  If "gazebo"
   provides a separate development package or SDK, be sure it has been
   installed.
   
   
#SOLUTION : INSTALL GAZEBO PACKAGE for Foxy
https://answers.ros.org/question/335833/how-to-solve-the-error-of-could-not-find-a-package-gazebo/


sudo apt install ros-foxy-gazebo*

#ERROR
--- stderr: turtlebot3_node                                                                                                                                 
CMake Error at CMakeLists.txt:19 (find_package):
  By not providing "Finddynamixel_sdk.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "dynamixel_sdk", but CMake did not find one.

  Could not find a package configuration file provided by "dynamixel_sdk"
  with any of the following names:

    dynamixel_sdkConfig.cmake
    dynamixel_sdk-config.cmake

  Add the installation prefix of "dynamixel_sdk" to CMAKE_PREFIX_PATH or set
  "dynamixel_sdk_DIR" to a directory containing one of the above files.  If
  "dynamixel_sdk" provides a separate development package or SDK, be sure it
  has been installed.


#SOLUTION
#STEP 1 : looking for "CMakeLists.txt"
Error message said turtlebot3_node node's CMakeLists.txt has an error
--- stderr: turtlebot3_node                                                                                                                                 
CMake Error at CMakeLists.txt:19 (find_package):

#or you can search all folders.
find ~/ros2_ws/ -name "CMakeLists.txt" 2>/dev/null
/home/orasman/ros2_ws/src/turtlebot3/turtlebot3_node/CMakeLists.txt


#NOT WORKING
find_package(dynamixel_sdk REQUIRED) @ /home/orasman/ros2_ws/src/turtlebot3/turtlebot3_node/CMakeLists.txt


#find dynamixel_sdk : https://github.com/robotis-ros2-release/dynamixel_sdk-release/tree/debian/foxy/dynamixel_sdk

git clone https://github.com/robotis-ros2-release/dynamixel_sdk-release.git

colcon build --packages-select dynamixel_sdk-release
[0.324s] WARNING:colcon.colcon_core.package_selection:ignoring unknown package 'dynamixel_sdk-release' in --packages-select
                     
Summary: 0 packages finished [0.34s]


download foxy version from github

change the folder name as dynamixel_sdk
then it can built

colcon build --packages-select dynamixel_sdk

 

빌드를 완료하고 

ros2 launch turtlebot3_cartographer cartographer.launch.py

를 실행했는데 

PackageNotFoundError("package 'cartographer_ros' not found

이렇게 패키지를 못 찾는다는 에러가 나면 해당 패키지를 설치해 준다

(출처 : https://answers.ros.org/question/327518/cant-find-package-cartographer_ros/)

sudo apt install ros-foxy-cartographer-ros

 

이렇게 하면 터미널을 3개 열어서 gazebo, teleop_keyboard, cartographer 를 실행하면

키보드로 터틀봇을 움직으면 map 이 만들어 진다

 

ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py ros2 run turtlebot3_teleop teleop_keyboard
ros2 launch turtlebot3_cartographer cartographer.launch.py  

 

 

ROS2 topic list shows /scan, /tf, /imu etc.

 

 

 

 

 

 

7. 앞으로 할일

/scan_2D 토픽을 ROS2 토픽으로 바꿨으니 이걸 cartographer 입력으로 넣어준다

CREATE3에서 올라온 /imu /odometer 등의 토픽을 /tf로 만들어서 cartographer 입력으로 넣어준다

 keyop 소스를 변경해서 CREATE3를 원격 조정한다 (CREATE3가 제공하는 ros2 액션 명령 이용)

Posted by orasman