отформатированы документы согласно нотации pep
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
from iiwa_bringup.utils import converter
|
|
||||||
|
|
||||||
|
|
||||||
from launch_ros.actions import Node
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch_ros.substitutions import FindPackageShare
|
from launch.actions import (
|
||||||
from launch.substitutions import PathJoinSubstitution, LaunchConfiguration
|
|
||||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
|
||||||
from launch.actions import (IncludeLaunchDescription,
|
|
||||||
DeclareLaunchArgument,
|
DeclareLaunchArgument,
|
||||||
OpaqueFunction)
|
IncludeLaunchDescription,
|
||||||
|
OpaqueFunction,
|
||||||
|
)
|
||||||
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||||
|
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
from launch_ros.substitutions import FindPackageShare
|
||||||
|
|
||||||
|
from iiwa_bringup.utils import converter
|
||||||
|
|
||||||
PACKAGE = "iiwa_bringup"
|
PACKAGE = "iiwa_bringup"
|
||||||
DESCRIPTION_PKG = "iiwa_description"
|
DESCRIPTION_PKG = "iiwa_description"
|
||||||
@@ -18,132 +18,129 @@ DESCRIPTION_PKG = "iiwa_description"
|
|||||||
def _runtime_setup(context, *args, **kwatgs):
|
def _runtime_setup(context, *args, **kwatgs):
|
||||||
setup = []
|
setup = []
|
||||||
|
|
||||||
model_path = LaunchConfiguration('model').perform(context)
|
model_path = LaunchConfiguration("model").perform(context)
|
||||||
robot_name = LaunchConfiguration('robot_name').perform(context)
|
robot_name = LaunchConfiguration("robot_name").perform(context)
|
||||||
world_path = LaunchConfiguration('world').perform(context)
|
world_path = LaunchConfiguration("world").perform(context)
|
||||||
rviz_status = LaunchConfiguration('rviz').perform(context).lower() in ['true', '1', 'yes']
|
rviz_status = LaunchConfiguration("rviz").perform(context).lower() in [
|
||||||
|
"true",
|
||||||
|
"1",
|
||||||
|
"yes",
|
||||||
|
]
|
||||||
|
|
||||||
transform = LaunchConfiguration('transform').perform(context)
|
transform = LaunchConfiguration("transform").perform(context)
|
||||||
rotation = LaunchConfiguration('rotation').perform(context)
|
rotation = LaunchConfiguration("rotation").perform(context)
|
||||||
timer = LaunchConfiguration('controller_timer').perform(context)
|
timer = LaunchConfiguration("controller_timer").perform(context)
|
||||||
|
|
||||||
robot_description = converter.load_robot_description(model_path=model_path,
|
robot_description = converter.load_robot_description(
|
||||||
robot_name=robot_name)
|
model_path=model_path, robot_name=robot_name
|
||||||
|
)
|
||||||
|
|
||||||
rsp_node = Node(
|
rsp_node = Node(
|
||||||
package="robot_state_publisher",
|
package="robot_state_publisher",
|
||||||
executable="robot_state_publisher",
|
executable="robot_state_publisher",
|
||||||
name="robot_state_publisher",
|
name="robot_state_publisher",
|
||||||
output="screen",
|
output="screen",
|
||||||
parameters=[{
|
parameters=[{"robot_description": robot_description, "use_sim_time": False}],
|
||||||
"robot_description": robot_description,
|
|
||||||
"use_sim_time": False
|
|
||||||
}]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
webots_launch = IncludeLaunchDescription(
|
webots_launch = IncludeLaunchDescription(
|
||||||
PythonLaunchDescriptionSource(
|
PythonLaunchDescriptionSource(
|
||||||
PathJoinSubstitution([
|
PathJoinSubstitution(
|
||||||
|
[
|
||||||
FindPackageShare(PACKAGE),
|
FindPackageShare(PACKAGE),
|
||||||
'launch',
|
"launch",
|
||||||
'supported', 'webots_spawn.launch.py'
|
"supported",
|
||||||
])
|
"webots_spawn.launch.py",
|
||||||
|
]
|
||||||
|
)
|
||||||
),
|
),
|
||||||
launch_arguments={
|
launch_arguments={
|
||||||
'robot_name': robot_name,
|
"robot_name": robot_name,
|
||||||
'model': model_path,
|
"model": model_path,
|
||||||
'world': world_path,
|
"world": world_path,
|
||||||
'transform': transform,
|
"transform": transform,
|
||||||
'rotation': rotation,
|
"rotation": rotation,
|
||||||
'controller_timer': timer
|
"controller_timer": timer,
|
||||||
}.items()
|
}.items(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
setup += [rsp_node, webots_launch]
|
setup += [rsp_node, webots_launch]
|
||||||
|
|
||||||
|
|
||||||
if rviz_status:
|
if rviz_status:
|
||||||
rviz_launch = IncludeLaunchDescription(
|
rviz_launch = IncludeLaunchDescription(
|
||||||
PythonLaunchDescriptionSource(
|
PythonLaunchDescriptionSource(
|
||||||
PathJoinSubstitution([FindPackageShare(PACKAGE),
|
PathJoinSubstitution(
|
||||||
"launch", "supported", 'rviz.launch.py'
|
[FindPackageShare(PACKAGE), "launch", "supported", "rviz.launch.py"]
|
||||||
])),
|
)
|
||||||
launch_arguments={'package_name': PACKAGE}.items()
|
),
|
||||||
|
launch_arguments={"package_name": PACKAGE}.items(),
|
||||||
)
|
)
|
||||||
|
|
||||||
setup.append(rviz_launch)
|
setup.append(rviz_launch)
|
||||||
|
|
||||||
return setup
|
return setup
|
||||||
|
|
||||||
def generate_launch_description():
|
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
# Объявление аргументов командной строки
|
# Объявление аргументов командной строки
|
||||||
declare_model_arg = DeclareLaunchArgument(
|
declare_model_arg = DeclareLaunchArgument(
|
||||||
name="model",
|
name="model",
|
||||||
default_value=PathJoinSubstitution([
|
default_value=PathJoinSubstitution(
|
||||||
FindPackageShare(DESCRIPTION_PKG),
|
[FindPackageShare(DESCRIPTION_PKG), "urdf", "iiwa7.urdf.xacro"]
|
||||||
"urdf",
|
),
|
||||||
"iiwa7.urdf.xacro"
|
description="Path to robot xacro or urdf file (used to build robot_description).",
|
||||||
]),
|
|
||||||
description="Path to robot xacro or urdf file (used to build robot_description)."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_robot_name_arg = DeclareLaunchArgument(
|
declare_robot_name_arg = DeclareLaunchArgument(
|
||||||
name="robot_name",
|
name="robot_name",
|
||||||
default_value="iiwa7",
|
default_value="iiwa7",
|
||||||
description="Robot name (used for TF and naming spawned robot)."
|
description="Robot name (used for TF and naming spawned robot).",
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_world_arg = DeclareLaunchArgument(
|
declare_world_arg = DeclareLaunchArgument(
|
||||||
name="world",
|
name="world",
|
||||||
default_value=PathJoinSubstitution([
|
default_value=PathJoinSubstitution(
|
||||||
FindPackageShare(DESCRIPTION_PKG),
|
[FindPackageShare(DESCRIPTION_PKG), "worlds", "iiwa.wbt"]
|
||||||
"worlds",
|
),
|
||||||
"iiwa.wbt"
|
description="Path to the Webots world (.wbt) to launch.",
|
||||||
]),
|
|
||||||
description="Path to the Webots world (.wbt) to launch."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_controller_arg = DeclareLaunchArgument(
|
declare_controller_arg = DeclareLaunchArgument(
|
||||||
name="controller",
|
name="controller",
|
||||||
default_value=PathJoinSubstitution([
|
default_value=PathJoinSubstitution(
|
||||||
FindPackageShare(PACKAGE),
|
[FindPackageShare(PACKAGE), "config", "iiwa_controller.yaml"]
|
||||||
"config",
|
),
|
||||||
"iiwa_controller.yaml"
|
description="Path to controllers YAML file (used by spawner and controller_manager).",
|
||||||
]),
|
|
||||||
description="Path to controllers YAML file (used by spawner and controller_manager)."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_transform_arg = DeclareLaunchArgument(
|
declare_transform_arg = DeclareLaunchArgument(
|
||||||
name="transform",
|
name="transform",
|
||||||
default_value="-0.25 0 0.79",
|
default_value="-0.25 0 0.79",
|
||||||
description="Translation applied when spawning the robot in the Webots world (x y z)."
|
description="Translation applied when spawning the robot in the Webots world (x y z).",
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_rotation_arg = DeclareLaunchArgument(
|
declare_rotation_arg = DeclareLaunchArgument(
|
||||||
name="rotation",
|
name="rotation",
|
||||||
default_value="0 0 1 0",
|
default_value="0 0 1 0",
|
||||||
description="Rotation (axis-angle) applied when spawning the robot in the Webots world."
|
description="Rotation (axis-angle) applied when spawning the robot in the Webots world.",
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_rviz_arg = DeclareLaunchArgument(
|
declare_rviz_arg = DeclareLaunchArgument(
|
||||||
name="rviz",
|
name="rviz",
|
||||||
default_value="0",
|
default_value="0",
|
||||||
description="If true|1|yes then launch RViz and joint_state_publisher_gui instead of controllers."
|
description="If true|1|yes then launch RViz and joint_state_publisher_gui instead of controllers.",
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_controller_manager_arg = DeclareLaunchArgument(
|
declare_controller_manager_arg = DeclareLaunchArgument(
|
||||||
name="controller_timer",
|
name="controller_timer",
|
||||||
default_value="50",
|
default_value="50",
|
||||||
description="Timeout (seconds) for controller_manager spawners (--controller-manager-timeout)."
|
description="Timeout (seconds) for controller_manager spawners (--controller-manager-timeout).",
|
||||||
)
|
)
|
||||||
|
|
||||||
runtime_setup = OpaqueFunction(
|
runtime_setup = OpaqueFunction(function=_runtime_setup)
|
||||||
function=_runtime_setup
|
|
||||||
)
|
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription(
|
||||||
|
[
|
||||||
declare_model_arg,
|
declare_model_arg,
|
||||||
declare_robot_name_arg,
|
declare_robot_name_arg,
|
||||||
declare_world_arg,
|
declare_world_arg,
|
||||||
@@ -152,5 +149,6 @@ def generate_launch_description():
|
|||||||
declare_rotation_arg,
|
declare_rotation_arg,
|
||||||
declare_rviz_arg,
|
declare_rviz_arg,
|
||||||
declare_controller_manager_arg,
|
declare_controller_manager_arg,
|
||||||
runtime_setup
|
runtime_setup,
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from launch_ros.actions import Node
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
|
from launch.actions import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
|
||||||
from launch_ros.substitutions import FindPackageShare
|
|
||||||
from launch.substitutions import Command, LaunchConfiguration, PathJoinSubstitution
|
|
||||||
from launch.events import Shutdown
|
|
||||||
from launch.event_handlers import OnProcessExit
|
from launch.event_handlers import OnProcessExit
|
||||||
|
from launch.events import Shutdown
|
||||||
|
from launch.substitutions import Command, LaunchConfiguration, PathJoinSubstitution
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
from launch_ros.substitutions import FindPackageShare
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
@@ -13,69 +13,70 @@ def generate_launch_description():
|
|||||||
|
|
||||||
declare_model_arg = DeclareLaunchArgument(
|
declare_model_arg = DeclareLaunchArgument(
|
||||||
name="model",
|
name="model",
|
||||||
default_value=PathJoinSubstitution([
|
default_value=PathJoinSubstitution(
|
||||||
FindPackageShare(description_package_name),
|
[FindPackageShare(description_package_name), "urdf", "iiwa7.urdf.xacro"]
|
||||||
"urdf",
|
),
|
||||||
"iiwa7.urdf.xacro"
|
description="Path to the robot URDF/Xacro file",
|
||||||
]),
|
|
||||||
description="Path to the robot URDF/Xacro file"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
declare_robot_name_arg = DeclareLaunchArgument(
|
declare_robot_name_arg = DeclareLaunchArgument(
|
||||||
name="robot_name",
|
name="robot_name",
|
||||||
default_value="iiwa7",
|
default_value="iiwa7",
|
||||||
description="Robot name fro the TF tree"
|
description="Robot name fro the TF tree",
|
||||||
)
|
)
|
||||||
|
|
||||||
robot_description = Command([
|
robot_description = Command(
|
||||||
"xacro ", LaunchConfiguration('model'),
|
[
|
||||||
" robot_name:=", LaunchConfiguration("robot_name")
|
"xacro ",
|
||||||
])
|
LaunchConfiguration("model"),
|
||||||
|
" robot_name:=",
|
||||||
|
LaunchConfiguration("robot_name"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
robot_state_publisher = Node(
|
robot_state_publisher = Node(
|
||||||
package="robot_state_publisher",
|
package="robot_state_publisher",
|
||||||
executable="robot_state_publisher",
|
executable="robot_state_publisher",
|
||||||
name="robot_state_publisher",
|
name="robot_state_publisher",
|
||||||
output="both",
|
output="both",
|
||||||
parameters=[{
|
parameters=[
|
||||||
|
{
|
||||||
"robot_description": robot_description,
|
"robot_description": robot_description,
|
||||||
"use_sim_time": False,
|
"use_sim_time": False,
|
||||||
}]
|
}
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
joint_state_publisher_gui = Node(
|
joint_state_publisher_gui = Node(
|
||||||
package='joint_state_publisher_gui',
|
package="joint_state_publisher_gui",
|
||||||
executable='joint_state_publisher_gui',
|
executable="joint_state_publisher_gui",
|
||||||
name='joint_state_publisher_gui',
|
name="joint_state_publisher_gui",
|
||||||
parameters=[{"use_sim_time": False}]
|
parameters=[{"use_sim_time": False}],
|
||||||
)
|
)
|
||||||
|
|
||||||
rviz_config = PathJoinSubstitution([
|
rviz_config = PathJoinSubstitution(
|
||||||
FindPackageShare(package_name),
|
[FindPackageShare(package_name), "config", "rviz_iiwa.rviz"]
|
||||||
'config',
|
)
|
||||||
'rviz_iiwa.rviz'
|
|
||||||
])
|
|
||||||
|
|
||||||
rviz = Node(
|
rviz = Node(
|
||||||
package='rviz2',
|
package="rviz2",
|
||||||
executable='rviz2',
|
executable="rviz2",
|
||||||
name='rviz2',
|
name="rviz2",
|
||||||
arguments=['-d', rviz_config],
|
arguments=["-d", rviz_config],
|
||||||
output='log'
|
output="log",
|
||||||
)
|
)
|
||||||
|
|
||||||
shutdown_on_rviz_exit = RegisterEventHandler(
|
shutdown_on_rviz_exit = RegisterEventHandler(
|
||||||
OnProcessExit(
|
OnProcessExit(target_action=rviz, on_exit=[EmitEvent(event=Shutdown())])
|
||||||
target_action=rviz,
|
|
||||||
on_exit=[EmitEvent(event=Shutdown())]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription(
|
||||||
|
[
|
||||||
declare_model_arg,
|
declare_model_arg,
|
||||||
declare_robot_name_arg,
|
declare_robot_name_arg,
|
||||||
robot_state_publisher,
|
robot_state_publisher,
|
||||||
joint_state_publisher_gui,
|
joint_state_publisher_gui,
|
||||||
rviz,
|
rviz,
|
||||||
shutdown_on_rviz_exit
|
shutdown_on_rviz_exit,
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,46 +1,36 @@
|
|||||||
from launch_ros.actions import Node
|
|
||||||
from launch.events import Shutdown
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
|
from launch.actions import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
|
||||||
from launch.event_handlers import OnProcessExit
|
from launch.event_handlers import OnProcessExit
|
||||||
from launch_ros.substitutions import FindPackageShare
|
from launch.events import Shutdown
|
||||||
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
|
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
|
||||||
from launch.actions import RegisterEventHandler, EmitEvent, DeclareLaunchArgument
|
from launch_ros.actions import Node
|
||||||
|
from launch_ros.substitutions import FindPackageShare
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
|
|
||||||
declare_package_arg = DeclareLaunchArgument(
|
declare_package_arg = DeclareLaunchArgument(
|
||||||
'package_name',
|
"package_name",
|
||||||
default_value='iiwa_bringup',
|
default_value="iiwa_bringup",
|
||||||
description='Package name where RViz config is stored'
|
description="Package name where RViz config is stored",
|
||||||
)
|
)
|
||||||
|
|
||||||
package_name = LaunchConfiguration('package_name')
|
package_name = LaunchConfiguration("package_name")
|
||||||
|
|
||||||
rviz_config = PathJoinSubstitution([
|
rviz_config = PathJoinSubstitution(
|
||||||
FindPackageShare(package_name),
|
[FindPackageShare(package_name), "config", "rviz_iiwa.rviz"]
|
||||||
'config',
|
)
|
||||||
'rviz_iiwa.rviz'
|
|
||||||
])
|
|
||||||
|
|
||||||
rviz = Node(
|
rviz = Node(
|
||||||
package='rviz2',
|
package="rviz2",
|
||||||
executable='rviz2',
|
executable="rviz2",
|
||||||
name='rviz2',
|
name="rviz2",
|
||||||
arguments=['-d', rviz_config],
|
arguments=["-d", rviz_config],
|
||||||
output='log'
|
output="log",
|
||||||
)
|
)
|
||||||
|
|
||||||
# При закрытии rviz закрываем все
|
# При закрытии rviz закрываем все
|
||||||
shutdown_on_rviz_exit = RegisterEventHandler(
|
shutdown_on_rviz_exit = RegisterEventHandler(
|
||||||
OnProcessExit(
|
OnProcessExit(target_action=rviz, on_exit=[EmitEvent(event=Shutdown())])
|
||||||
target_action=rviz,
|
|
||||||
on_exit=[EmitEvent(event=Shutdown())]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([declare_package_arg, rviz, shutdown_on_rviz_exit])
|
||||||
declare_package_arg,
|
|
||||||
rviz,
|
|
||||||
shutdown_on_rviz_exit
|
|
||||||
])
|
|
||||||
|
|||||||
@@ -1,51 +1,50 @@
|
|||||||
from launch_ros.actions import Node
|
|
||||||
from webots_ros2_driver.urdf_spawner import URDFSpawner
|
|
||||||
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import OpaqueFunction
|
from launch.actions import OpaqueFunction
|
||||||
from launch.substitutions import LaunchConfiguration
|
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_bringup.utils import converter
|
||||||
|
|
||||||
|
|
||||||
def _setup_controllers(context, *args, **kwargs):
|
def _setup_controllers(context, *args, **kwargs):
|
||||||
model_path = LaunchConfiguration('model').perform(context)
|
model_path = LaunchConfiguration("model").perform(context)
|
||||||
robot_name = LaunchConfiguration('robot_name').perform(context)
|
robot_name = LaunchConfiguration("robot_name").perform(context)
|
||||||
transform = LaunchConfiguration('transform').perform(context)
|
transform = LaunchConfiguration("transform").perform(context)
|
||||||
rotation = LaunchConfiguration('rotation').perform(context)
|
rotation = LaunchConfiguration("rotation").perform(context)
|
||||||
timer = LaunchConfiguration('controller_timer').perform(context)
|
timer = LaunchConfiguration("controller_timer").perform(context)
|
||||||
|
|
||||||
robot_description = converter.load_robot_description(model_path=model_path,
|
robot_description = converter.load_robot_description(
|
||||||
robot_name=robot_name)
|
model_path=model_path, robot_name=robot_name
|
||||||
|
)
|
||||||
|
|
||||||
tmo = ['--controller-manager-timeout', str(timer)]
|
tmo = ["--controller-manager-timeout", str(timer)]
|
||||||
|
|
||||||
jsb = Node(
|
jsb = Node(
|
||||||
package='controller_manager',
|
package="controller_manager",
|
||||||
executable='spawner',
|
executable="spawner",
|
||||||
output='screen',
|
output="screen",
|
||||||
arguments=['joint_state_broadcaster'] + tmo,
|
arguments=["joint_state_broadcaster"] + tmo,
|
||||||
parameters=[{'use_sim_time': False}],
|
parameters=[{"use_sim_time": False}],
|
||||||
)
|
)
|
||||||
|
|
||||||
jtc = Node(
|
jtc = Node(
|
||||||
package='controller_manager',
|
package="controller_manager",
|
||||||
executable='spawner',
|
executable="spawner",
|
||||||
output='screen',
|
output="screen",
|
||||||
arguments=['iiwa_arm_controller'] + tmo,
|
arguments=["iiwa_arm_controller"] + tmo,
|
||||||
parameters=[{'use_sim_time': False}],
|
parameters=[{"use_sim_time": False}],
|
||||||
)
|
)
|
||||||
|
|
||||||
spawner_urdf = URDFSpawner(
|
spawner_urdf = URDFSpawner(
|
||||||
name=robot_name,
|
name=robot_name,
|
||||||
robot_description=robot_description,
|
robot_description=robot_description,
|
||||||
translation=transform,
|
translation=transform,
|
||||||
rotation=rotation
|
rotation=rotation,
|
||||||
)
|
)
|
||||||
|
|
||||||
return [jsb, jtc, spawner_urdf]
|
return [jsb, jtc, spawner_urdf]
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
return LaunchDescription([
|
return LaunchDescription([OpaqueFunction(function=_setup_controllers)])
|
||||||
OpaqueFunction(function=_setup_controllers)
|
|
||||||
])
|
|
||||||
|
|||||||
@@ -1,32 +1,29 @@
|
|||||||
from launch.events import Shutdown
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.event_handlers import OnProcessExit
|
from launch.actions import (
|
||||||
from launch.substitutions import LaunchConfiguration
|
EmitEvent,
|
||||||
from launch_ros.substitutions import FindPackageShare
|
IncludeLaunchDescription,
|
||||||
from launch.event_handlers import OnProcessExit, OnProcessStart
|
|
||||||
from launch.substitutions import PathJoinSubstitution, LaunchConfiguration
|
|
||||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
|
||||||
from launch.actions import (IncludeLaunchDescription,
|
|
||||||
OpaqueFunction,
|
OpaqueFunction,
|
||||||
TimerAction,
|
|
||||||
RegisterEventHandler,
|
RegisterEventHandler,
|
||||||
EmitEvent)
|
TimerAction,
|
||||||
|
)
|
||||||
|
from launch.event_handlers import OnProcessExit, OnProcessStart
|
||||||
from webots_ros2_driver.webots_launcher import WebotsLauncher
|
from launch.events import Shutdown
|
||||||
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||||
|
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
|
||||||
|
from launch_ros.substitutions import FindPackageShare
|
||||||
from webots_ros2_driver.webots_controller import WebotsController
|
from webots_ros2_driver.webots_controller import WebotsController
|
||||||
|
from webots_ros2_driver.webots_launcher import WebotsLauncher
|
||||||
|
|
||||||
|
|
||||||
def _spawn_setup(context, *args, **kwargs):
|
def _spawn_setup(context, *args, **kwargs):
|
||||||
model_path = LaunchConfiguration('model').perform(context)
|
model_path = LaunchConfiguration("model").perform(context)
|
||||||
robot_name = LaunchConfiguration('robot_name').perform(context)
|
robot_name = LaunchConfiguration("robot_name").perform(context)
|
||||||
world_path = LaunchConfiguration('world').perform(context)
|
world_path = LaunchConfiguration("world").perform(context)
|
||||||
transform = LaunchConfiguration('transform').perform(context)
|
transform = LaunchConfiguration("transform").perform(context)
|
||||||
rotation = LaunchConfiguration('rotation').perform(context)
|
rotation = LaunchConfiguration("rotation").perform(context)
|
||||||
timer = LaunchConfiguration('controller_timer').perform(context)
|
timer = LaunchConfiguration("controller_timer").perform(context)
|
||||||
|
|
||||||
webots = WebotsLauncher(world=world_path,
|
webots = WebotsLauncher(world=world_path, ros2_supervisor=True)
|
||||||
ros2_supervisor=True)
|
|
||||||
|
|
||||||
driver = WebotsController(
|
driver = WebotsController(
|
||||||
robot_name=robot_name,
|
robot_name=robot_name,
|
||||||
@@ -34,57 +31,54 @@ def _spawn_setup(context, *args, **kwargs):
|
|||||||
{
|
{
|
||||||
"robot_description": model_path,
|
"robot_description": model_path,
|
||||||
"use_sim_time": True,
|
"use_sim_time": True,
|
||||||
"set_robot_state_publisher": False
|
"set_robot_state_publisher": False,
|
||||||
},
|
},
|
||||||
LaunchConfiguration('controller').perform(context)
|
LaunchConfiguration("controller").perform(context),
|
||||||
],
|
],
|
||||||
respawn=True
|
respawn=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
controllers_launch = IncludeLaunchDescription(
|
controllers_launch = IncludeLaunchDescription(
|
||||||
PythonLaunchDescriptionSource(
|
PythonLaunchDescriptionSource(
|
||||||
PathJoinSubstitution([
|
PathJoinSubstitution(
|
||||||
FindPackageShare('iiwa_bringup'),
|
[
|
||||||
'launch',
|
FindPackageShare("iiwa_bringup"),
|
||||||
'supported',
|
"launch",
|
||||||
'webots_controllers.launch.py'
|
"supported",
|
||||||
])
|
"webots_controllers.launch.py",
|
||||||
|
]
|
||||||
|
)
|
||||||
),
|
),
|
||||||
launch_arguments={
|
launch_arguments={
|
||||||
'robot_name': robot_name,
|
"robot_name": robot_name,
|
||||||
'model': model_path,
|
"model": model_path,
|
||||||
'transform': transform,
|
"transform": transform,
|
||||||
'rotation': rotation,
|
"rotation": rotation,
|
||||||
'controller_timer': timer
|
"controller_timer": timer,
|
||||||
}.items()
|
}.items(),
|
||||||
)
|
)
|
||||||
|
|
||||||
spawn_on_driver_start = RegisterEventHandler(
|
spawn_on_driver_start = RegisterEventHandler(
|
||||||
event_handler=OnProcessStart(
|
event_handler=OnProcessStart(
|
||||||
target_action=driver,
|
target_action=driver,
|
||||||
on_start=lambda evt, ctx: [
|
on_start=lambda evt, ctx: [
|
||||||
TimerAction(period=5.0,
|
TimerAction(period=5.0, actions=[controllers_launch])
|
||||||
actions=[controllers_launch]
|
],
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
shutdown_on_webots_exit = RegisterEventHandler(
|
shutdown_on_webots_exit = RegisterEventHandler(
|
||||||
OnProcessExit(
|
OnProcessExit(target_action=webots, on_exit=[EmitEvent(event=Shutdown())])
|
||||||
target_action=webots,
|
|
||||||
on_exit=[EmitEvent(event=Shutdown())]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return [webots,
|
return [
|
||||||
|
webots,
|
||||||
webots._supervisor,
|
webots._supervisor,
|
||||||
driver,
|
driver,
|
||||||
spawn_on_driver_start,
|
spawn_on_driver_start,
|
||||||
shutdown_on_webots_exit]
|
shutdown_on_webots_exit,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
return LaunchDescription([
|
return LaunchDescription([OpaqueFunction(function=_spawn_setup)])
|
||||||
OpaqueFunction(function=_spawn_setup)
|
|
||||||
])
|
|
||||||
|
|||||||
+22
-19
@@ -1,55 +1,58 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
package_name = 'iiwa_bringup'
|
package_name = "iiwa_bringup"
|
||||||
|
|
||||||
# Собираем список пакетов: основной + вложенные (если они есть).
|
# Собираем список пакетов: основной + вложенные (если они есть).
|
||||||
packages = [package_name]
|
packages = [package_name]
|
||||||
# Если есть подпапка utils с __init__.py — зарегистрируем её как iiwa_bringup.utils
|
# Если есть подпапка utils с __init__.py — зарегистрируем её как iiwa_bringup.utils
|
||||||
if os.path.isdir('utils') and os.path.isfile(os.path.join('utils', '__init__.py')):
|
if os.path.isdir("utils") and os.path.isfile(os.path.join("utils", "__init__.py")):
|
||||||
packages.append(f'{package_name}.utils')
|
packages.append(f"{package_name}.utils")
|
||||||
|
|
||||||
# Соответствие имени пакета -> директория на диске.
|
# Соответствие имени пакета -> директория на диске.
|
||||||
# iiwa_bringup -> текущая папка '.'
|
# iiwa_bringup -> текущая папка '.'
|
||||||
# iiwa_bringup.utils -> ./utils
|
# iiwa_bringup.utils -> ./utils
|
||||||
package_dir = {
|
package_dir = {
|
||||||
package_name: '.',
|
package_name: ".",
|
||||||
}
|
}
|
||||||
if f'{package_name}.utils' in packages:
|
if f"{package_name}.utils" in packages:
|
||||||
package_dir[f'{package_name}.utils'] = os.path.join('.', 'utils')
|
package_dir[f"{package_name}.utils"] = os.path.join(".", "utils")
|
||||||
|
|
||||||
|
|
||||||
def data_files_from_tree(src_dir: str, dst_root: str) -> list:
|
def data_files_from_tree(src_dir: str, dst_root: str) -> list:
|
||||||
entries = []
|
entries = []
|
||||||
if not os.path.isdir(src_dir):
|
if not os.path.isdir(src_dir):
|
||||||
return entries
|
return entries
|
||||||
EXCLUDE_DIRS = {'.git', '__pycache__', '.pytest_cache', '.idea'}
|
EXCLUDE_DIRS = {".git", "__pycache__", ".pytest_cache", ".idea"}
|
||||||
EXCLUDES = {'.DS_Store', 'Thumbs.db'}
|
EXCLUDES = {".DS_Store", "Thumbs.db"}
|
||||||
for root, dirs, files in os.walk(src_dir):
|
for root, dirs, files in os.walk(src_dir):
|
||||||
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS]
|
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS]
|
||||||
file_list = [os.path.join(root, f) for f in files if f not in EXCLUDES]
|
file_list = [os.path.join(root, f) for f in files if f not in EXCLUDES]
|
||||||
if not file_list:
|
if not file_list:
|
||||||
continue
|
continue
|
||||||
rel = os.path.relpath(root, src_dir)
|
rel = os.path.relpath(root, src_dir)
|
||||||
dst_dir = os.path.join(dst_root, rel) if rel != '.' else dst_root
|
dst_dir = os.path.join(dst_root, rel) if rel != "." else dst_root
|
||||||
entries.append((dst_dir, file_list))
|
entries.append((dst_dir, file_list))
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
data_files = [(f'share/{package_name}', ['package.xml'])]
|
|
||||||
data_files += data_files_from_tree('launch', f'share/{package_name}/launch')
|
data_files = [(f"share/{package_name}", ["package.xml"])]
|
||||||
data_files += data_files_from_tree('config', f'share/{package_name}/config')
|
data_files += data_files_from_tree("launch", f"share/{package_name}/launch")
|
||||||
data_files += data_files_from_tree('resource', f'share/{package_name}/resource')
|
data_files += data_files_from_tree("config", f"share/{package_name}/config")
|
||||||
|
data_files += data_files_from_tree("resource", f"share/{package_name}/resource")
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name=package_name,
|
name=package_name,
|
||||||
version='0.0.1',
|
version="0.0.1",
|
||||||
packages=packages,
|
packages=packages,
|
||||||
package_dir=package_dir,
|
package_dir=package_dir,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
data_files=data_files,
|
data_files=data_files,
|
||||||
install_requires=['setuptools'],
|
install_requires=["setuptools"],
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
maintainer='Grabar Daniil',
|
maintainer="Grabar Daniil",
|
||||||
maintainer_email='grabardm@ml-dev.ru',
|
maintainer_email="grabardm@ml-dev.ru",
|
||||||
description='iiwa bringup package',
|
description="iiwa bringup package",
|
||||||
license='Apache-2.0',
|
license="Apache-2.0",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
EXCLUDES = {'.DS_Store', 'Thumbs.db'}
|
EXCLUDES = {".DS_Store", "Thumbs.db"}
|
||||||
EXCLUDE_DIRS = {'__pycache__', '.pytest_cache', '.git', '.idea'}
|
EXCLUDE_DIRS = {"__pycache__", ".pytest_cache", ".git", ".idea"}
|
||||||
|
|
||||||
|
|
||||||
def data_files_from_tree(src_dir: str, dst_root: str) -> list:
|
def data_files_from_tree(src_dir: str, dst_root: str) -> list:
|
||||||
"""
|
"""
|
||||||
@@ -20,12 +22,13 @@ def data_files_from_tree(src_dir: str, dst_root: str) -> list:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
rel = os.path.relpath(root, src_dir)
|
rel = os.path.relpath(root, src_dir)
|
||||||
dst_dir = os.path.join(dst_root, rel) if rel != '.' else dst_root
|
dst_dir = os.path.join(dst_root, rel) if rel != "." else dst_root
|
||||||
entries.append((dst_dir, file_list))
|
entries.append((dst_dir, file_list))
|
||||||
|
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
package_name = 'iiwa_description'
|
|
||||||
|
package_name = "iiwa_description"
|
||||||
|
|
||||||
resource_intsall_root = f"share/{package_name}/resource"
|
resource_intsall_root = f"share/{package_name}/resource"
|
||||||
meshes_intsall_root = f"share/{package_name}/meshes"
|
meshes_intsall_root = f"share/{package_name}/meshes"
|
||||||
@@ -34,36 +37,34 @@ worlds_intsall_root = f"share/{package_name}/worlds"
|
|||||||
protos_intsall_root = f"share/{package_name}/protos"
|
protos_intsall_root = f"share/{package_name}/protos"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data_files = [
|
data_files = [
|
||||||
('share/' + package_name, ['package.xml']),
|
("share/" + package_name, ["package.xml"]),
|
||||||
]
|
]
|
||||||
|
|
||||||
data_files += data_files_from_tree('resource', resource_intsall_root)
|
data_files += data_files_from_tree("resource", resource_intsall_root)
|
||||||
data_files += data_files_from_tree('meshes', meshes_intsall_root)
|
data_files += data_files_from_tree("meshes", meshes_intsall_root)
|
||||||
data_files += data_files_from_tree('urdf', urdf_intsall_root)
|
data_files += data_files_from_tree("urdf", urdf_intsall_root)
|
||||||
data_files += data_files_from_tree('worlds', worlds_intsall_root)
|
data_files += data_files_from_tree("worlds", worlds_intsall_root)
|
||||||
data_files += data_files_from_tree('protos', protos_intsall_root)
|
data_files += data_files_from_tree("protos", protos_intsall_root)
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name=package_name,
|
name=package_name,
|
||||||
version='0.0.1',
|
version="0.0.1",
|
||||||
packages=find_packages(exclude=['test']),
|
packages=find_packages(exclude=["test"]),
|
||||||
data_files=data_files,
|
data_files=data_files,
|
||||||
install_requires=['setuptools'],
|
install_requires=["setuptools"],
|
||||||
zip_safe=True,
|
zip_safe=True,
|
||||||
maintainer='Grabar Daniil',
|
maintainer="Grabar Daniil",
|
||||||
maintainer_email='grabardm@ml-dev.ru',
|
maintainer_email="grabardm@ml-dev.ru",
|
||||||
description='TODO: Package description',
|
description="TODO: Package description",
|
||||||
license='Apache-2.0',
|
license="Apache-2.0",
|
||||||
extras_require={
|
extras_require={
|
||||||
'test': [
|
"test": [
|
||||||
'pytest',
|
"pytest",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
"console_scripts": [],
|
||||||
],
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,25 +2,25 @@
|
|||||||
# /Ros2Supervisor/spawn_urdf_robot
|
# /Ros2Supervisor/spawn_urdf_robot
|
||||||
|
|
||||||
|
|
||||||
import rclpy
|
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
|
import rclpy
|
||||||
|
from rclpy.executors import ExternalShutdownException
|
||||||
from rclpy.node import Node
|
from rclpy.node import Node
|
||||||
from rclpy.task import Future
|
from rclpy.task import Future
|
||||||
from rclpy.executors import ExternalShutdownException
|
|
||||||
from webots_ros2_msgs.srv import SpawnNodeFromString
|
from webots_ros2_msgs.srv import SpawnNodeFromString
|
||||||
|
|
||||||
|
|
||||||
class ObjectSpawner(Node):
|
class ObjectSpawner(Node):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("object_spawner")
|
super().__init__("object_spawner")
|
||||||
# self._object_count: int = randint(1, 5)
|
self._object_count: int = randint(1, 5)
|
||||||
self._object_count: int = 1
|
|
||||||
self._spawned_count: int = 0
|
self._spawned_count: int = 0
|
||||||
self._call_in_progress: bool = False
|
self._call_in_progress: bool = False
|
||||||
|
|
||||||
|
self.cli = self.create_client(
|
||||||
self.cli = self.create_client(SpawnNodeFromString,
|
SpawnNodeFromString, "/Ros2Supervisor/spawn_node_from_string"
|
||||||
"/Ros2Supervisor/spawn_node_from_string")
|
)
|
||||||
|
|
||||||
while not self.cli.wait_for_service(timeout_sec=10):
|
while not self.cli.wait_for_service(timeout_sec=10):
|
||||||
self.get_logger().warning(
|
self.get_logger().warning(
|
||||||
@@ -31,19 +31,16 @@ class ObjectSpawner(Node):
|
|||||||
|
|
||||||
def timer_callback(self):
|
def timer_callback(self):
|
||||||
if self._spawned_count >= self._object_count:
|
if self._spawned_count >= self._object_count:
|
||||||
self.get_logger().info(
|
self.get_logger().info(f"All {self._object_count} objects spawned")
|
||||||
f"All {self._object_count} objects spawned"
|
|
||||||
)
|
|
||||||
self._timer.cancel()
|
self._timer.cancel()
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._call_in_progress:
|
if self._call_in_progress:
|
||||||
return
|
return
|
||||||
|
|
||||||
data = "Solid { name \"test_box2\" translation 0 1 0.5 children [ Shape { appearance PBRAppearance { baseColor 0.901961 0.380392 0 } geometry Box { size 0.1 0.1 0.1 } } ] boundingObject Box { size 0.1 0.1 0.1 } physics Physics { } }"
|
data = 'Solid { name "test_box2" translation 0 1 0.5 children [ Shape { appearance PBRAppearance { baseColor 0.901961 0.380392 0 } geometry Box { size 0.1 0.1 0.1 } } ] boundingObject Box { size 0.1 0.1 0.1 } physics Physics { } }'
|
||||||
|
|
||||||
req = SpawnNodeFromString.Request(data=data,
|
req = SpawnNodeFromString.Request(data=data, check_fields=True)
|
||||||
check_fields=True)
|
|
||||||
self.get_logger().info(
|
self.get_logger().info(
|
||||||
f"Calling spawn service #{self._spawned_count + 1}/{self._object_count}"
|
f"Calling spawn service #{self._spawned_count + 1}/{self._object_count}"
|
||||||
)
|
)
|
||||||
@@ -70,5 +67,6 @@ def main(args=None):
|
|||||||
except (KeyboardInterrupt, ExternalShutdownException):
|
except (KeyboardInterrupt, ExternalShutdownException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user