gz_ros2_control icon indicating copy to clipboard operation
gz_ros2_control copied to clipboard

added namespace to controller manager

Open ahcorde opened this issue 2 years ago • 2 comments

Signed-off-by: ahcorde [email protected]

Minor fix to allow CM to be run in the defined namespace, ref https://github.com/ros-controls/gazebo_ros2_control/pull/122

Related PR https://github.com/ros-controls/gazebo_ros2_control/pull/147

ahcorde avatar Jul 28 '22 09:07 ahcorde

@ahcorde @destogl It seems after looking around in the code that adding the namespace while creating the controller_manager is not enough. This should maybe be done also for the ignition_ros_control node

  std::string node_name = "ignition_ros_control";
  this->dataPtr->node_ = rclcpp::Node::make_shared(node_name, this->dataPtr->node_->get_namespace());

And also for rclcpp::init(static_cast<int>(argv.size()), argv.data()); we should take away the namespace argument

  std::string ns_arg = std::string("__ns:=") + ns;
  arguments.push_back(RCL_REMAP_FLAG);
  arguments.push_back(ns_arg);

since this will initialize our context inside the namespace and then whenever we try to create a new controller_manage it will do it inside the same context and thus the same namespace.

Testing this seems to work and will give us separated controller_manager instances in different namespaces but when we try to spawn our controllers they will be without namespace.

moutalibbadr avatar Jul 29 '22 13:07 moutalibbadr

Hi @ahcorde, I don't know if you had time to look at my last comment. Having tested those changes locally seemed to fix the namespacing for the create3 with multiple instances of the robot in the same simulation. We had however to prefix our controllers in the config files e.g:

/robot_0:
  controller_manager:
    ros__parameters:
      update_rate: 1000  # Hz

      robot_0_joint_state_broadcaster:
        type: joint_state_broadcaster/JointStateBroadcaster

      robot_0_diffdrive_controller:
        type: diff_drive_controller/DiffDriveController   

/robot_1:
  controller_manager:
    ros__parameters:
      update_rate: 1000  # Hz

      robot_1_joint_state_broadcaster:
        type: joint_state_broadcaster/JointStateBroadcaster

      robot_1_diffdrive_controller:
        type: diff_drive_controller/DiffDriveController

and our controller nodes appear like this :

/robot_0_diffdrive_controller
/robot_0_joint_state_broadcaster
/robot_1_diffdrive_controller
/robot_1_joint_state_broadcaster

And in the case of no namespacing it seemed to be working fine so i suppose these changes should not cause problems for normal applications that do not involve namespacing.

Tell me if i should put this in a separate PR.

moutalibbadr avatar Aug 09 '22 09:08 moutalibbadr

Seems to be fixed with https://github.com/ros-controls/gz_ros2_control/pull/92 and https://github.com/ros-controls/gz_ros2_control/pull/128

christophfroehlich avatar Jul 06 '24 12:07 christophfroehlich