AI/ROS2

[ROS2] Topic 실습(Pub-Sub)

이태홍 2024. 4. 17. 23:01

 

🤖 Nodes 실행 

아래 링크의 demo_nodes_cpp와 demo_nodes_python을 가지고 와서 두 개의 node를 실행할 것이다.

 

 

https://github.com/ros2/demos

 

GitHub - ros2/demos

Contribute to ros2/demos development by creating an account on GitHub.

github.com

 

cpp로 되어있는 패키지에서 talker를 실행함과 동시에

 

py로 되어있는 패키지에서 listener를 실행한다.

 

 

/talker Node는 /chatter Topic을 publish하고 /listener Node는 /chatter Topic을 subscribe한다.

 

이를 확인하기 위해 rqt_graph를 실행한다.

 

 

아래의 사진과 같이 /talker Node는 /chatter Topic을 publish하고 /listener Node는 /chatter Topic을 subscribe 하는 것을 알 수 있다.

 

실행한 결과는 아래와 같다.

 

 

Topic으로 주고받는 Message는 integer, float, bool, string과 같은 data type 뿐만 아니라 이들을 묶은 데이터 구조(Nested Structure)를 지원한다.