[ros-users] read value of a topic from the callback of another topic

Gonçalo Cabrita goncabrita at gmail.com
Thu Nov 18 16:32:29 UTC 2010


Hi!

I guess I would suggest something simple like storing the values coming from
the other callback on a std_msgs::String class variable and accessing it
from the void imageCallback(const sensor_msgs::ImageConstPtr& msg_ptr)
function.

Hope this helps,

Gonçalo Cabrita
ISR - University of Coimbra
Portugal

On Thu, Nov 18, 2010 at 4:01 PM, <gatemaze at gmail.com> wrote:

> Hello,
>
> sorry if this is a basic question but I couldn't find anything in the wiki.
> I would like to retrieve the current value of a topic from the callback of
> another topic. How is this possible? In more detail I have:
>
> public:
>     ImageConverter(ros::NodeHandle &n) : n_(n), it_(n_)
>     {
>         cvNamedWindow("Image window");
>         image_sub_ = it_.subscribe("/camera_sim/image_raw", 1,
> &ImageConverter::imageCallback, this);
>     }
>
> void imageCallback(const sensor_msgs::ImageConstPtr& msg_ptr)
> {
>         // Image obtained from subscribed node and converted to IplImage
>         IplImage *img = NULL;
>         try {
>             img = bridge_.imgMsgToCv(msg_ptr, "bgr8"); // reads the image
>             // I WOULD LIKE TO READ THE VALUE OF ANOTHER TOPIC
> (std_msgs::String) HERE
>         }
>         catch (sensor_msgs::CvBridgeException error) {
>             ROS_ERROR("error");
>         }
> }
>
> Many Thanks
>
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20101118/88bd25fc/attachment-0003.html>


More information about the ros-users mailing list