ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
This is purely a C++ question. In the future it would be best if you'd post these on a forum dedicated to C++ questions.
In this particular case:
LoadRobot::LoadRobot() { // Load robot model robot_model_loader::RobotModelLoader robot_model_loader("robot_description"); robot_model::RobotModelPtr kinematic_model = robot_model_loader.getModel(); }
the problem here is that kinematic_model
is a variable defined and declared in the local scope of LoadRobot
.
As soon as that scope exits (ie: ceases to exist), it will destroy all variables declared in it, including kinematic_model
.
kinematic_model
simply doesn't exist any more in create_group()
.
Should I put what's in the constructor to the header file and make them private?
I'm not sure I entirely understand what you mean by this, but one option could be to make kinematic_model
a member variable indeed, and then initialise it in the constructor. At that point it would be part of a scope other than the local one of LoadRobot
and persist to be used by create_group()
.
But again: this is purely a C++ related question. The fact that ROS classes are being used (or more precisely: MoveIt) does not factor in here.