Ask Your Question
0

Several Images in one msg, How can I do it?

asked 2016-08-19 05:02:17 -0500

Rodrigo Lourenço gravatar image

updated 2016-08-19 08:41:25 -0500

The code I have is the following:

 
int main(int argc, char **argv)
{
    ros::init(argc, argv, "image_listener");
        ros::NodeHandle nh;
    ros::Rate loop_rate(100);       // Rate class instance. 
    ImageManagmentStruct LeftCameraImageStructForGrid, RightCameraImageStructForGrid, KinectImageStructForGrid, KinectDepthImageStructForGrid;      
    ImageManagmentStruct LeftCameraImageStructOneImage, RightCameraImageStructOneImage, KinectImageStructOneImage, KinectDepthImageStructOneImage;

    // Initializing the image/camera data structures.   
    dataStructuresInitialization ( &LeftCameraImageStructForGrid, 
                                   &RightCameraImageStructForGrid, 
                                   &KinectImageStructForGrid,
                                   &KinectDepthImageStructForGrid,
                                   &LeftCameraImageStructOneImage,
                                   &RightCameraImageStructOneImage,
                                   &KinectImageStructOneImage,
                                   &KinectDepthImageStructOneImage
                                 );

    // GTK library initialization
    gtk_init ( &argc, &argv );

    // Creating a top level window and connecting it to a sygnal.    
    createMainInterfaceWindow (); 

    // Creating a fixed container, which will hold all the widgets of the GUI.
    createFixedContainer ();

    // Creating a GtkGrid widget, which will contain all the images.
    createGtkTable ();

    // Attaching the created table to the Container.
    gtk_fixed_put (GTK_FIXED (pGlobalFixedContainer), pGlobalGtkTable, IMAGES_HORIZONTAL_PLACEMENT, IMAGES_VERTIACL_PLACEMENT);

    // Subscribing in order to receive images.

    //ros::Subscriber subLeft = nh.subscribe<sensor_msgs::image> ("/republished/bb2/triclops/left/image_raw", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[0], globalArrayForSingleImages[0]));  
    // ros::Subscriber subRight = nh.subscribe<sensor_msgs::image> ("/republished/bb2/triclops/right/image_raw", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[1], globalArrayForSingleImages[1])); 
    // ros::Subscriber subKinect = nh.subscribe<sensor_msgs::image> ("/republished/usb_cam/image_raw", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[2], globalArrayForSingleImages[2]));
    // ros::Subscriber subKinectDepth = nh.subscribe<sensor_msgs::image> ("/republished/usb_cam/image_raw", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[3], globalArrayForSingleImages[3]));

    //New Code, replacing the ros::Subscriber
    image_transport::ImageTransport it(nh);
    image_transport::Subscriber subLeft = it.subscribe("/republished/bb2/triclops/left/image_raw", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[0], globalArrayForSingleImages[0]));  
    image_transport::Subscriber subRight = it.subscribe("/republished/bb2/triclops/right/image_raw", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[1], globalArrayForSingleImages[1]));
    image_transport::Subscriber subKinect = it.subscribe("/republished/usb_cam/image_raw/", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[2], globalArrayForSingleImages[2]));
    image_transport::Subscriber subKinectDepth = it.subscribe("/republished/usb_cam/image_raw//republished/bb2/triclops/left/image_raw", 2, boost::bind(imageCallbackWrapper, _1, globalArrayOfImagesForGrid[3], globalArrayForSingleImages[3]));

    g_timeout_add(1000 / 100, do_ros, NULL);

    gtk_main();

    if ( MY_FUNCTIONS_ENTRANCE_CONTROL ) { printf ("\033[01;33mExited from the main function normally.\033[01;37m\n" ); }
    return 0;
}

I try to get the images, but I got none. A simple receiver code, works fine with the Rosbag and one image, this code thosen't make the connections, can any one help me with this problem. pls.

Rodrigo

edit retag flag offensive close merge delete

Comments

Sorry my mistake, I forgot to show do_ros function.

gboolean do_ros ( gpointer data ) {

// Showing the main window, with the attached image.
if ( GTK_IS_WIDGET (globalTopLevelWindow) )
{

    gtk_widget_show_all ( globalTopLevelWindow );       

}

if (ros::ok())
{

    ros::spinOnce();
Rodrigo Lourenço gravatar image Rodrigo Lourenço  ( 2016-08-19 08:40:13 -0500 )edit

can you put some std::cout just before ros::spinOnce() to confirm that it gets called?

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2016-08-19 08:58:07 -0500 )edit

I also find the names of the topics you subscribe to rather strange. run rostopic list and check whether it outputs those same topic name exactly (slashes matter).

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2016-08-19 09:01:41 -0500 )edit

Also check whether there is some data on those topics. rostopic echo --noarr /republished/usb_cam/image_raw//republished/bb2/triclops/left/image_raw

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2016-08-19 09:02:32 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2016-09-09 18:55:08 -0500

Rodrigo Lourenço gravatar image

After changing from virtual machine to PC, the problem was solved.

The program runs as it should.

edit flag offensive delete link more
0

answered 2016-08-19 07:23:53 -0500

Dimitri Schachmann gravatar image

updated 2016-08-19 07:25:06 -0500

The problem is, that you never call ros::spin or ros::spinOnce.

Try replacinggtk_main(); with

auto t = std::thread([&]() {
    ros::spin();
});

gtk_main();

// clean up the thread
if (t.joinable()) {
    t.join();
}

That's needs at least c++11, otherwise you need to figure some other syntax for running ros::spin() in it's own thread.

Basically gtk and ros both need a dedicated thread to loop and process events. Pay attention on racing conditions between the two threads!

edit flag offensive delete link more

Comments

Right now I'm changing the system to Indigo, later I was using a virtual machine in windows. About your quetions, one of my node paths, was wrong, corrected. Second I tried to use printf or cout, but never got anything on the screen, compiling in Indigo and testing again. Later I will see the rest.

Rodrigo Lourenço gravatar image Rodrigo Lourenço  ( 2016-08-19 08:36:32 -0500 )edit

To see printf or cout output, you need to add output="screen" to your node tag in your launch file. What I do instead is just use ROS_ERROR_STREAM("This is debug text. Value of foo is " << foo);

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2016-08-24 05:34:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-08-19 05:02:17 -0500

Seen: 104 times

Last updated: Sep 09 '16