# Revision history [back]

Hi everyone,

After studying this problem for a while I think I have reached a solution that fits my requirements. For anyone wanting to solve this kind of problem I will post here my approach:

So let's say we have a Node with a init function that calls nh.suscribeand/or nh.advertise funtion(s) to initialize the Node Class. The class owns a subscriber to a /reset topic in order to reset its params and subs/pubs connections. With this set up, when the /reset callback is called the init funtion is executed, but you only want to call it once since the connection to this reset callbak is being generated again. So, the problem is to avoid executing this init function from a latched topic or a topic in which is being publisher rapidly in a period of time. For this to only happen once you can use the time at which the init funtion is called.

E.g.:

Node::init
{
[...]
private_nh_.param<double>(reset_time", reset_time_, 3.0);
last_callback_ = ros::Time::now();
}

Node::resetCallback
{
ros::Duration elapsed_time = ros::Time::now() - last_callback_;
if(elapsed_time.toSec() > reset_time_)
{
init();
}
}


With this you can avoid calling the init function multiple times.

Hope this can help. If anyone come up with a more elegant solution I will glad to discuss it here.

Cheers.

Hi everyone,

After studying this problem for a while I think I have reached a solution that fits my requirements. For anyone wanting to solve this kind of problem I will post here my approach:

So let's say we have a Node with a init function that calls nh.suscribeand/or nh.advertise funtion(s) to initialize the Node Class. The class owns a subscriber to a /reset topic in order to reset its params and subs/pubs connections. With this set up, when the /reset callback is called the init funtion is executed, but you only want to call it once since the connection to this reset callbak is being generated again. So, the problem is to avoid executing this init function from a latched topic or a topic in which is being publisher rapidly in a period of time. For this to only happen once you can use the time at which the init funtion is called.

E.g.:

Node::init
{
[...]
//[...]
private_nh_.param<double>(reset_time", reset_time_, 3.0);
last_callback_ = ros::Time::now();
}

Node::resetCallback
{
ros::Duration elapsed_time = ros::Time::now() - last_callback_;
if(elapsed_time.toSec() > reset_time_)
{
init();
}
}


With this you can avoid calling the init function multiple times.

Hope this can help. If anyone come up with a more elegant solution I will glad to discuss it here.

Cheers.