网络安全检测|网络安全服务|网络安全扫描-香港墨客投资移动版

主页 > 业界资讯 > Routers配置

roscpp/Overview/Callbacks and Spinning(2)

This makes all subscription, service, timer, etc. callbacks go through my_callback_queue instead of roscpp's default queue. This means ros::spin() and ros::spinOnce() will not call these callbacks. Instead, you must service that queue separately. You can do so manually using the ros::CallbackQueue::callAvailable() and ros::CallbackQueue::callOne() methods:

my_callback_queue.callAvailable(ros::WallDuration()); // alternatively, .callOne(ros::WallDuration()) to only call a single callback instead of all available

The various *Spinner objects can also take a pointer to a callback queue to use rather than the default one:

ros::AsyncSpinner spinner(0, &my_callback_queue); spinner.start();

or

ros::MultiThreadedSpinner spinner(0); spinner.spin(&my_callback_queue);

Uses

Separating out callbacks into different queues can be useful for a number of reasons. Some examples include:

Long-running services. Assigning a service its own callback queue that gets serviced in a separate thread means that service is guaranteed not to block other callbacks.

Threading specific computationally expensive callbacks. Similar to the long-running service case, this allows you to thread specific callbacks while keeping the simplicity of single-threaded callbacks for the rest your application.

(责任编辑:admin)