отформатированы документы согласно нотации pep

This commit is contained in:
Даниил Грабарь
2025-11-29 15:51:45 +10:00
parent b36bd0e98b
commit 37da67abe5
8 changed files with 276 additions and 292 deletions
@@ -1,46 +1,36 @@
from launch_ros.actions import Node
from launch.events import Shutdown
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
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.actions import RegisterEventHandler, EmitEvent, DeclareLaunchArgument
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
def generate_launch_description():
declare_package_arg = DeclareLaunchArgument(
'package_name',
default_value='iiwa_bringup',
description='Package name where RViz config is stored'
"package_name",
default_value="iiwa_bringup",
description="Package name where RViz config is stored",
)
package_name = LaunchConfiguration('package_name')
package_name = LaunchConfiguration("package_name")
rviz_config = PathJoinSubstitution([
FindPackageShare(package_name),
'config',
'rviz_iiwa.rviz'
])
rviz_config = PathJoinSubstitution(
[FindPackageShare(package_name), "config", "rviz_iiwa.rviz"]
)
rviz = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
arguments=['-d', rviz_config],
output='log'
package="rviz2",
executable="rviz2",
name="rviz2",
arguments=["-d", rviz_config],
output="log",
)
# При закрытии rviz закрываем все
shutdown_on_rviz_exit = RegisterEventHandler(
OnProcessExit(
target_action=rviz,
on_exit=[EmitEvent(event=Shutdown())]
)
OnProcessExit(target_action=rviz, on_exit=[EmitEvent(event=Shutdown())])
)
return LaunchDescription([
declare_package_arg,
rviz,
shutdown_on_rviz_exit
])
return LaunchDescription([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.actions import OpaqueFunction
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
def _setup_controllers(context, *args, **kwargs):
model_path = LaunchConfiguration('model').perform(context)
robot_name = LaunchConfiguration('robot_name').perform(context)
transform = LaunchConfiguration('transform').perform(context)
rotation = LaunchConfiguration('rotation').perform(context)
timer = LaunchConfiguration('controller_timer').perform(context)
model_path = LaunchConfiguration("model").perform(context)
robot_name = LaunchConfiguration("robot_name").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=model_path,
robot_name=robot_name)
tmo = ['--controller-manager-timeout', str(timer)]
robot_description = converter.load_robot_description(
model_path=model_path, robot_name=robot_name
)
tmo = ["--controller-manager-timeout", str(timer)]
jsb = Node(
package='controller_manager',
executable='spawner',
output='screen',
arguments=['joint_state_broadcaster'] + tmo,
parameters=[{'use_sim_time': False}],
package="controller_manager",
executable="spawner",
output="screen",
arguments=["joint_state_broadcaster"] + tmo,
parameters=[{"use_sim_time": False}],
)
jtc = Node(
package='controller_manager',
executable='spawner',
output='screen',
arguments=['iiwa_arm_controller'] + tmo,
parameters=[{'use_sim_time': False}],
package="controller_manager",
executable="spawner",
output="screen",
arguments=["iiwa_arm_controller"] + tmo,
parameters=[{"use_sim_time": False}],
)
spawner_urdf = URDFSpawner(
name=robot_name,
robot_description=robot_description,
translation=transform,
rotation=rotation
rotation=rotation,
)
return [jsb, jtc, spawner_urdf]
def generate_launch_description():
return LaunchDescription([
OpaqueFunction(function=_setup_controllers)
])
return LaunchDescription([OpaqueFunction(function=_setup_controllers)])
@@ -1,90 +1,84 @@
from launch.events import Shutdown
from launch import LaunchDescription
from launch.event_handlers import OnProcessExit
from launch.substitutions import LaunchConfiguration
from launch_ros.substitutions import FindPackageShare
from launch.actions import (
EmitEvent,
IncludeLaunchDescription,
OpaqueFunction,
RegisterEventHandler,
TimerAction,
)
from launch.event_handlers import OnProcessExit, OnProcessStart
from launch.substitutions import PathJoinSubstitution, LaunchConfiguration
from launch.events import Shutdown
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.actions import (IncludeLaunchDescription,
OpaqueFunction,
TimerAction,
RegisterEventHandler,
EmitEvent)
from webots_ros2_driver.webots_launcher import WebotsLauncher
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_launcher import WebotsLauncher
def _spawn_setup(context, *args, **kwargs):
model_path = LaunchConfiguration('model').perform(context)
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)
model_path = LaunchConfiguration("model").perform(context)
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)
webots = WebotsLauncher(world=world_path, ros2_supervisor=True)
webots = WebotsLauncher(world=world_path,
ros2_supervisor=True)
driver = WebotsController(
robot_name=robot_name,
parameters=[
{
"robot_description": model_path,
"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(
PythonLaunchDescriptionSource(
PathJoinSubstitution([
FindPackageShare('iiwa_bringup'),
'launch',
'supported',
'webots_controllers.launch.py'
])
PathJoinSubstitution(
[
FindPackageShare("iiwa_bringup"),
"launch",
"supported",
"webots_controllers.launch.py",
]
)
),
launch_arguments={
'robot_name': robot_name,
'model': model_path,
'transform': transform,
'rotation': rotation,
'controller_timer': timer
}.items()
"robot_name": robot_name,
"model": model_path,
"transform": transform,
"rotation": rotation,
"controller_timer": timer,
}.items(),
)
spawn_on_driver_start = RegisterEventHandler(
event_handler=OnProcessStart(
target_action=driver,
on_start=lambda evt, ctx: [
TimerAction(period=5.0,
actions=[controllers_launch]
)
]
TimerAction(period=5.0, actions=[controllers_launch])
],
)
)
shutdown_on_webots_exit = RegisterEventHandler(
OnProcessExit(
target_action=webots,
on_exit=[EmitEvent(event=Shutdown())]
)
OnProcessExit(target_action=webots, on_exit=[EmitEvent(event=Shutdown())])
)
return [webots,
webots._supervisor,
driver,
spawn_on_driver_start,
shutdown_on_webots_exit]
return [
webots,
webots._supervisor,
driver,
spawn_on_driver_start,
shutdown_on_webots_exit,
]
def generate_launch_description():
return LaunchDescription([
OpaqueFunction(function=_spawn_setup)
])
return LaunchDescription([OpaqueFunction(function=_spawn_setup)])