0
$\begingroup$

Rosanswers logo

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();

Originally posted by Sufyan on ROS Answers with karma: 17 on 2018-09-23

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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();
            }

Originally posted by Hamid Didari with karma: 1769 on 2018-09-23

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.