Can't load custom controller
I am learning ros_control
and trying to create and use own controller. But controller spawner couldn't load it.
I created empty dumb controller:
namespace roscontrol_test
{
class MyController : public controller_interface::Controller<hardware_interface::PositionJointInterface>
{
public:
virtual bool init(hardware_interface::PositionJointInterface *hw, ros::NodeHandle &n) override
{
return true;
}
virtual void starting(const ros::Time & /*time*/) override {}
virtual void update(const ros::Time &time, const ros::Duration &period) override {}
virtual void stopping(const ros::Time& /*time*/) override {}
};
PLUGINLIB_EXPORT_CLASS(roscontrol_test::MyController, controller_interface::ControllerBase);
}
I configure plugin.
controller_plugin.xml
<library path="lib/libmy_controller">
<class
name="roscontrol_test/MyController"
type="roscontrol_test::MyController"
base_class_type="controller_interface::ControllerBase">
<description>This is an example ros_control plugin.</description>
</class>
</library>
package.xml
...
<export>
<roscontrol_test plugin="${prefix}/controller_plugins.xml"/>
</export>
...
I also test that pluginlib can load this plugin:
int main(int argc, char** argv)
{
pluginlib::ClassLoader<controller_interface::ControllerBase> controller_loader("roscontrol_test", "controller_interface::ControllerBase");
try
{
auto controller = controller_loader.createInstance("roscontrol_test/MyController");
ROS_INFO("Plugin loaded");
}
catch(pluginlib::PluginlibException& ex)
{
ROS_ERROR("Failed to load plguin");
ROS_ERROR(ex.what());
}
return 0;
}
And all is OK. Finally, I create simple robot and this is a YAML config:
arm:
# publish all joint states
joint_state_controller:
type: joint_state_controller/JointStateController
publish_rate: 50
# position controllers
pan_joint_position_controller:
type: position_controllers/JointPositionController
joint: pan_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
tilt_joint_position_controller:
#type: position_controllers/JointPositionController
type: roscontrol_test/MyController
joint: tilt_joint
But I faced with error while loading:
[ INFO] [1520931242.427358562, 0.308000000]: Loaded gazebo_ros_control.
[INFO] [1520931242.500081, 0.380000]: Controller Spawner: Waiting for service controller_manager/switch_controller
[INFO] [1520931242.503352, 0.383000]: Controller Spawner: Waiting for service controller_manager/unload_controller
[INFO] [1520931242.506296, 0.387000]: Loading controller: joint_state_controller
[INFO] [1520931242.517501, 0.398000]: Loading controller: pan_joint_position_controller
[INFO] [1520931242.531252, 0.412000]: Loading controller: tilt_joint_position_controller
[ERROR] [1520931242.534222608, 0.415000000]: Could not load controller 'tilt_joint_position_controller' because controller type 'roscontrol_test/MyController' does not exist.
[ERROR] [1520931242.534263585, 0.415000000]: Use 'rosservice call controller_manager/list_controller_types' to get the available types
[urdf_spawner-4] process has finished cleanly
log file: /home/garrus/.ros/log/12367bb2-269c-11e8-8a6d-94de802129d7/urdf_spawner-4*.log
[ERROR] [1520931243.535656, 1.414000]: Failed to load tilt_joint_position_controller
[INFO] [1520931243.536768, 1.415000]: Controller Spawner: Loaded controllers: joint_state_controller, pan_joint_position_controller
[INFO] [1520931243.542771, 1.421000]: Started controllers: joint_state_controller, pan_joint_position_controller
Why controller spawner couldn't load controller, but I can load it manually by pluginlib?
Asked by markovalexey on 2018-03-13 03:59:21 UTC
Answers
I've found that you need a depend
on controller_interface
in package.xml. Did you have that?
Asked by AndyZe on 2018-11-01 16:44:11 UTC
Comments
Did the comment below solve this issue for you, or was there another step you took? My ROS package depends directly on another package that contains a custom controller plugin, but the controller manager still can't find my controller type.
Asked by jdcarp19 on 2019-10-11 17:00:39 UTC