ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Creating Controller Plugin No joint_name specified

asked 2022-05-21 22:32:07 -0600

CroCo gravatar image

updated 2022-05-22 04:27:59 -0600

I'm having an issue with making the plugin works in Gazebo 9 and melodic in ubuntu 18.04. I'm keep getting these errors

[ERROR] [1653189634.080473330, 0.379000000]: No joint_name specified
[ERROR] [1653189634.080611896, 0.379000000]: Failed to initialize the controller
[ERROR] [1653189634.080791301, 0.379000000]: Initializing controller 'joint1_position_controller' failed
[INFO] [1653189634.710451, 1.015000]: Calling service /gazebo/set_model_configuration
[INFO] [1653189634.717597, 1.019000]: Set model configuration status: SetModelConfiguration: success
[spawn_urdf-4] process has finished cleanly
log file: /home/bandar/.ros/log/214f367c-d97e-11ec-baf2-f07bcb42944d/spawn_urdf-4*.log
[ERROR] [1653189635.082707, 1.369000]: Failed to load joint1_position_controller

For controller_plugins.xml file, I have

<library path="lib/libmy_controller_lib">
    <class name="my_position_controller/MyPositionController" 
           type="my_controller_ns::MyPositionController"
           base_class_type="controller_interface::ControllerBase" />
</library>

I'm not sure what needs to be written in class name=. Should I type the name of the package or the name of namespace in my class? I've tried both but with no success. The shared library has been created successfully though. My source file is

namespace my_controller_ns 
{
    class MyPositionController : public controller_interface::Controller<hardware_interface::EffortJointInterface>
    {...}
}

The .yaml file is

rrbot:
  # Publish all joint states ------------------------
  joint_state_controller:
    type: joint_state_controller/JointStateController
    publish_rate: 50

  # Position Controllers ----------------------------
  joint1_position_controller:
    type: my_position_controller/MyPositionController
    joint: joint1
    gain: 0.1

I'm totally sure the name of the joint is joint1 and this is my source file related to this part

// retrieve the joint object to control
    std::string joint_name;
    if( !n.getParam("joint1", joint_name) ){
        ROS_ERROR("No joint_name specified");
        return false;
    }

    joint_ = hw->getHandle(joint_name);
    command_ = joint_.getPosition();

When I run

>rospack plugins --attrib=plugin controller_interface

I get this listed

my_position_controller /home/xxx/Desktop/RosControllers/catkin_ws1/src/my_position_controller/controller_plugins.xml

I also made sure the gazebo_ros and transmission tags are added

<!-- ***** Transmission Tags ***** -->
<transmission name="transmission1">
   <type>transmission_interface/SimpleTransmission</type>
   <joint name="joint1">
     <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
   </joint>
   <actuator name="motor1">
     <hardwareInterface>EffortJointInterface</hardwareInterface>
     <mechanicalReduction>1</mechanicalReduction>
   </actuator>
</transmission>

<!-- ros_control pluging -->
<gazebo>
   <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
       <robotNamespace>/rrbot</robotNamespace>
       <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
   </plugin>
</gazebo>

Moreover, the namespace is consistent with the launch file

<node name="control_spawner" pkg="controller_manager" type="spawner" respawn="false"
        output="screen" ns="/rrbot" args="joint_state_controller joint1_position_controller"/>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-05-22 18:56:04 -0600

CroCo gravatar image

Ok I've solved this problem and I would like share it since a lot of people are complaining. The errors come usually as

1- Controller Spawner couldn't find the expected controller_manager ROS interface.
2- Failed to initialize the controller
3- Initializing controller 'joint1_position_controller' failed

This error pops up from different sources. First, make sure you installed all related control packages

ros-<rosdistro>-ros-control  ros-<rosdistro>-ros-controllers ros-<rosdistro>-gazebo-ros ros-<rosdistro>-gazebo-ros-control

Second, if you are using namespace as in the following line which is located in .urdf file

<gazebo>
        <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
            <robotNamespace>/rrbot</robotNamespace>
            <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
        </plugin>
</gazebo>

Make sure you are using the same namespace in .launch and .yaml files which appears as ns="/rrbot"

 <node name="control_spawner" pkg="controller_manager" type="spawner" respawn="false"
      output="screen" ns="/rrbot" args="joint1_position_controller"/>

and the .yaml may look like this

rrbot:
  # Publish all joint states ------------------------
  joint_state_controller:
    type: joint_state_controller/JointStateController
    publish_rate: 50

  # Position Controllers ----------------------------
  joint1_position_controller:
    type: my_controller/MyPositionController
    joint: joint1
    gain: 0.1

If you are using your own plugin controller, you better check it is registered which can be done as (i.e. source your catkin_ws folder first)

rospack plugins --attrib=plugin controller_interface | grep my_controller

you should except to get something like this

my_controller /home/xxx/Desktop/RosControllers/catkin_ws1/src/my_controller/controller_plugins.xml

In my case none of the above solutions solved my problem. The interesting thing I found getParam() is not getting the correct joint name which in the source file as

bool MyPositionController::init(hardware_interface::EffortJointInterface* hw, ros::NodeHandle &n)
{
    // retrieve the joint object to control
    std::string joint_name;
    if( !n.getParam("joint1", joint_name) ){
        ROS_ERROR("No joint name specified");
        return false;
    }
     ....
}

when I type "joint" rather than "joint1" which represents the joint's name in my .urdf, the error gone. I've seen some books use "joint_name" which yields an error as well. I'm not sure if this is a new update or these books use old ros version which uses joint_name rather than joint. I'm using Gazebo 9 and Melodic in Ubuntu 18.04.

edit flag offensive delete link more

Comments

You're jumping to conclusions a bit I believe.

Here:

  joint1_position_controller:
    type: my_position_controller/MyPositionController
    joint: joint1

In the last line, the name of the parameter would be joint1_position_controller/joint, notjoint1_position_controller/joint1.

joint1 is the value.

So this:

n.getParam("joint1", joint_name)

cannot work, as there is no parameter with the namejoint1. There is only a joint parameter, with valuejoint1.

This has nothing to do with namespaces or any of the other things you mentioned.

when I type "joint" rather than "joint1" which represents the joint's name in my .urdf, the error gone

no, again, this is due to joint being the name, and joint1 being the value.

You can only pass getParam(..) a name, not a value.

gvdhoorn gravatar image gvdhoorn  ( 2022-05-23 02:21:16 -0600 )edit

@gvdhoom thank you for the comment. I was following a book and the author put it as joint_name but since the error's message is same for other errors, it drove me nuts until I saw there is a problem with the parameter.

CroCo gravatar image CroCo  ( 2022-05-23 02:37:00 -0600 )edit

Ok.

I still believe what you posted as an answer isn't really the answer, but you seem to be happy, so that is probably enough.

gvdhoorn gravatar image gvdhoorn  ( 2022-05-23 03:03:51 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2022-05-21 22:32:07 -0600

Seen: 108 times

Last updated: May 22 '22