ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I have done it in this way
class Rosinit
{
static int is_inited = 0;
public:
Rosinit()
{
if(!is_inited){
int argc=0;
char** argv = NULL;
ros::init(argc,argv,"client_test_stage_ros_synced2");
is_inited=1;
}
}
};
class Rosnode_parent
{
Rosinit init;
public:
ros::NodeHandle n;
Rosnode_parent():init()
{};
};
the class Rosnode_parent has a memer Rosinit init, in the constructer this member is initializied with with an argumentlist,this is done bevor a NodeHandle Construkter is called.
in class Rosinit the static member "static int is_inited" enusres that there is only on call of ros::init
I use Rosnode_parent as a super calls and inherite , important is that in the childclass in there own constructer the super constructer is called
2 | No.2 Revision |
I have done it in this way
class Rosinit
{
static int is_inited = 0;
public:
Rosinit()
Rosinit(int argc, char **argv, const char *node_name)
{
if(!is_inited){
int argc=0;
char** argv = NULL;
ros::init(argc,argv,"client_test_stage_ros_synced2");
ros::init(argc,argv,node_name);
is_inited=1;
}
}
};
class Rosnode_parent
{
Rosinit init;
public:
ros::NodeHandle n;
Rosnode_parent():init()
{};
Rosnode_parent(int argc, char **argv, const char *node_name):init(argc, argv, node_name)
{
//...
};
};
the class Rosnode_parent has a memer Rosinit init, in the constructer this member is initializied with with an argumentlist,this is done bevor a NodeHandle Construkter is called.
in class Rosinit the static member "static int is_inited" enusres that there is only on call of ros::init
I use Rosnode_parent as a super calls and inherite , important is that in the childclass in there own constructer the super constructer is called