GAZEBO 사용하기
저작권: 쿼드(QUAD) 드론연구소 https://smartstore.naver.com/maponarooo
Gazebo 실행
이전에는 gazebo
명령어로 Gazebo를 직접 실행했지만, 이것은 ROS와 별도로 Gazebo를 실행한 것입니다. ROS 지원으로 실행하는 것은 까다로울 수 있으므로 우리를 위해 처리하는 ROS launch 파일이 제공됩니다. 아래 명령은 Gazebo를 시작하고 지정하기로 선택한 경우 특정 세계 환경을 로드합니다.
ros2 launch gazebo_ros gazebo.launch.py world:=src/robot_testing/worlds/world6.world
로봇 생성
URDF 파일을 수정한 후에는 robot_state_publisher를
실행하여 robot_description
토픽에 게시하려고 합니다. 이 작업이 완료되면 로봇을 생성하는 아래 명령을 실행할 수 있습니다.
ros2 run gazebo_ros spawn_entity.py -topic robot_description -entity my_bot
이렇게 하면 URDF robot_description
에서 설명하는 로봇이 생성되고 Gazebo 내에서 이름(some_name)
이 지정됩니다 . 파일이나 모델 데이터베이스에서 직접 로봇을 생성할 수도 있지만 대부분의 시나리오에서는 이미 실행 중인 설명 항목이 있으므로 이를 사용합니다.
launch 파일 사용하기
이 모든 프로세스를 단순화하기 위해 평소와 같이 실행 파일에 래핑할 수 있습니다. 아래 launch 파일은 robot_state_publisher
( use_sim_time
), Gazebo 실행기 및 생성기 스크립트를 실행합니다.
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
import xacro
def generate_launch_description():
# Specify the name of the package and path to xacro file within the package
pkg_name = 'urdf_example'
file_subpath = 'description/example_robot.urdf.xacro'
# Use xacro to process the file
xacro_file = os.path.join(get_package_share_directory(pkg_name),file_subpath)
robot_description_raw = xacro.process_file(xacro_file).toxml()
# Configure the node
node_robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[{'robot_description': robot_description_raw,
'use_sim_time': True}] # add other parameters here if required
)
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('gazebo_ros'), 'launch'), '/gazebo.launch.py']),
)
spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py',
arguments=['-topic', 'robot_description',
'-entity', 'my_bot'],
output='screen')
# Run the node
return LaunchDescription([
gazebo,
node_robot_state_publisher,
spawn_entity
])
Last updated