Переработана вся структура запуска файлов. Теперь в iiwa_bringup хранятся только launch файлы.

Все конфигурационные файлы переехали в пакет `iiwa_config`. также там появился общий конфигурационный файл, который упращает запуск `digital_twin.launch.py`

Добавлен дополнительный пакет  `iiwa_utils`, в который переехал весь код с папки `iiwa_bringup/utils`, а также все тестовые ноды переехали с `iiwa_object_spawner` в этот пакет

Пакеты `iiwa_bringup` и `iiwa_description` переведены на `ament_cmake` для дальнейшего удобсва - пакеты не будут содержать код для реализации
This commit is contained in:
Даниил Грабарь
2025-12-25 21:46:40 +10:00
parent 1a65f48c03
commit fa39991bcf
41 changed files with 680 additions and 377 deletions
+55 -169
View File
@@ -15,45 +15,22 @@ from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from moveit_configs_utils import MoveItConfigsBuilder
from iiwa_bringup.utils import converter
PACKAGE = "iiwa_bringup"
DESCRIPTION_PKG = "iiwa_description"
def _arg(name: str, default, desc: str):
"""Short helper to declare a launch argument."""
return DeclareLaunchArgument(name=name, default_value=default, description=desc)
def _share_file(pkg_arg_name: str, *relpath: str):
"""Join <share>/<relpath...> where <share> is FindPackageShare(LaunchConfiguration(pkg_arg_name))."""
return PathJoinSubstitution([FindPackageShare(LaunchConfiguration(pkg_arg_name)), *relpath])
from iiwa_utils import converter, setting_loader
def _runtime_setup(context, *args, **kwatgs):
setup = []
robot_name = LaunchConfiguration("robot_name").perform(context)
world_path = LaunchConfiguration("world").perform(context)
transform = LaunchConfiguration("transform").perform(context)
rotation = LaunchConfiguration("rotation").perform(context)
timer = LaunchConfiguration("controller_timer").perform(context)
xacro_file = LaunchConfiguration("xacro_file").perform(context)
srdf_file = LaunchConfiguration("srdf_file").perform(context)
# ros2_controllers_file = LaunchConfiguration("controller").perform(context)
initial_positions_file = LaunchConfiguration("initial_positions_file").perform(context)
kinematics_yaml = LaunchConfiguration("kinematics_yaml").perform(context)
joint_limits_yaml = LaunchConfiguration("joint_limits_yaml").perform(context)
pilz_limits_yaml = LaunchConfiguration("pilz_limits_yaml").perform(context)
moveit_controllers_yaml = LaunchConfiguration("moveit_controllers_yaml").perform(context)
settings = setting_loader.build_settings(
settings_path=LaunchConfiguration("setting").perform(context), check_files=True
)
robot_description = converter.load_robot_description(
model_path=xacro_file, robot_name=robot_name
model_path=settings.digital_twin.description,
robot_name=settings.robot.name,
xacro_args={
"initial_positions_file": settings.controller.moveit.initial_positions
},
)
rsp_node = Node(
@@ -61,15 +38,14 @@ def _runtime_setup(context, *args, **kwatgs):
executable="robot_state_publisher",
name="robot_state_publisher",
output="screen",
parameters=[{"robot_description": robot_description,
"use_sim_time": False}],
parameters=[{"robot_description": robot_description, "use_sim_time": False}],
)
webots_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
FindPackageShare(PACKAGE),
FindPackageShare("iiwa_bringup"),
"launch",
"supported",
"webots_spawn.launch.py",
@@ -77,26 +53,31 @@ def _runtime_setup(context, *args, **kwatgs):
)
),
launch_arguments={
"robot_name": robot_name,
"xacro_file": xacro_file,
"world": world_path,
"transform": transform,
"rotation": rotation,
"controller_timer": timer,
"robot_name": str(settings.robot.name),
"description": str(settings.digital_twin.description),
"world": str(settings.digital_twin.webots.world),
"transform": str(settings.digital_twin.webots.transform),
"rotation": str(settings.digital_twin.webots.rotation),
"controller_timer": str(settings.digital_twin.webots.controller_timer),
"controller": str(settings.controller.controller_path),
"initial_positions_file": str(settings.controller.moveit.initial_positions),
}.items(),
)
moveit_configs = (
MoveItConfigsBuilder("iiwa7", package_name=LaunchConfiguration("config_pkg").perform(context))
.robot_description(file_path=xacro_file, mappings={
"initial_positions_file": initial_positions_file,
})
.robot_description_semantic(file_path=srdf_file)
.robot_description_kinematics(file_path=kinematics_yaml)
.joint_limits(file_path=joint_limits_yaml)
.pilz_cartesian_limits(file_path=pilz_limits_yaml)
.trajectory_execution(file_path=moveit_controllers_yaml)
.moveit_cpp(file_path="/home/daniel/dev/ros2_iiwa7/src/iiwa_bringup/config/motion_planing.yaml") # TODO: сделать подстановочным значением
MoveItConfigsBuilder("iiwa7", package_name="iiwa_config")
.robot_description(
file_path=settings.digital_twin.description,
mappings={
"initial_positions_file": settings.controller.moveit.initial_positions
},
)
.robot_description_semantic(file_path=settings.controller.moveit.srdf)
.robot_description_kinematics(file_path=settings.controller.moveit.kinematics)
.joint_limits(file_path=settings.controller.moveit.joint_limits)
.pilz_cartesian_limits(file_path=settings.controller.moveit.pilz_limits)
.trajectory_execution(file_path=settings.controller.moveit.moveit_controllers)
.moveit_cpp(file_path=settings.controller.moveit.moveit_cpp)
.to_moveit_configs()
)
@@ -106,29 +87,25 @@ def _runtime_setup(context, *args, **kwatgs):
output="screen",
parameters=[
moveit_configs.to_dict(),
robot_description,
{"robot_description": robot_description},
],
)
# TODO: не забудь поменять правильное название и имя пакета
moveit_py_node = Node(
name="moveit_py",
package="iiwa_object_spawner",
package="iiwa_utils",
executable="motion_planning_test",
output="both",
parameters=[moveit_configs.to_dict()],
)
rviz_config = PathJoinSubstitution(
[FindPackageShare(PACKAGE), "config", "rviz_iiwa.rviz"]
)
rviz_launch = Node(
condition=IfCondition(LaunchConfiguration("rviz")),
package="rviz2",
executable="rviz2",
name="rviz2",
arguments=["-d", rviz_config],
arguments=["-d", settings.digital_twin.rviz.config],
output="log",
parameters=[
moveit_configs.robot_description,
@@ -140,133 +117,42 @@ def _runtime_setup(context, *args, **kwatgs):
)
shutdown_on_rviz_exit = RegisterEventHandler(
OnProcessExit(target_action=rviz_launch,
on_exit=[EmitEvent(event=Shutdown())])
OnProcessExit(target_action=rviz_launch, on_exit=[EmitEvent(event=Shutdown())])
)
setup += [rsp_node,
webots_launch,
move_group,
moveit_py_node,
rviz_launch,
shutdown_on_rviz_exit
]
setup += [
rsp_node,
webots_launch,
move_group,
moveit_py_node,
rviz_launch,
shutdown_on_rviz_exit,
]
return setup
def generate_launch_description():
# Объявление аргументов командной строки
declare_description_pkg = _arg(
"description_pkg",
DESCRIPTION_PKG,
"Package containing URDF/Xacro (and optionally SRDF/worlds).",
)
declare_config_pkg = _arg(
"config_pkg",
PACKAGE,
"Package containing MoveIt/ros2_control config YAML files (config/*).",
declare_rviz = DeclareLaunchArgument(
name="rviz",
default_value="0",
description="If true|1|yes then launch RViz/MoveIt branch (instead of controllers branch)",
)
declare_robot_name = _arg(
"robot_name",
"iiwa7",
"Robot name (used for TF and naming).",
declacre_setting = DeclareLaunchArgument(
name="setting",
default_value=PathJoinSubstitution(
[FindPackageShare("iiwa_config"), "config", "setting.yaml"]
),
description="Absolute path to settings file",
)
declare_world = _arg(
"world",
_share_file("description_pkg", "worlds", "iiwa.wbt"),
"Path to Webots world (.wbt).",
)
declare_controller = _arg(
"controller",
_share_file("config_pkg", "config", "iiwa_controller.yaml"),
"Controllers YAML (spawner/controller_manager).",
)
declare_transform = _arg(
"transform",
"-0.25 0 0.79",
"Spawn translation in Webots (x y z).",
)
declare_rotation = _arg(
"rotation",
"0 0 1 0",
"Spawn rotation axis-angle in Webots.",
)
declare_rviz = _arg(
"rviz",
"0",
"If true|1|yes then launch RViz/MoveIt branch (instead of controllers branch).",
)
declare_controller_timer = _arg(
"controller_timer",
"50",
"Timeout (seconds) for controller_manager spawners.",
)
# URDF/SRDF
declare_xacro_file = _arg(
"xacro_file",
_share_file("description_pkg", "urdf", "iiwa7.urdf.xacro"),
"Xacro used by MoveIt robot_description.",
)
declare_srdf_file = _arg(
"srdf_file",
_share_file("config_pkg", "config", "iiwa7.srdf"),
"SRDF path.",
)
# YAML конфиги
declare_initial_positions = _arg(
"initial_positions_file",
_share_file("config_pkg", "config", "initial_positions.yaml"),
"initial_positions.yaml passed into xacro arg initial_positions_file.",
)
declare_kinematics_yaml = _arg(
"kinematics_yaml",
_share_file("config_pkg", "config", "kinematics.yaml"),
"MoveIt kinematics.yaml",
)
declare_joint_limits_yaml = _arg(
"joint_limits_yaml",
_share_file("config_pkg", "config", "joint_limits.yaml"),
"MoveIt joint_limits.yaml",
)
declare_pilz_limits_yaml = _arg(
"pilz_limits_yaml",
_share_file("config_pkg", "config", "pilz_cartesian_limits.yaml"),
"Pilz cartesian limits yaml.",
)
declare_moveit_controllers_yaml = _arg(
"moveit_controllers_yaml",
_share_file("config_pkg", "config", "moveit_controllers.yaml"),
"MoveIt controllers (trajectory_execution / simple_controller_manager).",
)
runtime_setup = OpaqueFunction(function=_runtime_setup)
return LaunchDescription(
[
declare_description_pkg,
declare_config_pkg,
declare_robot_name,
declare_world,
declare_controller,
declare_transform,
declare_rotation,
declare_rviz,
declare_controller_timer,
declare_xacro_file,
declare_srdf_file,
declare_initial_positions,
declare_kinematics_yaml,
declare_joint_limits_yaml,
declare_pilz_limits_yaml,
declare_moveit_controllers_yaml,
declacre_setting,
runtime_setup,
]
)
@@ -4,23 +4,26 @@ from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from webots_ros2_driver.urdf_spawner import URDFSpawner
from iiwa_bringup.utils import converter
from iiwa_utils import converter
def _setup_controllers(context, *args, **kwargs):
xacro_file = LaunchConfiguration("xacro_file").perform(context)
robot_name = LaunchConfiguration("robot_name").perform(context)
description = LaunchConfiguration("description").perform(context)
transform = LaunchConfiguration("transform").perform(context)
rotation = LaunchConfiguration("rotation").perform(context)
timer = LaunchConfiguration("controller_timer").perform(context)
robot_description = converter.load_robot_description(
model_path=xacro_file, robot_name=robot_name
controller_timer = LaunchConfiguration("controller_timer").perform(context)
initial_positions_file = LaunchConfiguration("initial_positions_file").perform(
context
)
tmo = ["--controller-manager-timeout", str(timer)]
robot_description = converter.load_robot_description(
model_path=description,
robot_name=robot_name,
xacro_args={"initial_positions_file": initial_positions_file},
)
tmo = ["--controller-manager-timeout", str(controller_timer)]
jsb = Node(
package="controller_manager",
@@ -16,24 +16,28 @@ from webots_ros2_driver.webots_launcher import WebotsLauncher
def _spawn_setup(context, *args, **kwargs):
xacro_file = LaunchConfiguration("xacro_file").perform(context)
robot_name = LaunchConfiguration("robot_name").perform(context)
world_path = LaunchConfiguration("world").perform(context)
description = LaunchConfiguration("description").perform(context)
world = LaunchConfiguration("world").perform(context)
transform = LaunchConfiguration("transform").perform(context)
rotation = LaunchConfiguration("rotation").perform(context)
timer = LaunchConfiguration("controller_timer").perform(context)
controller_timer = LaunchConfiguration("controller_timer").perform(context)
controller = LaunchConfiguration("controller").perform(context)
initial_positions_file = LaunchConfiguration("initial_positions_file").perform(
context
)
webots = WebotsLauncher(world=world_path, ros2_supervisor=True)
webots = WebotsLauncher(world=world, ros2_supervisor=True)
driver = WebotsController(
robot_name=robot_name,
parameters=[
{
"robot_description": xacro_file,
"robot_description": description,
"use_sim_time": False,
"set_robot_state_publisher": False,
},
LaunchConfiguration("controller").perform(context),
controller,
],
respawn=True,
)
@@ -51,10 +55,11 @@ def _spawn_setup(context, *args, **kwargs):
),
launch_arguments={
"robot_name": robot_name,
"xacro_file": xacro_file,
"description": description,
"transform": transform,
"rotation": rotation,
"controller_timer": timer,
"controller_timer": controller_timer,
"initial_positions_file": initial_positions_file,
}.items(),
)