Skip to content

Commit

Permalink
Spawn (broken) noah into webots
Browse files Browse the repository at this point in the history
Signed-off-by: IDavGal <[email protected]>
  • Loading branch information
IDavGal committed Jul 12, 2023
1 parent 7ae1dea commit 2cfcfe8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions noah_webots/launch/noah_webots.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,37 @@
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.
# - `gui` (bool): Whether to display GUI or not.
# - `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
)

Expand All @@ -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(
Expand Down

0 comments on commit 2cfcfe8

Please sign in to comment.