본문 바로가기
Robot/ROS

[MicroROS] MicroROS + Arduino DUE 튜토리얼

by interactics 2022. 7. 24.

레퍼런스

https://github.com/micro-ROS/micro_ros_arduino

 

GitHub - micro-ROS/micro_ros_arduino: micro-ROS library for Arduino

micro-ROS library for Arduino. Contribute to micro-ROS/micro_ros_arduino development by creating an account on GitHub.

github.com

 

Micro-ROS

 

ROS1에서는 아두이노, STM 등 MCU와 통신하기 위해 ROSSerial 을 사용했습니다만

ROS2로 넘어오면서 Micro-ROS로 전환되었습니다.

 

기존 로스시리얼은 시리얼통신만 가능했던 부분에서 마이크로로스는 CAN이나 이더넷, Wi-Fi로도 가능하게 되었고
클라이언트 라이브러리도 전반적으로 ROS2와 유사성을 띄는 등 장점을 가집니다.

 

하지만 아직까지 베타의 형태로 공식적으로 지원되는 보드가 한정적이라 살짝 까다롭긴 합니다.

 

기본적으로 지원되는 보드들 2022년 7월 24일

아두이노 시리즈 중 고성능 모델인 Arduino Due에 마이크로로스를 탑재하는 튜토리얼을 작성해보고자 합니다.

 

아트메가를 사용하는 아두이노 우노나 메가는 연산 성능이나 메모리 한계 때문에 적용이 어려운 듯 보입니다.

 

Arduino DUE 스펙

 

 

Arduino DUE의 스펙으로

마이크로컨트롤러는 AT91SAM3X8E으로 ARM Cortex M3 아키텍처에 최대 84MHz 사양을 지원하고 플래시메모리는 512MB를 가집니다.

 

 

 

Micro-ROS 설치

본인의 ROS2 워크스페이스에서 작업합니다.

#본인의 ROS2 워크스페이스에서 작업하면 됩니다.
cd ~/robot2_ws/src 
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git

# rosdep으로 의존 패키지 업데이트
sudo apt update && rosdep update
rosdep install --from-paths src --ignore-src -y

# pip 설치
sudo apt-get install python3-pip

# micro-ROS tools 과 소스 빌드
cd ~/robot2_ws
colcon build --packages-select micro_ros_setup
source install/local_setup.bash

 

마이크로 로스 에이전트 패키지를 설치합니다.

 

# micro-ROS agent 패키지 설치

cd ~/robot_ws
ros2 run micro_ros_setup create_agent_ws.sh

ros2 run micro_ros_setup build_agent.sh
source install/local_setup.bash

 

설치가 완료되면 테스트해봅니다.

 

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0

다음 사진처럼 표현이 되면 설치가 된 것입니다.

 

 

라이브러리 설치하기

https://github.com/micro-ROS/micro_ros_arduino/releases

 

Releases · micro-ROS/micro_ros_arduino

micro-ROS library for Arduino. Contribute to micro-ROS/micro_ros_arduino development by creating an account on GitHub.

github.com

다음의 레포지터리에서 본인의 ROS2 버전에 맞는 소스를 다운로드합니다.

 

아두이노 IDE에서

Sketch -> Include library -> Add .ZIP Library를 통해 다운로드한 라이브러리를 추가해줍니다.

추가 후에 보드 설정을 Arduino DUE로 적용하면 다음과 같이 Example에 MicroROS 예제를 확인할 수 있습니다.

이 상태로 빌드하게 되면 

undefined reference to `rcl_publish'

undefined reference to `rmw_uros_set_custom_transport'

등과 같은 에러메시지를 보게 됩니다.

 

Files -> Preferences에 들어갑니다.

하단 "More preferences can be edited directly in the file" 아래의 주소를 클릭합니다.

 

아래와 같이 파일구조가 이루어져있다는 것을 볼 수 있습니다.

여기서 packages -> arduino -> hardware -> sam -> 1.6.12(버전) 아래의 platform.txt를 바꿔야합니다.

해당 위치까지 터미널로 들어가 

 

curl https://raw.githubusercontent.com/micro-ROS/micro_ros_arduino/main/extras/patching_boards/platform_arduinocore_sam.txt > platform.txt

 

다음의 명령어로 업데이트 해줍니다.

 

이를 업로드합니다.

 

 

실행하기

 

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0

를 입력합니다.

여기서 /dev/ttyACM0 대신 본인의 디바이스 주소로 바꿔줍니다.

이렇게 연결되며 

 

다음과 같이 연결되는 것을 확인할 수 있습니다.

 

 

'Robot > ROS' 카테고리의 다른 글

[ROS2] 치트시트  (0) 2022.08.14
[MicroROS] 참고할만한 자료들  (0) 2022.08.06
[MicroROS] Publisher와 Subscriber 생성하기  (2) 2022.08.06
[MicroROS] ST Nucleo에 MicroROS 설치하기  (1) 2022.06.29
[ROS2] zsh 자동완성 이슈  (0) 2022.06.28

댓글