Threading function - udp client integration to a Ros node
Hi,
I have working ROS node with callBacks for subscriptions, and also with timers like this:
timer= nh.createTimer(ros::Duration(0.050), &Control::spin,this); // 20Hz
void Control::spin(const ros::TimerEvent & e)
But I would like to create additional function which connects to a UDP server and ask data. For this I need to create own function which would run as separate loop alongside other node callBacks. How should i create this, with help of what kind of tools? I guess timer is not the best solution because of constant Hz in loop.
My control node current structure:
int main(int argc, char **argv)
{
printf("*************************************\n");
ros::init(argc, argv, "control");
ros::NodeHandle n;
Control Mcontrol(n);
ros::spin();
return 0;
}
Control class requires itself quite fast response time to its tasks. It subscribes to IMU data ~20Hz and camera coordinate data would be obtained with help of UDP. UDP should be as fast as possible.
All tips are highly appreciated. Thanks.
EDIT: At the moment too busy to try solve this problem this way. Made separate node for UDP-client. Maybe later try to integrate them in to one node. I'm unsure will this make any difference latency wise?
What's wrong with timers? If you want it to run as fast as possible, setting the timeout to 0 should work.
sure, of course i can do that too. I'm just wondering about possible solutions, if timers are the correct way then i'm happy to use them.
Timers will work, but they introduce extra latency for programs like this.