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

How to modify or change C++ file located in the ROS stack

asked 2011-12-01 00:58:46 -0500

maruchi gravatar image

updated 2014-01-28 17:10:55 -0500

ngrennan gravatar image

I have the following error message:

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:52: error: ‘class pr2_mechanism_model::JointState’ has no member named ‘position_1’

/home/username/ros_workspace/my_controller_pkg/src/my_controller_file.cpp:53: error: ‘class pr2_mechanism_model::JointState’ has no member named ‘position_2’

I think it mean I have to delare "position_1" and "position_2" in the "joint.h" file, but this header file belongs to ROS stack so that it will not be changed. Is anybody who know how to modify the C++ header file belonged to ROS stack?

edit retag flag offensive close merge delete


Are you sure, you need to do that. Can't you create two instances of JointState?
dornhege gravatar image dornhege  ( 2011-12-01 01:51:37 -0500 )edit
I think your suggestion will be the right solution. I am trying to working it out with still learning C++. Could you give more detail instructions for the below C++ header file?
maruchi gravatar image maruchi  ( 2011-12-01 02:34:20 -0500 )edit
It's better to update your original post for readabilty.
dornhege gravatar image dornhege  ( 2011-12-01 03:32:04 -0500 )edit
Please find the attached below header file "my_controller_pkg.h". Thanks dornhege.
maruchi gravatar image maruchi  ( 2011-12-01 03:38:05 -0500 )edit
Please edit your question instead of replying with a "answer". Also I recommend using the preformatted blocks for code. Highlight the code and press the 101010 button.
tfoote gravatar image tfoote  ( 2011-12-01 06:22:59 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2011-12-01 01:06:43 -0500

DimitriProsser gravatar image

It is advised not to do this because every update to the ROS stacks will wipe your changes. If you need to make modifications to the ROS stacks, it's generally advised that you check out the source from SVN so that you have control over all updates to the stack.

For the pr2_mechanism_model, you could check out the stack with:

hg clone

(you must have Mercurial installed to do this. sudo apt-get install mercurial).

This is the generally accepted method for making modifications to ROS stacks.

edit flag offensive delete link more


In my created package, C++ header file includes "joint.h" which belongs to ROS stack. But I need to declare additional variables.
maruchi gravatar image maruchi  ( 2011-12-01 01:42:18 -0500 )edit
With the method of this answer you can do that.
dornhege gravatar image dornhege  ( 2011-12-01 01:51:08 -0500 )edit
You would have to uninstall your current pr2_mechanism stack and do this instead. Then you can modify joint.h.
DimitriProsser gravatar image DimitriProsser  ( 2011-12-01 03:13:25 -0500 )edit
Actually it should be enough to put the source version in front of the base version in the ROS_PACKAGE_PATH. I've used that with a hacked openni_kinect driver.
dornhege gravatar image dornhege  ( 2011-12-01 03:32:48 -0500 )edit

answered 2011-12-01 03:36:37 -0500

maruchi gravatar image

updated 2011-12-01 03:40:07 -0500

------------- my_controller_file.h ------------------

include <pr2_controller_interface controller.h="">

include <pr2_mechanism_model joint.h="">

namespace my_controller_ns{

class MyControllerClass: public pr2_controller_interface::Controller {


pr2_mechanism_model::JointState* wheel1_state;

pr2_mechanism_model::JointState* wheel2_state;

//double init_pos_;

double init_pos_1;

double init_pos_2;

double position_1;

double position_2;


virtual bool init(pr2_mechanism_model::RobotState *robot,ros::NodeHandle &n);

virtual void starting();

virtual void update();

virtual void stopping();



edit flag offensive delete link more

Question Tools


Asked: 2011-12-01 00:58:46 -0500

Seen: 901 times

Last updated: Dec 01 '11