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

Simple URDF-Controller Example

asked 2011-11-22 10:24:57 -0600

maruchi gravatar image

updated 2011-11-23 01:37:16 -0600

Hi, I have been trying to figure it out "Simple URDF-Controller Example" in the following link, If there is anyone who know the details to follow the above example, could you let me know it? I followed all the required recommendation, but could not complete the tutorial.

Before describing what problems I have in following the "Simple URDF-Controller Example", I want to say that my overall goal is that making robot model, putting state feedback controller, and simulating using ROS. Eventually the final goal will be implementing on Gumstix.

About following the above tutorial, "Simple URDF-Controller Example", I followed the recommended tutorial, "Writing a realtime joint controller", which is on the link, . I have no problem in this tutorial. Based on this tutorial, to follow the tutorials of "Simple URDF-Controller Example", the procedures I have taken are:

$ roscreate-pkg my_controller_pkg pr2_controller_interface pr2_mechanism_model pluginlib $ roscd my_controller_pkg $ rosmake And I put robot.xml (which is in the also create a directory src and a file called src/my_controller_file.cpp ) inside the new package and create the directory include, then include/my_controller_pkg/my_controller_file.h, where this .h file is in "Writing a realtime joint controller". And also create a directory src and a file called src/my_controller_file.cpp, where this .cpp file is made according to "Simple URDF-Controller Example" and "Writing a realtime joint controller". And Open the CMakeLists.txt file, and add the following line on the bottom: rosbuild_add_library(my_controller_lib src/my_controller_file.cpp) and $ make

Then the following error messages are shown:

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp: In member function ‘virtual bool my_controller_ns::MyControllerClass::init(pr2_mechanism_model::RobotState*, ros::NodeHandle&)’: /home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:22: error: ‘wheel1_state’ was not declared in this scope

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:38: error: ‘wheel2_state’ was not declared in this scope

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:50: error: a function-definition is not allowed here before ‘{’ token

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:57: error: a function-definition is not allowed here before ‘{’ token

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:66: error: a function-definition is not allowed here before ‘{’ token

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp: At global scope:

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:67: error: expected ‘}’ at end of input

make[3]: * [CMakeFiles/my_controller_lib.dir/src/my_controller_file.o] Error 1

make[3]: Leaving directory `/home/username/ros_workspace/my_controller_pkg/build'

make[2]: * [CMakeFiles/my_controller_lib.dir/all] Error 2

make[2]: Leaving directory `/home/username/ros_workspace/my_controller_pkg/build'

make[1]: * [all] Error 2

make[1]: Leaving directory `/home/username/ros_workspace/my_controller_pkg/build'

make: * [all] Error 2

That is why I can not proceed on the tutorial, "Simple URDF-Controller Example".

Here is my_controller_file.cpp: include "my_controller_pkg/my_controller_file.h" include <pluginlib class_list_macros.h="">

namespace my_controller_ns {

/// Controller initialization in non-realtime bool MyControllerClass::init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n) { std::string wheel1, wheel2;

///Link all Joints //////////////////////////////////////////////////////////////////////// if (!n ... (more)

edit retag flag offensive close merge delete


What exactly failed ?
Guido gravatar image Guido  ( 2011-11-22 19:57:32 -0600 )edit

3 Answers

Sort by » oldest newest most voted

answered 2011-11-23 10:20:04 -0600

bit-pirate gravatar image

Well, the output gives some hints: [...] error: ‘wheel1_state’ was not declared in this scope error: ‘wheel2_state’ was not declared in this scope [...] So, I would start with declaring wheel1_state and wheel2_state. :-) Or, as Guido asked, are you talking about another problem?

edit flag offensive delete link more

answered 2011-11-25 00:56:08 -0600

Guido gravatar image

As Marcus said, you should declare wheel1_state and wheel2_state. In "writing a realtime controller", only one joint is controlled and its state is retrieved in the variable "joint_state_" declared in "my_controller_file.h . In your case, you will need two joints states (one for each wheel), so you have to replace "joint_state_" with "wheel1_state" and "wheel2_state".

Hope this helps,


edit flag offensive delete link more

answered 2011-11-27 10:36:22 -0600

maruchi gravatar image

Thanks, Guido. I followed your recommendation but still have error due to no changes made in the parts of Controller startup in realtime and Controller update loop in realtime in the my_controller_file.cpp. Could you let me know how to change the below codes in the cpp file ?

/// 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_ + 15 * sin(ros::Time::now().toSec()); double current_pos = joint_state_->position_; joint_state_->commanded_effort_ = -10 * (current_pos - desired_pos); }

edit flag offensive delete link more


You will have to keep track of two init_pos, two desired_pos, two current_pos and two commanded_effort.
Guido gravatar image Guido  ( 2011-11-27 21:27:07 -0600 )edit
Guido, how about "joint_state_" ? Do I have to write in this way? From "init_pos_ = joint_state_->position_" To "init_pos_1 = joint_state_1->position_1" and "init_pos_2 = joint_state_2->position_2"
maruchi gravatar image maruchi  ( 2011-11-30 02:42:09 -0600 )edit
yes, but as far as I know, you doesn't use joint_state1(/2) but wheel1(/2)_state
Guido gravatar image Guido  ( 2011-12-04 19:40:07 -0600 )edit

Question Tools

1 follower


Asked: 2011-11-22 10:24:57 -0600

Seen: 788 times

Last updated: Dec 01 '11