0
$\begingroup$

Rosanswers logo

Hi, I have been trying to figure it out "Simple URDF-Controller Example" in the following link, http://www.ros.org/wiki/pr2_mechanism/Tutorials/SImple%20URDF-Controller%20Example. 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, http://www.ros.org/wiki/pr2_mechanism/Tutorials/Writing%20a%20realtime%20joint%20controller . 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

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.getParam("wheel1", wheel1)) { ROS_ERROR("No joint given in namespace: '%s')", n.getNamespace().c_str()); return false; }

wheel1_state = robot->getJointState(wheel1); if (! wheel1_state ) { ROS_ERROR("MyController could not find joint named '%s'", wheel1.c_str()); return false; }

//////////////////////////////////////////////////////////////////////// if (!n.getParam("wheel2", wheel2)) { ROS_ERROR("No joint given in namespace: '%s')", n.getNamespace().c_str()); return false; }

wheel2_state = robot->getJointState(wheel2); if (!wheel2_state ) { ROS_ERROR("MyController could not find joint named '%s'", wheel2.c_str()); return false; }

/// 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); }

/// Controller stopping in realtime void MyControllerClass::stopping() {} } // namespace

thanks in advance


Originally posted by maruchi on ROS Answers with karma: 157 on 2011-11-22

Post score: 0


Original comments

Comment by Guido on 2011-11-22:
What exactly failed ?

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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?


Originally posted by bit-pirate with karma: 2062 on 2011-11-23

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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,

Guido


Originally posted by Guido with karma: 514 on 2011-11-25

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.