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

Multiple bondcpp bonds between nodes

asked 2017-04-18 09:28:41 -0500

l4ncelot gravatar image

updated 2017-04-19 03:51:26 -0500

Hi,

what I want to achieve is to create system watchdog informing me when some of my nodes crash.

The problem is that the bonds cannot be created. Or at least they die after few seconds. When I test this in rqt_graph I can see the connections between my nodes and system watchdog established. But after a few seconds all bonds are broken for some reason. Is this the right way how to create list of bonds? Am I missing something?

Here's my example of such a watchdog:

std::string filename_;
std::vector<std::string> node_list_;
std::vector<std::shared_ptr<bond::Bond>> bonds_;

void initFilename() {
    std::string home_directory = getenv("HOME");
    if (home_directory.empty()) {
        home_directory = getpwuid(getuid())->pw_dir;
    }
    filename_ = home_directory + "/aft_copter/src/aft_copter/aft_safety/config/node_list.txt";
}

void initNodeList() {
    if (filename_.empty()) return;

    std::ifstream file(filename_.c_str());
    std::string text;

    while (std::getline(file, text)) {
        node_list_.push_back(text + "_bond");
    }

}

void initBonds() {
    if (node_list_.empty()) return;

    bonds_.resize(node_list_.size());

    int i{0};
    for (auto&& node :node_list_) {
        bonds_.at(i) = std::make_shared<bond::Bond>(node + "_topic", node);
        bonds_.at(i)->start();
        i++;
    }

}

int main(int argc, char** argv) {
    ros::init(argc, argv, "system_watchdog");
    ros::NodeHandle nh;

    initFilename();
    initNodeList();
    initBonds();

    ros::Rate rate(20.0);
    while (ros::ok()) {
        ros::spinOnce();
        rate.sleep();
    } 

    return 0;
}

This code basically reads names of nodes saved in text file and creates bonds with those nodes. Then in those nodes I do something like this:

class PatternRecognitionAction {
public:
    PatternRecognitionAction(){
        initBond();
    }
    void initBond() {
        std::string node_name = "pattern_recognition_action";
        bond_ = std::make_shared<bond::Bond>(node_name + "_bond_topic",
                                             node_name + "_bond");
        bond_->start();
    }

private:
    std::shared_ptr<bond::Bond> bond_;


int main(int argc, char** argv) {
    ros::init(argc, argv, "pattern_recognition");

    PatternRecognitionAction pattern_recognition("pattern_recognition");

    ros::spin();

    ROS_INFO_STREAM("Ready to recognize pattern.");

    return 0;
}
edit retag flag offensive close merge delete

Comments

1

'node_name' is not defined in your lower example. You can reuse a topic for all bonds is defined by the topic AND the bond_name. How long are the nodes established? How many nodes do you connect with the central server? Is it possible that setting up all the bonds takes too long?

NEngelhard gravatar image NEngelhard  ( 2017-04-18 14:18:39 -0500 )edit

The node_name variable was not declared in my example, but in my original code it is defined. I've tried only 3 bonds, but even with 1 bond this example doesn't work. The strange thing is that when I look at bond_topic I can see messages coming there. But after 6 messages, bond is broken.

l4ncelot gravatar image l4ncelot  ( 2017-04-19 03:48:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-04-19 10:39:56 -0500

l4ncelot gravatar image

Ok, so after a while I've figured it out. I had my watchdog in different namespace which should be fine because I could see connections between my watchdog and nodes in rqt_graph. So I've changed the namespace names and now it's working for some reason...

edit flag offensive delete link more

Comments

The namespace needs to match on both ends of the bond; this is how multiple nodes share the same bond topic.

ahendrix gravatar image ahendrix  ( 2017-04-19 12:17:57 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-18 09:28:41 -0500

Seen: 554 times

Last updated: Apr 19 '17