def main():
    """ Main for spwaning turtlebot node """
    # Get input arguments from user
    argv = sys.argv[1:]

    # Start node
    rclpy.init()
    node = rclpy.create_node(
        "entity_spawner",
        cli_args=[
            #  '--ros-args -r /tf:=/' + utils.get_robot_name('T') + '/tf'])
            '--ros-args -r __ns=/T206 /tf:=tf'
        ])

    node.get_logger().info(
        'Creating Service client to connect to `/spawn_entity`')
    client = node.create_client(SpawnEntity, "/spawn_entity")

    node.get_logger().info("Connecting to `/spawn_entity` service...")
    if not client.service_is_ready():
        client.wait_for_service()
        node.get_logger().info("...connected!")

    # Get path to the turtlebot3 burgerbot
    sdf_file_path = os.path.join(
        get_package_share_directory("turtlebot3_gazebo"), "models",
        "turtlebot3_burger", "model.sdf")

    # Set data for request
    request = SpawnEntity.Request()
    request.name = utils.get_robot_name('T')
    request.xml = open(sdf_file_path, 'r').read()
    request.robot_namespace = utils.get_robot_name('T')
    request.initial_pose.position.x = float(argv[0])
    request.initial_pose.position.y = float(argv[1])
    request.initial_pose.position.z = float(argv[2])

    node.get_logger().info("Sending service request to `/spawn_entity`")
    future = client.call_async(request)
    rclpy.spin_until_future_complete(node, future)
    if future.result() is not None:
        print('response: %r' % future.result())
    else:
        raise RuntimeError('exception while calling service: %r' %
                           future.exception())

    node.get_logger().info("Done! Shutting down node.")
    node.destroy_node()
    rclpy.shutdown()
Ejemplo n.º 2
0
def generate_launch_description():
    port = LaunchConfiguration('port', default='/dev/ttyUSB0')
    frame_id = LaunchConfiguration('frame_id', default='laser')
    robot_name = LaunchConfiguration('robot_name', default=utils.get_robot_name('robot'))

    return LaunchDescription([

        DeclareLaunchArgument(
            'port',
            default_value=port,
            description='Specifying usb port to connected lidar'),

        DeclareLaunchArgument(
            'frame_id',
            default_value=frame_id,
            description='Specifying frame_id of lidar. Default frame_id is \'laser\''),

        Node(
            package='hls_lfcd_lds_driver',
            executable='hlds_laser_publisher',
            name='hlds_laser_publisher',
            parameters=[{'port': port, 'frame_id': frame_id}],
            output='both',
            namespace=robot_name,
            remappings=[("/tf", "tf"), ("/tf_static", "tf_static")]
        ),
    ])
Ejemplo n.º 3
0
def generate_launch_description():

    use_sim_time = LaunchConfiguration('use_sim_time', default='false')
    urdf_file_name = 'turtlebot3_burger.urdf'
    robot_name = LaunchConfiguration('robot_name',
                                     default=utils.get_robot_name('robot'))

    print("urdf_file_name : {}".format(urdf_file_name))

    urdf = os.path.join(get_package_share_directory('turtlebot3_description'),
                        'urdf', urdf_file_name)

    return LaunchDescription([
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        Node(package='robot_state_publisher',
             executable='robot_state_publisher',
             name='robot_state_publisher',
             output='screen',
             parameters=[{
                 'use_sim_time': use_sim_time
             }],
             arguments=[urdf],
             namespace=robot_name,
             remappings=[("/tf", "tf"), ("/tf_static", "tf_static")]),
    ])
def generate_launch_description():

    ip = launch_ros.actions.Node(
        package='system_status',
        executable='system_status',
        output='both',  # "screen", "log" or "both"
        name='system_status',
    )

    robot = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            [ThisLaunchFileDir(), '/robot.launch.py']), )

    watchdog = launch_ros.actions.Node(
        package='robot_spawner_pkg',
        executable='watchdog',
        namespace=utils.get_robot_name('robot'),
    )

    # Create the launch description and populate
    ld = LaunchDescription()
    ld.add_action(ip)
    ld.add_action(robot)
    ld.add_action(watchdog)
    return ld
Ejemplo n.º 5
0
def edit_param_file_namespace(param_file_dir):
    with open(param_file_dir, 'r') as f:
        data = yaml.safe_load(f)
        name = utils.get_robot_name('robot') + "':"
        # for every robotXXX you find in the data, replace with the name
        replaced = re.sub(r'robot[^\s]*', name, str(data))
        # str->dict
        replaced = ast.literal_eval(replaced)

    with open(param_file_dir, 'w') as f:
        yaml.dump(replaced, f)
Ejemplo n.º 6
0
def generate_launch_description():
    default_param_dir = os.path.join(
        get_package_share_directory('system_status'),
        'param',
        'burger.yaml'
    )

    tb3_param_dir = LaunchConfiguration(
        'tb3_param_dir',
        default=default_param_dir
    )
    # ATTENTION: this is editing the parameter file's content!
    edit_param_file_namespace(default_param_dir)

    usb_port = LaunchConfiguration('usb_port', default='/dev/ttyACM0')
    use_sim_time = LaunchConfiguration('use_sim_time', default='false')
    robot_name = LaunchConfiguration('robot_name', default=utils.get_robot_name('robot'))

    return LaunchDescription([
        DeclareLaunchArgument(
            'robot_name',
            default_value=robot_name,
            description='for the namespace of this robot'
        ),

        DeclareLaunchArgument(
            'use_sim_time',
            default_value=use_sim_time,
            description='Use simulation (Gazebo) clock if true'),

        DeclareLaunchArgument(
            'usb_port',
            default_value=usb_port,
            description='Connected USB port with OpenCR'),

        DeclareLaunchArgument(
            'tb3_param_dir',
            default_value=tb3_param_dir,
            description='Full path to turtlebot3 parameter file to load'),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                [ThisLaunchFileDir(), '/turtlebot3_state_publisher.launch.py']
            ),
            launch_arguments={'use_sim_time': use_sim_time}.items(),
        ),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                [ThisLaunchFileDir(), '/hlds_laser.launch.py']
            ),
            launch_arguments={'port': '/dev/ttyUSB0',
                              'frame_id': 'base_scan', 'namespace': 'robot_name'}.items(),
        ),

        Node(
            package='turtlebot3_node',
            executable='turtlebot3_ros',
            parameters=[tb3_param_dir],
            arguments=['-i', usb_port],
            output='both',
            namespace=robot_name,
            remappings=[("/tf", "tf"), ("/tf_static", "tf_static")]
        ),
    ])