Can I define publishers in a function and then I can call that function in main() file? Can I really?
I just wanted to ask whether I can define my publisher in a function and then call the function in a main() file like the following code sniplet exhibits:
static void myfunct(stream* str, strble *conv, unsigned char *buff, int n){
ros::NodeHandle nh;
ros::Publisher pub_navigation_msg = nh.advertise<rtklib::Navigation>("nav_topic", 10);
rtklib::Navigation navmsg;
navmsg.time= conv->time;
pub_navigation_msg.publish(navmsg);
}
int main(int argc, char** argv){
ros::Rate r(1);
while (ros::ok()){
myfunct();
}
ros::spinOnce();
}