quadruped_ros2_control/descriptions/unitree/go1_description/launch/ocs2_control.launch.py

110 lines
3.7 KiB
Python
Raw Normal View History

2024-09-11 11:32:54 +08:00
import os
import xacro
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import OpaqueFunction, RegisterEventHandler
2024-09-19 14:00:43 +08:00
from launch.event_handlers import OnProcessExit
2024-09-11 11:32:54 +08:00
from launch.substitutions import PathJoinSubstitution
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
package_description = "go1_description"
2024-09-30 20:06:20 +08:00
package_controller = "ocs2_quadruped_controller"
2024-09-11 11:32:54 +08:00
def process_xacro():
2024-09-11 11:32:54 +08:00
pkg_path = os.path.join(get_package_share_directory(package_description))
xacro_file = os.path.join(pkg_path, 'xacro', 'robot.xacro')
robot_description_config = xacro.process_file(xacro_file)
return robot_description_config.toxml()
2024-09-11 11:32:54 +08:00
def generate_launch_description():
rviz_config_file = os.path.join(get_package_share_directory(package_controller), "config", "visualize_ocs2.rviz")
2024-09-11 11:32:54 +08:00
robot_description = process_xacro()
2024-09-11 11:32:54 +08:00
robot_controllers = PathJoinSubstitution(
[
FindPackageShare(package_description),
"config",
"robot_control.yaml",
]
)
2024-09-19 14:00:43 +08:00
robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
parameters=[
{
'publish_frequency': 20.0,
'use_tf_static': True,
'robot_description': robot_description,
'ignore_timestamp': True
}
],
)
controller_manager = Node(
package="controller_manager",
executable="ros2_control_node",
2024-09-28 23:05:13 +08:00
parameters=[robot_controllers,
{
'urdf_file': os.path.join(get_package_share_directory(package_description), 'urdf',
'robot.urdf'),
2024-09-28 23:05:13 +08:00
'task_file': os.path.join(get_package_share_directory(package_description), 'config', 'ocs2',
'task.info'),
'reference_file': os.path.join(get_package_share_directory(package_description), 'config',
'ocs2', 'reference.info'),
'gait_file': os.path.join(get_package_share_directory(package_description), 'config',
'ocs2', 'gait.info')
2024-09-28 23:05:13 +08:00
}],
2024-09-19 14:00:43 +08:00
output="both",
)
joint_state_publisher = Node(
package="controller_manager",
executable="spawner",
arguments=["joint_state_broadcaster",
"--controller-manager", "/controller_manager"],
)
imu_sensor_broadcaster = Node(
package="controller_manager",
executable="spawner",
arguments=["imu_sensor_broadcaster",
"--controller-manager", "/controller_manager"],
)
2024-09-30 20:06:20 +08:00
ocs2_controller = Node(
2024-09-19 14:00:43 +08:00
package="controller_manager",
executable="spawner",
2024-09-28 23:05:13 +08:00
arguments=["ocs2_quadruped_controller", "--controller-manager", "/controller_manager"]
2024-09-19 14:00:43 +08:00
)
return LaunchDescription([
Node(
package='rviz2',
executable='rviz2',
name='rviz_ocs2',
output='screen',
arguments=["-d", rviz_config_file]
),
2024-09-19 14:00:43 +08:00
robot_state_publisher,
controller_manager,
joint_state_publisher,
RegisterEventHandler(
event_handler=OnProcessExit(
target_action=joint_state_publisher,
on_exit=[imu_sensor_broadcaster],
)
2024-09-11 11:32:54 +08:00
),
2024-09-19 14:00:43 +08:00
RegisterEventHandler(
event_handler=OnProcessExit(
target_action=imu_sensor_broadcaster,
2024-09-30 20:06:20 +08:00
on_exit=[ocs2_controller],
2024-09-19 14:00:43 +08:00
)
2024-09-11 11:32:54 +08:00
),
])