diff --git a/.entrypoint.sh b/.entrypoint.sh index 78353f8c..b6eec181 100755 --- a/.entrypoint.sh +++ b/.entrypoint.sh @@ -1,5 +1,8 @@ #!/bin/bash set -e source "/opt/lge-ros2/install/setup.bash" + +echo "Check ROS_DOMAIN_ID here!!" echo ROS_DOMAIN_ID=$ROS_DOMAIN_ID -exec ros2 run cloisim_ros_bringup cloisim_ros_bringup "$@" \ No newline at end of file + +exec ros2 launch cloisim_ros_bringup bringup.launch.py "$@" \ No newline at end of file diff --git a/README.md b/README.md index 570cdf24..bb0d1319 100644 --- a/README.md +++ b/README.md @@ -36,15 +36,7 @@ check here [details](https://github.com/lge-ros2/cloisim_ros/tree/foxy/cloisim_r strongly recommend to use this method. -#### Turn on single Mode - -will NOT apply namespace for robot and the number of robot must BE single in world environment. - -```shell -ros2 run cloisim_ros_bringup cloisim_ros_bringup --ros-args -p singlemode:=True -``` - -#### Turn off single mode +#### Turn off single mode(=multi robot mode) apply namespace for each robot) @@ -54,39 +46,39 @@ ros2 run cloisim_ros_bringup cloisim_ros_bringup --ros-args -p singlemode:=False ros2 run cloisim_ros_bringup cloisim_ros_bringup ``` -### launch cloisim_ros for robot - -will be deprecated. +or ```shell -ros2 launch cloisim_ros_bringup robot.launch.py robot_name:=cloi +ros2 launch cloisim_ros_bringup bringup.launch.py + +ros2 launch cloisim_ros_bringup bringup.launch.py singlemode:=False ``` -### launch factory (elevator system and world) +#### Turn on single Mode -will be deprecated. +will NOT apply namespace for robot and the number of robot must BE single in world environment. ```shell -ros2 launch cloisim_ros_bringup factory.launch.py +ros2 run cloisim_ros_bringup cloisim_ros_bringup --ros-args -p singlemode:=True ``` -### How to run cloisim_ros with CLOiSim together - -#### only simulator +or ```shell -ros2 launch cloisim_ros_bringup cloisim.launch.py sim_path:=/opt/CLOiSim/CLOiSim-1.10.0 world:=lg_seocho.world +ros2 launch cloisim_ros_bringup bringup.launch.py singlemode:=True ``` -#### simulator + cloisim_ros package(clock topic) +## Running CLOiSim + +it provides a script to run CLOiSim easily. ```shell -ros2 launch cloisim_ros_bringup cloisim_and_factory.launch.py sim_path:=/opt/CLOiSim/CLOiSim-1.10.0 world:=lg_seocho.world +ros2 launch cloisim_ros_bringup cloisim.launch.py sim_path:=/opt/CLOiSim/CLOiSim-1.10.0 world:=lg_seocho.world ``` ## Using Docker -Run below command after clone this repository(this branch). Only support 'ros2 run' +Run below command after clone this repository(this branch). Only support 'ros2 run' ### Build Docker image @@ -99,15 +91,15 @@ docker build -t cloisim_ros . ### Running container ```shell -docker run -it --rm --net=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID cloisim_ros +docker run -it --rm --net=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID cloisim_ros -docker run -it --rm --net=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID cloisim_ros --ros-args -p singlemode:=False +docker run -it --rm --net=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID cloisim_ros singlemode:=False ``` or ```shell -docker run -it --rm --net=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID cloisim_ros --ros-args -p singlemode:=True +docker run -it --rm --net=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID cloisim_ros singlemode:=True ``` ## Version info diff --git a/cloisim_ros_bringup/CMakeLists.txt b/cloisim_ros_bringup/CMakeLists.txt index 12fe8bca..3205800e 100644 --- a/cloisim_ros_bringup/CMakeLists.txt +++ b/cloisim_ros_bringup/CMakeLists.txt @@ -93,6 +93,4 @@ install( RUNTIME DESTINATION lib/${PROJECT_NAME} ) -ament_python_install_package(${PROJECT_NAME} PACKAGE_DIR launch/module) - ament_package() \ No newline at end of file diff --git a/cloisim_ros_bringup/launch/cloisim_ros.launch.py b/cloisim_ros_bringup/launch/bringup.launch.py similarity index 51% rename from cloisim_ros_bringup/launch/cloisim_ros.launch.py rename to cloisim_ros_bringup/launch/bringup.launch.py index 5ffbdb93..9c45f029 100644 --- a/cloisim_ros_bringup/launch/cloisim_ros.launch.py +++ b/cloisim_ros_bringup/launch/bringup.launch.py @@ -16,33 +16,32 @@ def generate_launch_description(): - _package_name = LaunchConfiguration('package_name') - _robot_name = LaunchConfiguration('robot_name') - _name = LaunchConfiguration('name') - _parameters = LaunchConfiguration('parameters') + _singlemode = LaunchConfiguration('singlemode') cloisim_ros_cmd = Node( - package=_package_name, - executable=_package_name, - name=_name, - namespace=_robot_name, + package="cloisim_ros_bringup", + executable="cloisim_ros_bringup", output='screen', - parameters=[_parameters]) + parameters=[{'singlemode': _singlemode}]) - declare_launch_argument_rn = DeclareLaunchArgument( - 'robot_name', - default_value='', - description='it is equal to namespace') + declare_launch_argument = DeclareLaunchArgument( + 'singlemode', + default_value='False', + description='whether to use single mode') - stdout_linebuf_envvar = SetEnvironmentVariable( + stdout_log_use_stdout_envvar = SetEnvironmentVariable( + 'RCUTILS_LOGGING_USE_STDOUT', '1') + + stdout_log_buf_stream_envvar = SetEnvironmentVariable( 'RCUTILS_LOGGING_BUFFERED_STREAM', '1') # Create the launch description and populate ld = launch.LaunchDescription() # Set environment variables - ld.add_action(stdout_linebuf_envvar) - ld.add_action(declare_launch_argument_rn) + ld.add_action(stdout_log_use_stdout_envvar) + ld.add_action(stdout_log_buf_stream_envvar) + ld.add_action(declare_launch_argument) ld.add_action(cloisim_ros_cmd) return ld diff --git a/cloisim_ros_bringup/launch/cloisim.launch.py b/cloisim_ros_bringup/launch/cloisim.launch.py index 7f3a98a7..d75226c9 100644 --- a/cloisim_ros_bringup/launch/cloisim.launch.py +++ b/cloisim_ros_bringup/launch/cloisim.launch.py @@ -17,7 +17,7 @@ def generate_launch_description() -> LaunchDescription: world = LaunchConfiguration('world') execute_multi_robot_simulator = ExecuteProcess( - cmd=['./CLOiSim.x86_64', '-worldFile', world], + cmd=['./CLOiSim.x86_64', '-world', world], cwd=[sim_path], output='screen') diff --git a/cloisim_ros_bringup/launch/cloisim_and_factory.launch.py b/cloisim_ros_bringup/launch/cloisim_and_factory.launch.py deleted file mode 100644 index 188b1c7f..00000000 --- a/cloisim_ros_bringup/launch/cloisim_and_factory.launch.py +++ /dev/null @@ -1,65 +0,0 @@ -# -# LGE Advanced Robotics Laboratory -# Copyright (c) 2020 LG Electronics Inc., LTD., Seoul, Korea -# All Rights are Reserved. -# -# SPDX-License-Identifier: MIT -# - -import os -import launch.actions -import launch_ros.actions - -from ament_index_python.packages import get_package_share_directory -from launch import LaunchDescription -from launch.actions import IncludeLaunchDescription -from launch.actions import DeclareLaunchArgument -from launch.actions import SetEnvironmentVariable -from launch.substitutions import LaunchConfiguration -from launch.launch_description_sources import PythonLaunchDescriptionSource - - -def generate_launch_description(): - - # Get the launch directory - _pkg_name = "cloisim_ros_bringup" - launch_dir = os.path.join(get_package_share_directory(_pkg_name), 'launch') - - included_launch_world = IncludeLaunchDescription( - PythonLaunchDescriptionSource([launch_dir, '/factory.launch.py'])) - - sim_path = LaunchConfiguration('sim_path') - world = LaunchConfiguration('world') - - included_launch_cloisim = IncludeLaunchDescription( - PythonLaunchDescriptionSource([launch_dir, '/cloisim.launch.py']), - launch_arguments={'sim_path': sim_path, 'world': world}.items()) - - declare_launch_argument_sim_path = DeclareLaunchArgument( - 'sim_path', - default_value='', - description='path where the CLOiSim simulator located') - - declare_launch_argument_world = DeclareLaunchArgument( - 'world', - default_value='', - description='It is World file name. Please check environments before run. [CLOISIM_WORLD_PATH, CLOISIM_MODEL_PATH]') - - # Create environment variables - stdout_linebuf_envvar = SetEnvironmentVariable( - 'RCUTILS_LOGGING_BUFFERED_STREAM', '1') - - # Create the launch description and populate - ld = LaunchDescription() - - # Set environment variables - ld.add_action(stdout_linebuf_envvar) - - # Add the actions to launch all nodes - ld.add_action(declare_launch_argument_sim_path) - ld.add_action(declare_launch_argument_world) - - ld.add_action(included_launch_cloisim) - ld.add_action(included_launch_world) - - return ld \ No newline at end of file diff --git a/cloisim_ros_bringup/launch/factory.launch.py b/cloisim_ros_bringup/launch/factory.launch.py deleted file mode 100644 index df5fff35..00000000 --- a/cloisim_ros_bringup/launch/factory.launch.py +++ /dev/null @@ -1,73 +0,0 @@ -# -# LGE Advanced Robotics Laboratory -# Copyright (c) 2020 LG Electronics Inc., LTD., Seoul, Korea -# All Rights are Reserved. -# -# SPDX-License-Identifier: MIT -# - -import os -import launch.actions -from ament_index_python.packages import get_package_share_directory -from cloisim_ros_bringup.common import get_package_name_by_device_type -from cloisim_ros_bringup.common import get_target_device_list -from cloisim_ros_bringup.common import generate_temp_params -from launch.actions import IncludeLaunchDescription -from launch.launch_description_sources import PythonLaunchDescriptionSource - - -def generate_launch_description(): - - # Create the launch description and populate - ld = launch.LaunchDescription() - - # Get the launch directory - _pkg_name = "cloisim_ros_bringup" - launch_dir = os.path.join(get_package_share_directory(_pkg_name), 'launch') - - # Elevator - model_name = "SeochoTower" - elevator_list = get_target_device_list(model_name); - - for (device_type, nodes) in elevator_list.items(): - print(device_type) - - for (name, port_maps) in nodes.items(): - print("\t", name) - - package_name = get_package_name_by_device_type(device_type) - print("\t > ", package_name) - - _config_params = generate_temp_params(name, model_name, port_maps) - - included_launch = IncludeLaunchDescription( - PythonLaunchDescriptionSource( - [launch_dir, '/cloisim_ros.launch.py']), - launch_arguments={'package_name':package_name, 'name': name, 'parameters': _config_params}.items()) - - ld.add_action(included_launch) - - - # World - model_name = "World" - world_list = get_target_device_list(model_name); - - for (device_type, nodes) in world_list.items(): - print(device_type) - - for (name, port_maps) in nodes.items(): - print("\t", name) - - package_name = get_package_name_by_device_type(device_type) - print("\t > ", package_name) - - _config_params = generate_temp_params(name, model_name, port_maps) - - included_launch = IncludeLaunchDescription( - PythonLaunchDescriptionSource( - [launch_dir, '/cloisim_ros.launch.py']), - launch_arguments={'package_name':package_name, 'name': name, 'parameters': _config_params}.items()) - - ld.add_action(included_launch) - - return ld \ No newline at end of file diff --git a/cloisim_ros_bringup/launch/module/__init__.py b/cloisim_ros_bringup/launch/module/__init__.py deleted file mode 100644 index 6a8c7819..00000000 --- a/cloisim_ros_bringup/launch/module/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -# -# LGE Advanced Robotics Laboratory -# Copyright (c) 2020 LG Electronics Inc., LTD., Seoul, Korea -# All Rights are Reserved. -# -# SPDX-License-Identifier: MIT -# \ No newline at end of file diff --git a/cloisim_ros_bringup/launch/module/common.py b/cloisim_ros_bringup/launch/module/common.py deleted file mode 100644 index d0a2f24e..00000000 --- a/cloisim_ros_bringup/launch/module/common.py +++ /dev/null @@ -1,171 +0,0 @@ -# -# LGE Advanced Robotics Laboratory -# Copyright (c) 2020 LG Electronics Inc., LTD., Seoul, Korea -# All Rights are Reserved. -# -# SPDX-License-Identifier: MIT -# - -import os -import sys -import yaml -import json -import time -from tempfile import NamedTemporaryFile -from websocket import create_connection - -CLOISIM_BRIDGE_IP="127.0.0.1" -CLOISIM_SERVICE_PORT=8080 - -def get_package_name_by_device_type(device_type): - - package_name = {'MICOM': 'cloisim_ros_micom', - 'LIDAR': 'cloisim_ros_lidar', - 'LASER': 'cloisim_ros_lidar', - 'CAMERA': 'cloisim_ros_camera', - 'DEPTHCAMERA': 'cloisim_ros_depthcamera', - 'MULTICAMERA': 'cloisim_ros_multicamera', - 'REALSENSE': 'cloisim_ros_realsense', - 'GPS': 'cloisim_ros_gps', - 'ELEVATOR': 'cloisim_ros_elevatorsystem', - 'WORLD': 'cloisim_ros_world'}.get(device_type, None) - - return None if (package_name is None) else package_name - - -def _get_robot_name_in_arg(): - - _robot_name = '' - - # find ros param setting template - for idx in range(4, len(sys.argv)): - tmp_arg = sys.argv[idx] - tmp_sp = tmp_arg.split(':=') - - # if argument is ros param template - if len(tmp_sp) == 2: - tmp_key = tmp_sp[0] - tmp_value = tmp_sp[1] - - # check param name is robot_name - if str(tmp_key) == 'robot_name' or str(tmp_key) == '_robot_name': - # set namespace with robot_name - _robot_name = tmp_value - - return _robot_name - - -def get_robot_name_in_env(): - - _robot_name = '' - - # check environment param - if 'ROBOT_NAME' in os.environ.keys(): - # if environment param name has ROBOT_NAME - env_robot_name = os.environ['ROBOT_NAME'] - - if env_robot_name != None: - # set namespace with ROBOT_NAME - _robot_name = env_robot_name - - return _robot_name - - -def find_robot_name(): - - _robot_name = _get_robot_name_in_arg() - - # if robot_name still not exist - if len(_robot_name.strip()) == 0: - _robot_name = get_robot_name_in_env() - - return _robot_name - -def _create_params_file_from_dict(params): - with NamedTemporaryFile(mode='w', prefix='cloisim_ros_launch_params_', delete=False) as h: - param_file_path = h.name - yaml.dump(params, h, default_flow_style=False) - return param_file_path - - -def generate_temp_params(_name, model_name, port_maps): - - # capsule config with namespace - config_dict = dict() - config_dict[_name] = dict() - config_dict[_name]['ros__parameters'] = dict() - config_dict[_name]['ros__parameters']['model'] = model_name - config_dict[_name]['ros__parameters']['bridge'] = port_maps - - # print(config_dict) - - # create temp file for config load - result_config_param = _create_params_file_from_dict(config_dict) - # print(type(result_config_param)) - # print(result_config_param) - - return result_config_param - -def generate_temp_params_with_ns(_namespace, _name, port_maps): - - # capsule config with namespace - config_dict = dict() - config_dict[_namespace] = dict() - config_dict[_namespace][_name] = dict() - config_dict[_namespace][_name]['ros__parameters'] = dict() - config_dict[_namespace][_name]['ros__parameters']['bridge'] = port_maps - - # print(config_dict) - - # create temp file for config load - result_config_param = _create_params_file_from_dict(config_dict) - # print(type(result_config_param)) - # print(result_config_param) - - return result_config_param - - -def connect_to_simulator(_target_model_name): - - delay = 3.0 - - while True: - - try: - ws = create_connection("ws://" + CLOISIM_BRIDGE_IP + ":" + str(CLOISIM_SERVICE_PORT) + "/control") - message = "{'command':'device_list', 'filter':'" + _target_model_name + "'}" - ws.send(message) - # print("send '%s'" % message) - result = ws.recv() - # print("Received '%s'" % result) - ws.close() - - return result; - - except ConnectionRefusedError as err: - print("=> Failed to connect to CLOiSim: {}\n".format(err)) - print("Try to reconnect to CLOiSim after {} sec: {}".format(delay, err)) - time.sleep(delay) - - -def get_target_device_list(_target_model_name): - - delay = 2.0 - - while True: - - result = connect_to_simulator(_target_model_name) - - device_list = json.loads(result) - - try: - target_device_list = device_list["result"][_target_model_name] - # print(target_device_list) - return target_device_list - - except Exception as inst: - # print(type(inst)) - # print(inst) - print("Target robot name is invalid: " + _target_model_name + ", it may be not loaded yet.") - print("Retry to get device list after {} sec".format(delay)) - time.sleep(delay) diff --git a/cloisim_ros_bringup/launch/robot.launch.py b/cloisim_ros_bringup/launch/robot.launch.py deleted file mode 100755 index f32c1769..00000000 --- a/cloisim_ros_bringup/launch/robot.launch.py +++ /dev/null @@ -1,57 +0,0 @@ -# -# LGE Advanced Robotics Laboratory -# Copyright (c) 2020 LG Electronics Inc., LTD., Seoul, Korea -# All Rights are Reserved. -# -# SPDX-License-Identifier: MIT -# - -import os -import launch.actions -import launch_ros.actions -from ament_index_python.packages import get_package_share_directory -from cloisim_ros_bringup.common import generate_temp_params_with_ns -from cloisim_ros_bringup.common import find_robot_name -from cloisim_ros_bringup.common import get_package_name_by_device_type -from cloisim_ros_bringup.common import get_target_device_list -from launch.actions import IncludeLaunchDescription -from launch.substitutions import LaunchConfiguration -from launch.launch_description_sources import PythonLaunchDescriptionSource - - -def generate_launch_description(): - - # Create the launch description and populate - ld = launch.LaunchDescription() - - robot_name = find_robot_name() - - target_device_list = get_target_device_list(robot_name) - - # Get the launch directory - launch_dir = os.path.join(get_package_share_directory("cloisim_ros_bringup"), 'launch') - - robot_namespace = LaunchConfiguration('robot_name') - - for (device_type, nodes) in target_device_list.items(): - print(device_type) - - for (parts_name, port_maps) in nodes.items(): - print("\t", parts_name) - - package_name = get_package_name_by_device_type(device_type) - print("\t > ", package_name) - - _config_params = generate_temp_params_with_ns(robot_name, parts_name, port_maps) - - included_launch = IncludeLaunchDescription( - PythonLaunchDescriptionSource( - [launch_dir, '/cloisim_ros.launch.py']), - launch_arguments={'package_name':package_name, 'robot_name': robot_namespace, - 'name': parts_name, 'parameters': _config_params}.items()) - - ld.add_action(included_launch) - - print("\t") - - return ld diff --git a/cloisim_ros_bringup/package.xml b/cloisim_ros_bringup/package.xml index 5290e9b5..1a61c142 100644 --- a/cloisim_ros_bringup/package.xml +++ b/cloisim_ros_bringup/package.xml @@ -27,7 +27,6 @@ cloisim_ros_elevatorsystem cloisim_ros_world - python3-websocket libwebsocketpp-dev libjsoncpp-dev asio