Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is it possible to use a certain data value of a topic for executing some code?

Hello, i will try to be as clear as possible. I have a ROS topic in which are published only 0 and 1. In another node i have a subscriber that is subscribed to that topic. Then i had an idea to implement a callback function, that as some code to execute inside, that is called by the subscriber. Let's say that every ten data valued 1 a data valued 0 will show up in the topic. So my question is, is it possible to execute the code inside the callback function only when the subscriber reads 0 in the topic? I mean with a sort of if(...) {...} mechanism or something similar. I apologize if it's not clear, i can provide other details or explanations; just let me know. Thank you in advance!

Is it possible to use a certain data value of a topic for executing some code?

Hello, i will try to be as clear as possible. I have a ROS topic in which are published only 0 and 1. In another node i have a subscriber that is subscribed to that topic. Then i had an idea to implement a callback function, that as some code to execute inside, that is called by the subscriber. Let's say that every ten data valued 1 a data valued 0 will show up in the topic. So my question is, is it possible to execute the code inside the callback function only when the subscriber reads 0 in the topic? I mean with a sort of if(...) {...} mechanism or something similar. I apologize if it's not clear, i can provide other details or explanations; just let me know. Thank you in advance!

EDIT: here is the correct code of the callback function that i mentioned in the comment:

void orderCallback(const std_msgs::Bool::ConstPtr& msg)
{

if (msg->data == 0)
{
chdir("/home/marco/catkin_ws/src/heart_rate_monitor");

system("get_hrv -R my_data_file.txt >doc.txt");
}
}