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

Revision history [back]

I would do the following.

bool is_receive;

void callback_topic_A(msgtype &msg)
{
    is_receive = true;
}

// ...
    ros::Rate loop(frequency);
    is_receive = false;
    while(ros::ok()){
        if (new message on topic A is received){
            //do some computations and publish messages
            is_receive = false;
        }
        loop.sleep();
        ros::spinOnce();
    }

If there is a better way, I would love to know.

I would do the following.

bool is_receive;

void callback_topic_A(msgtype &msg)
{
    is_receive = true;
}

// ...
    ros::Rate loop(frequency);
    is_receive = false;
    while(ros::ok()){
        if (new message on topic A is received){
(is_receive){
            //do some computations and publish messages
            is_receive = false;
        }
        loop.sleep();
        ros::spinOnce();
    }

If there is a better way, I would love to know.