ROS2 foxy에서 Gazebo 예제

mseokq23·2025년 1월 15일
0

Ubuntu on WSL

목록 보기
7/11

이제 직접오브젝트를 만들어서 스폰 테스트를 해보자.

spawn_entity.py 스크립트를 사용하면 직접 작성한 SDF/URDF 파일을 Gazebo에 불러온다.
아래는 가장 간단한 SDF 예시인 “구(sphere)”를 스폰해 보는 데모이다.

  1. 테스트 SDF 파일 작성
  • sphere.sdf # 파일명, home 디렉토리에 생성
<?xml version="1.0"?>
<sdf version="1.6">
  <model name="my_sphere">
    <pose>0 0 0.5 0 0 0</pose>
    <link name="link">
      <inertial>
        <mass>1.0</mass>
        <inertia>
          <ixx>0.1</ixx>
          <ixy>0.0</ixy>
          <ixz>0.0</ixz>
          <iyy>0.1</iyy>
          <iyz>0.0</iyz>
          <izz>0.1</izz>
        </inertia>
      </inertial>
      <collision name="collision">
        <geometry>
          <sphere>
            <radius>0.5</radius>
          </sphere>
        </geometry>
      </collision>
      <visual name="visual">
        <geometry>
          <sphere>
            <radius>0.5</radius>
          </sphere>
        </geometry>
      </visual>
    </link>
  </model>
</sdf>
  1. Gazebo 서버 및 클라이언트 실행

첫번째 터미널에 입력하는 명령어(서버 호출)

ros2 launch gazebo_ros gzserver.launch.py

두번째 터미널에 입력하는 명령어(클라이언트 실행)

ros2 launch gazebo_ros gzclient.launch.py
  1. 오브젝트 스폰(spawn)

세번째 터미널을 열고 위에서 만든 파일 sphere.sdf를 불러온다.

ros2 run gazebo_ros spawn_entity.py \
  -entity my_sphere \
  -file ~/sphere.sdf

-entity 뒤의 이름(my_sphere)은 Gazebo 내부에서 구분하기 위한 모델 이름.
-file 뒤에는 실제 SDF(또는 URDF) 파일의 절대경로를 적어줘야함(우리는 home 디렉토리에 생성했기에 안해도 이대로 입력하면 될것임).

이 명령을 실행하면, Gazebo 빈 월드 안에 “구(sphere)”가 하나 떠 있는 것을 확인할 수 있다.

0개의 댓글