상세 컨텐츠

본문 제목

ROS2 turtlesim 및 rqt 설치 실행해보기

Programming

by 신농해태 2021. 8. 20. 14:28

본문

반응형

ROS2를 설치한 후에 turtlesim을 실행해보고자 합니다. 

 

컴퓨터를 켜서 ROS2를 시작할 때마다 작업을 해야합니다. 

source /opt/ros/foxy/setup.bash 를 해야합니다.  이것이 귀찮으면

echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc 를 합니다. 

 

작업 디렉토리를 편리하게 빠르게 이동하기 위해서

pip install -U colcon-common-extensions 설치합니다.

echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc

echo "export _colcon_cd_root=~/ros2_install" >> ~/.bashrc

 

ROS의 버전을 확인합니다. 

printenv | grep -i ROS

 

turtlesim을 설치합니다. 

sudo apt update

sudo apt install ros-foxy-turtlesim

 

설치된 turtlesim 패키지를 봅니다.

ros2 pkg executables ros2 pkg executables turtlesim

패키지는 4개정도 보여줍니다.

turtlesim draw_square

turtlesim mimic

turtlesim turtle_teleop_key

turtlesim turtlesim_node

 

turtlesim을 실행합니다.

ros2 run turtlesim turtlesim_node

 

거북이를 이동시키는 프로그램을 실행합니다. 

ros2 run turtlesim turtle_teleop_key

 

turtlesim에서 이용된 노드와 토픽 등을 볼 수 있습니다. 

ros2 node list

ros2 topic list

ros2 service list

ros2 action list

 

rqt를 설치 이용하여 turtlesim을 변경해봅니다. 

rqt를 설치합니다. 

sudo apt update

sudo apt install ~nros-foxy-rqt*

그리고, 실행합니다. 

rqt

rqt 창이 나오면, Plugins / Services / Service Caller를 순서대로 클릭합니다. 

 

Service 목록창에서 /spawn을 선택 클릭합니다. 

Requenst 항목의 name에 해당하는 Expression의 맨 아래의 '' 사이에 turtle2라고 입력 하고, => 'turtle2'

x에 해당한 Expression을 1.0, y에 해당한 Expression을 1.0 입력후,

오른쪽 위의 Call 버튼을 클릭합니다. 

새로운 거북이가 생깁니다.

 

Service 목록창에서 /turtle1/set_pen을 선택 클릭합니다.

색상 r, g, b, 와 width를 변경 후, Call 버튼을 클릭합니다. 

거북이를 이동시키면 이동 흔적 선이 변경된것을 확인가능합니다. 

 

Remapping

새로운 터미널을 실행시킨 후,

ros2 run turtlesim turtle_teleop_key --ros-args --remap turtle1/cmd_vel:=turtle2/cmd_vel 입력 엔터

앞에서 새롭게 생성되었던 거북이를 이동시킬수 있습니다. 

 

종료

turtle_sim 노드 터미널에서는 Ctrl + c 입력하여 종료

teleop 터미널에서는 q를 입력하여 종료

 

 

728x90
LIST

관련글 더보기

댓글 영역