How can I post the time that has passed during a process?
I would like to know how much time has gone by while performing a certain process. As an example I have used the Publisher/Subscriber tutorial code from ros.org with some minor modifications. Basically, I want to know the time that has passed since the beginning of the code until the end of it. I understand why this code doesn't work but I posted it anyway so you can get the idea of what I want.
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "geometry_msgs/Vector3.h"
#include <sstream>
geometry_msgs::Vector3 valorFloat;
int valor = 1;
double start_time, finish_time, delta_t;
int main(int argc, char **argv)
{
double tiempo_actual;
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
ros::Publisher mensaje = n.advertise<geometry_msgs::Vector3>("/ValorFloat",50);
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok())
{
current_time=(double)ros::Time::now().toSec();
start_time = current_time; //Save current time as t1
std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
valorFloat.x=valor;
valorFloat.y=valor+1;
valorFloat.z=valor+2;
chatter_pub.publish(msg);
mensaje.publish(valorFloat);
ros::spinOnce();
loop_rate.sleep();
++count;
finish_time=current_time; //Save current time as t2
delta_t=finish_time-start_time;
printf("Delta t: %f \n",delta_t);
}
return 0;
}