From 2cfcfe80715b5606252e0de93b31030ca36c8652 Mon Sep 17 00:00:00 2001 From: IDavGal Date: Tue, 11 Jul 2023 21:15:40 -0300 Subject: [PATCH] Spawn (broken) noah into webots Signed-off-by: IDavGal --- noah_webots/launch/noah_webots.launch.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/noah_webots/launch/noah_webots.launch.py b/noah_webots/launch/noah_webots.launch.py index a0656bc..e12cd43 100644 --- a/noah_webots/launch/noah_webots.launch.py +++ b/noah_webots/launch/noah_webots.launch.py @@ -31,16 +31,29 @@ import launch import os import pathlib +import xacro from ament_index_python.packages import get_package_share_directory from launch_ros.actions import Node +from webots_ros2_driver.urdf_spawner import URDFSpawner from webots_ros2_driver.webots_launcher import WebotsLauncher -# Obtain package -package_dir = get_package_share_directory('noah_webots') +# Obtain packages +curr_pkg_dir = get_package_share_directory('noah_webots') +noah_pkg_dir = get_package_share_directory('noah_description') def generate_launch_description(): + noah_xacro_path = os.path.join(noah_pkg_dir, 'urdf', 'accurate_noah.urdf.xacro') + noah_description = xacro.process_file(noah_xacro_path).toprettyxml(indent=' ') + + spawn_URDF_noah = URDFSpawner( + name='accurate_noah', + robot_description=noah_description, + translation='0 1 0.022', + rotation=' 0 0 1 0', + ) + # The WebotsLauncher is used to start a Webots instance. # Arguments: # - `world` (str): Path to the world to launch. @@ -48,7 +61,7 @@ def generate_launch_description(): # - `mode` (str): Can be `pause`, `realtime`, or `fast`. # - `ros2_supervisor` (bool): Spawn the `Ros2Supervisor` custom node that communicates with a Supervisor robot in the simulation. webots = WebotsLauncher( - world=os.path.join(package_dir, 'worlds', 'myWorld.wbt'), + world=os.path.join(curr_pkg_dir, 'worlds', 'myWorld.wbt'), ros2_supervisor=True ) @@ -58,6 +71,8 @@ def generate_launch_description(): webots, # Starts the Ros2Supervisor node created with the WebotsLauncher webots._supervisor, + # Spawn Noah's URDF + spawn_URDF_noah, # This action will kill all nodes once the Webots simulation has exited launch.actions.RegisterEventHandler( event_handler=launch.event_handlers.OnProcessExit(