quadruped_ros2_control/descriptions/unitree/b2_description/launch/visualize.launch.py

49 lines
1.5 KiB
Python
Raw Normal View History

2024-09-30 17:48:59 +08:00
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
import xacro
package_description = "b2_description"
2024-10-10 22:44:32 +08:00
def process_xacro():
2024-09-30 17:48:59 +08:00
pkg_path = os.path.join(get_package_share_directory(package_description))
xacro_file = os.path.join(pkg_path, 'xacro', 'robot.xacro')
2024-10-10 22:44:32 +08:00
robot_description_config = xacro.process_file(xacro_file)
2024-09-30 17:48:59 +08:00
return robot_description_config.toxml()
2024-10-10 22:44:32 +08:00
def generate_launch_description():
rviz_config_file = os.path.join(get_package_share_directory(package_description), "config", "visualize_urdf.rviz")
robot_description = process_xacro()
2024-09-30 17:48:59 +08:00
2024-10-10 22:44:32 +08:00
return LaunchDescription([
Node(
package='rviz2',
executable='rviz2',
name='rviz_ocs2',
output='screen',
arguments=["-d", rviz_config_file]
),
2024-09-30 17:48:59 +08:00
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='screen',
parameters=[
{
'publish_frequency': 100.0,
'use_tf_static': True,
'robot_description': robot_description
}
],
),
Node(
package='joint_state_publisher_gui',
executable='joint_state_publisher_gui',
name='joint_state_publisher',
output='screen',
)
])