Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck creating moveit::planning_interface::MoveGroupInterface object when launching in a custom namespace #2415

Closed
catmulti7 opened this issue Oct 9, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@catmulti7
Copy link

Description

Hi everyone,
First I have to say I'm not sure whether this is caused by my mistake or it is a bug. And help will be appreciate.
I'm trying to launch move_group node(from package "moveit_ros_move_group") and move_group_interface node(the node I wrote which uses moveit::planning_interface::MoveGroupInterface to manipulate the robot), I put them in a single launch file(move_group.launch.py) and launch it. It works as expected. But than I create another launch file, include move_group.launch.py and use PushRosNamespace to add a namespace for both nodes, the move_group_interface node stuck at creating moveit::planning_interface::MoveGroupInterface object. There isn't any error information. Programs just hangs there.

Your environment

  • ROS Distro: Humble
  • OS Version: Ubuntu 22.04
  • Source or Binary build? Binary
  • If binary, which release version? 2.5.4-1jammy.20230624.062116
  • Which RMW (Fast DDS or Cyclone DDS)? Cyclone.

Steps to reproduce

I modify this code and launch file based on hello_moveit package.
move_group.launch

import os
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import ExecuteProcess
from ament_index_python.packages import get_package_share_directory
from moveit_configs_utils import MoveItConfigsBuilder


def generate_launch_description():
    moveit_config = (
        MoveItConfigsBuilder("moveit_resources_panda")
        .robot_description(file_path="config/panda.urdf.xacro")
        .trajectory_execution(file_path="config/gripper_moveit_controllers.yaml")
        .to_moveit_configs()
    )
    # Start the actual move_group node/action server
    run_move_group_node = Node(
        package="moveit_ros_move_group",
        executable="move_group",
        output="screen",
        parameters=[moveit_config.to_dict()],
    )

    move_group_demo = Node(
        name="hello_moveit",
        package="hello_moveit",
        executable="hello_moveit",
        output="screen",
        parameters=[
            moveit_config.robot_description,
            moveit_config.robot_description_semantic,
            moveit_config.robot_description_kinematics,
        ],
    )

    return LaunchDescription(
        [
            run_move_group_node,
            move_group_demo
        ]
    )

move_group_with_ns.launch

import os
from ament_index_python.packages import get_package_share_directory
from launch.actions import IncludeLaunchDescription
from launch import LaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource


from launch.actions import GroupAction
from launch_ros.actions import PushRosNamespace


def generate_launch_description():


    moveit_launch_dir = get_package_share_directory('hello_moveit')

    arm_0_moveit = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(os.path.join(moveit_launch_dir, 'launch', 'move_group.launch.py')))
    
    arm_0_moveit_with_namespace = GroupAction(
     actions=[
         PushRosNamespace('arm_0'),
         arm_0_moveit
      ]
    )

    
    return LaunchDescription([
        arm_0_moveit_with_namespace,
    ])

hello_moveit.cpp

#include <moveit/move_group_interface/move_group_interface.h>
#include <moveit/planning_scene_interface/planning_scene_interface.h>

#include <moveit_msgs/msg/display_robot_state.hpp>
#include <moveit_msgs/msg/display_trajectory.hpp>

#include <moveit_msgs/msg/attached_collision_object.hpp>
#include <moveit_msgs/msg/collision_object.hpp>

#include <moveit_visual_tools/moveit_visual_tools.h>

// All source files that use ROS logging should define a file-specific
// static const rclcpp::Logger named LOGGER, located at the top of the file
// and inside the namespace with the narrowest scope (if there is one)
static const rclcpp::Logger LOGGER = rclcpp::get_logger("move_group_demo");

int main(int argc, char** argv)
{
  rclcpp::init(argc, argv);
  rclcpp::NodeOptions node_options;
  node_options.automatically_declare_parameters_from_overrides(true);
  auto move_group_node = rclcpp::Node::make_shared("move_group_interface_tutorial", node_options);

  rclcpp::executors::SingleThreadedExecutor executor;
  executor.add_node(move_group_node);
  std::thread([&executor]() { executor.spin(); }).detach();


  static const std::string PLANNING_GROUP = "panda_arm";

  moveit::planning_interface::MoveGroupInterface move_group(move_group_node, PLANNING_GROUP);

  rclcpp::shutdown();
  return 0;
}

Expected behaviour

Running ros2 launch hello_moveit move_group_with_ns.launch.py should gives the same output as running ros2 launch hello_moveit move_group.launch.py . Node hello_moveit should finishes automatically.

Actual behaviour

When running ros2 launch hello_moveit move_group_with_ns.launch.py , node hello_moveit never finishes. It seems the constructor of moveit::planning_interface::MoveGroupInterface never return.

Backtrace or Console output

This is what happened when I run ros2 launch hello_moveit move_group.launch.py

[move_group-1] Loading 'move_group/MoveGroupKinematicsService'...
[move_group-1] Loading 'move_group/MoveGroupMoveAction'...
[move_group-1] Loading 'move_group/MoveGroupPlanService'...
[move_group-1] Loading 'move_group/MoveGroupQueryPlannersService'...
[move_group-1] Loading 'move_group/MoveGroupStateValidationService'...
[move_group-1]
[move_group-1] You can start planning now!
[move_group-1]
[hello_moveit-2] [INFO] [1696830269.760325874] [move_group_interface]: Ready to take commands for planning group panda_arm.
[INFO] [hello_moveit-2]: process has finished cleanly [pid 83817]

Running ros2 launch hello_moveit move_group_with_ns.launch.py

[move_group-1] Loading 'move_group/MoveGroupKinematicsService'...
[move_group-1] Loading 'move_group/MoveGroupMoveAction'...
[move_group-1] Loading 'move_group/MoveGroupPlanService'...
[move_group-1] Loading 'move_group/MoveGroupQueryPlannersService'...
[move_group-1] Loading 'move_group/MoveGroupStateValidationService'...
[move_group-1]
[move_group-1] You can start planning now!
[move_group-1]

There is no further output from node hello_moveit.

Thank you for reading this issue and help me.

@catmulti7 catmulti7 added the bug Something isn't working label Oct 9, 2023
@catmulti7
Copy link
Author

I have figured it out. The constructor of moveit::planning_interface::MoveGroupInterface has another overloaded function which takes the namespace of move_group as a parameter(more accurately, it takes moveit::planning_interface::MoveGroupInterface::Options as a param, which contains the namespace of move_group).
When using custom namespace, create a MoveGroupInterface like this solves above issue

moveit::planning_interface::MoveGroupInterface move_group(
    move_group_node, 
    moveit::planning_interface::MoveGroupInterface::Options(
        PLANNING_GROUP,
        moveit::planning_interface::MoveGroupInterface::ROBOT_DESCRIPTION,
        move_group_namespace));

Note: In my case, string move_group_namespace should have a "/", it should be "/arm_0" rather than "arm_0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant