what is the max frequency for a ros::Publisher to publish message
hello,
I try to use a timer to trigger to publish a std_msg/Floot32 msg to test how much frequency that Publish could be. When the timer is set to 0.001
, i use
rostopic hz /pub
to test frequency, result is1000
;
when the timer is set to 0.0008
,
rostopic hz /pub
result is 1250
;
when the timer is set to 0.0005
,
rostopic hz /pub
result is only 1720
;
So I think the max frequency for a publisher is limited, The max frequency might be 1000 - 1500 hz
Update
my test code:
#include "ros/ros.h"
#include <std_msgs/Float32.h>
class myTimer{
public:
myTimer(){
pub = nh.advertise<std_msgs::Float32>("/pub",1000);
t1 = nh.createTimer(ros::Duration(0.0005),&myTimer::callback,this);
//t2 = nh.createTimer(ros::Duration(1),&myTimer::callback2,this);
}
~myTimer(){}
void callback(const ros::TimerEvent& ev){
static ros::Time start = ros::Time::now();
ROS_INFO("callback 1 triggered");
std_msgs::Float32 ii;
ii.data = 1000000.0000;
pub.publish(ii);
ros::Time end =ros::Time::now();
ROS_INFO("___%f",(end.toSec() - start.toSec()));
start = end;
}
void callback2(const ros::TimerEvent& ev){
ROS_INFO("++1 s callback trigered! ");
}
private:
ros::NodeHandle nh;
ros::Publisher pub;
ros::Timer t1;
//ros::Timer t2;
};
int main(int argc, char *argv[])
{
ros::init(argc,argv,"myTimer_class");
//ros::Time begin = ros::Time::now();
myTimer mt;
ros::spin();
return 0;
}