# Heartbeat-bond: being aware of aliveness of other nodes

Hi!

Situation: running ROS Kinetic on a Ubuntu 16.04 x86 I am working on a project, in which i would create a dynamic network in which a central node can manage all the operations needed to put the others in contact, while having an up-to-date list of the online nodes. It means, since every "user" node, when launched, must call a service of the central one, i want this to keep track of the online users' nodes, adding its references in a structure, and then deleting them once they are out.

Problem: I need something like an heartbeat, so that a node can feel when another one is out.

Attempts: I had a look for it, but i haven't found a "direct" way to do so, like a quick way to see if the topic you were subscribing stopped working. It would be of course the best way: do you know something like that?

-bond: I found the bond package, that seems to do what i want, but i had problems in building it up. Just adding the 2 lines in both the nodes i want to be linked

bond::Bond bond("heartbeat", id); // id is a std::string as required
bond.start();


undefined reference to bond::Bond::Bond(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::function<void ()>, boost::function<void ()>)
utm_node.cpp:(.text+0x6d0): undefined reference to bond::Bond::start()'
utm_node.cpp:(.text+0x6ef): undefined reference to bond::Bond::~Bond()'
utm_node.cpp:(.text+0x864): undefined reference to bond::Bond::~Bond()'


Now: the needed page to understand everything would be that, i am trying but i still have to practice swimming in that sea. I have some questione regarding the bond itself:

the bond is defined with a topic and an id, that should coincide with the one of the other node. Is this topic unique (meaning: can i create a single heartbeat topic receiving many heatbeat with different IDs) or i should create a topic for every bond? and if so: should i declare a bond::Bond for every heartbeat? and if so: how can i manage a dynamic network (i am not supposed to know a priori how many nodes will connect and their name) with such a static mechanism?

and, at this point: wishing to create a bond between 2 nodes, and a callback when it breaks, i have doubt on how to do it. looking at the documentation, we have:

bond::Bond bond(const std::string &     topic,
const std::string &     id,
boost::function< void(void)> on_broken boost::function<void(void)>(),
boost::function< void(void)>   on_formed = boost::function<void(void)>()
)


How should i declare the cb to be called on_broken? maybe...

    bond::Bond bond("example_bond_topic", id, on_broken = callback);


or, thinking on how i build up a subscriber and its callback...

        bond::Bond bond("example_bond_topic", id, &callback);


then creating the cb routine as (don't ...

edit retag close merge delete