Error when loading MyControllerClass
Hi, I run this tutorial. And everything seems ok, but at last I couldn't load the controller. How to fix that? Thank you~~
It showed that:
sam@sam-desktop:~/code/ros/controller/joint_controller_pkg$ rosparam set MyControllerClass/type MyControllerPlugin
sam@sam-desktop:~/code/ros/controller/joint_controller_pkg$ rosparam set MyControllerClass/joint_name r_shoulder_pan_joint
sam@sam-desktop:~/code/ros/controller/joint_controller_pkg$ rosrun pr2_controller_manager pr2_controller_manager load MyControllerClass
Error when loading MyControllerClass
sam@sam-desktop:~/code/ros/controller/joint_controller_pkg$
My controller.h
#include <pr2_controller_interface/controller.h>
#include <pr2_mechanism_model/joint.h>
namespace my_controller_ns{
class MyControllerClass: public pr2_controller_interface::Controller
{
private:
pr2_mechanism_model::JointState* joint_state_;
double init_pos_;
public:
virtual bool init(pr2_mechanism_model::RobotState *robot,
ros::NodeHandle &n);
virtual void starting();
virtual void update();
virtual void stopping();
};
}
My controller.cpp
#include <pluginlib/class_list_macros.h>
#include "controller.h"
namespace my_controller_ns {
/// Controller initialization in non-realtime
bool MyControllerClass::init(pr2_mechanism_model::RobotState *robot,ros::NodeHandle &n)
{
//使用時會從console取得joint名字才能繼續執行
std::string joint_name;
if (!n.getParam("joint_name", joint_name))
{
ROS_ERROR("No joint given in namespace: '%s')",
n.getNamespace().c_str());
return false;
}
joint_state_ = robot->getJointState(joint_name);
if (!joint_state_)
{
ROS_ERROR("MyController could not find joint named '%s'",
joint_name.c_str());
return false;
}
return true;
}
/// Controller startup in realtime
void MyControllerClass::starting()
{
init_pos_ = joint_state_->position_;
}
/// Controller update loop in realtime
void MyControllerClass::update()
{
double desired_pos = init_pos_ + 0.5 * sin(ros::Time::now().toSec());
double current_pos = joint_state_->position_;
joint_state_->commanded_effort_ = -10 * (current_pos - desired_pos);
}
/// Controller stopping in realtime
void MyControllerClass::stopping()
{}
} // namespace
/// Register controller to pluginlib
PLUGINLIB_DECLARE_CLASS(joint_controller_pkg,MyControllerPlugin,
my_controller_ns::MyControllerClass,
pr2_controller_interface::Controller)
My CMakeLists.txt
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()
#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})
rosbuild_add_library(joint_controller_lib src/controller.cpp)
My manifest.xml
<package>
<description brief="joint_controller">
joint_controller
</description>
<author>sam</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>
<url>http://ros.org/wiki/joint_controller</url>
<depend package="pr2_controller_interface"/>
<depend package="pr2_mechanism_model"/>
<depend package="pluginlib"/>
<export>
<pr2_controller_interface plugin="${prefix}/controller_plugins.xml" />
</export>
</package>
My controller_plugins.xml
<library path="lib/libjoint_controller_lib">
<class name="joint_controller_pkg/MyControllerPlugin"
type="joint_controller_ns::MyControllerClass"
base_class_type="pr2_controller_interface::Controller" />
</library>
I also find some similar error others met and run the instruction
sam@sam-desktop:~/code/ros/controller/joint_controller_pkg$ nm lib/libjoint_controller.so | grep pocoBuildManifest
00002f30 T pocoBuildManifestjoint_controller_pkg__MyControllerPlugin
sam@sam-desktop:~/code/ros/controller/joint_controller_pkg$
I also run rxconsole,and it showed that
Could not load class MyControllerPlugin: According to the loaded plugin descriptions the class MyControllerPlugin with base class type pr2_controller_interface::Controller does not exist ...