Ask Your Question
0

changing the frequency of loop

asked 2018-09-23 05:20:31 -0500

Sufyan gravatar image

following is the snipet of my code i want to change the frequency with which the image is pubished i tried changing the loop_rate(10) to loop_rate(1) but it didn't work

    ros::Rate loop_rate(10);
    int counter =0;
       while(ros::ok() ){
    counter++;
        #if 1
            ros::Time time = ros::Time::now();
            cv_ptr->encoding = "bgr8";
            cv_ptr->header.stamp = time;

cv_ptr->header.frame_id = "/Sufyan_ImageTopic";
        #endif

            cv_ptr->image = image;
            image_pub_.publish(cv_ptr->toImageMsg());

            ROS_INFO("ImageMsg Send.");
        #endif

        }   

    ros::spin();
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-09-23 06:45:37 -0500

hamid gravatar image

updated 2018-09-23 06:48:00 -0500

Hi you must to use loop_rate.sleep() in the end of while to control your loop rate

           while(ros::ok() ){
               counter++;
#if 1
                ros::Time time = ros::Time::now();
                cv_ptr->encoding = "bgr8";
                cv_ptr->header.stamp = time;

               cv_ptr->header.frame_id = "/Sufyan_ImageTopic";
 #endif

                cv_ptr->image = image;
                image_pub_.publish(cv_ptr->toImageMsg());

                ROS_INFO("ImageMsg Send.");
#endif
                loop_rate.sleep();
            }
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2018-09-23 05:20:31 -0500

Seen: 32 times

Last updated: Sep 23 '18