ros-controls / ros_control

Generic and simple controls framework for ROS
http://wiki.ros.org/ros_control
BSD 3-Clause "New" or "Revised" License
478 stars 306 forks source link

Possible to have different namespace for control.yaml and hardware_interface.cpp? [Question] #514

Open Doctor-N0 opened 1 year ago

Doctor-N0 commented 1 year ago

For several reasons, it is necessary that my control.yaml has no namespace and thus looks like:

    my_joint_publisher:
       type: "joint_state_controller/JointStateController"
       publish_rate: 50

    my_velocity_controller:
       type: "diff_drive_controller/DiffDriveController"

    hardware_interface:
       joints:
         - front_left_wheel
         - rear_left_wheel
         - front_right_wheel
         - rear_right_wheel

As in this tutorial, I create the JointHandle in my_hardware_interface.cpp. However, I don't receive the DiffDriveController's output when I register to the JointHandle. I assume that this is due to the fact, that the JointHandle is called in my_namespace while my_velocity_controller is assigned to no namespace.

Therefore my question: Is there any possibility to create a JointHandle if it is not in the same namespace as it's controller? Here's an minimal working example of the my_hardware_interface.cpp.

    namespace my_namespace {
        bool MyHWInterface::init(ros::NodeHandle & root_nh, ros::NodeHandle & robot_hw_nh) {
            [...]
            for (unsigned int i = 0; i < num_joints_; i++) {
                // Create JointStateHandle
                hardware_interface::JointStateHandle joint_state_handle(joint_names_[i], & joint_positions_[i], & joint_velocities_[i], & joint_efforts_[i]);

                // Register with JointStateInterface.
                joint_state_interface_.registerHandle(joint_state_handle);

                // Can I create a JointHandle if the DiffDriveController is NOT in my_namespace???
                hardware_interface::JointHandle joint_handle(joint_state_handle, & joint_velocity_commands_[i]);
                velocity_joint_interface_.registerHandle(joint_handle);
            }
        }
    }