ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Cant publish a time object

asked 2018-04-27 07:17:45 -0500

aks gravatar image

updated 2018-04-27 08:37:13 -0500

I am trying to publish the current wallclock time but some how during the build process it always gives an error : Const Class ros::Time does not have any member named getMD5su

Here is the code :

#include "ros/xmlrpc_manager.h"  
#include  "std_msgs/Float32.h"  
#include "std_msgs/String.h"  
#include "std_msgs/Time.h"  
#include "ros/time.h"
#include "time.h"  
#include "sstream"           
using namespace std;
int main(int argc, char **argv){

ros::init(argc, argv, "talker");

ros::NodeHandle n;

ros::Publisher sum_publisher = n.advertise<std_msgs::Time>("sum", 1000);


ros::Rate loop_rate(1);
int a = 0;
int count = 0;
while (ros::ok()){

            std_msgs::Time msg;

   = ros::Time::now();





return 0;


I guess i should be advertising std_msgs::Time instead of ros::Time but it is not getting resolved. I already have included ros/time.h

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-04-27 07:57:31 -0500

updated 2018-04-27 08:24:14 -0500

Did you tried including #include <std_msgs/Time.h> ?

Also, dont mix ros::Time which is a class to represent Time in a ROS context and std_msgs::Time Which is a Time message that you can publish/subscribe.

Edit : Small example :

#include <ros/ros.h>
#include <ros/time.h>
#include <std_msgs/Time.h>

int main(int argc, char **argv)
  ros::init(argc, argv, "time_publisher");
  ros::NodeHandle nh;
  std_msgs::Time msg;
  ros::Publisher time_publisher = nh.advertise<std_msgs::Time>("time", 1000);

  while (ros::ok()){ = ros::Time::now();
    time_publisher .publish(msg);
edit flag offensive delete link more


after your comment i tried including #include<std_msgs/Time.h but it is not at all resolving std_msgs::Time So basically you mean I need to use std_msgs::Time to publish time messages using the class ros::Time ?

aks gravatar image aks  ( 2018-04-27 08:07:56 -0500 )edit

Yes and no, I edited my answer with a small code to explain better : You need to publish a std_msgs/Time message. But you need to use ros::Time to get the time value.

lmathieu gravatar image lmathieu  ( 2018-04-27 08:26:58 -0500 )edit

I have edited the question and pasted my complete code, it is almost the same what you suggested, but still not getting resolved.

aks gravatar image aks  ( 2018-04-27 08:38:12 -0500 )edit

Sorry, i wasnt saving my file thats why the resolution wasnt getting updated. Dumb mistake. Thanks

aks gravatar image aks  ( 2018-04-27 08:45:24 -0500 )edit

@Imathieu Could I anyhow multiply and integer or a float with time ?

aks gravatar image aks  ( 2018-04-27 08:45:59 -0500 )edit

If this works now, that great :) you can do arithmetic time and duration : But with primitive, you can use Time::toSec() and Time::fromSec() (or toNsec and fromNsec), don't hesitate to ask a new questions

lmathieu gravatar image lmathieu  ( 2018-04-27 08:53:41 -0500 )edit

How can i print this time on the console ? If i use ROS_INFO("%d",, it always shows 0. and if i use ROS_INFO("%d", it gives me some garbage value. I guess that is because %d is for integers. Also, shouldnt it give the actual wall clock time ?

aks gravatar image aks  ( 2018-04-27 09:49:11 -0500 )edit

for the second part of my question : multipying with time, i meant q289766

aks gravatar image aks  ( 2018-04-27 10:04:00 -0500 )edit

Question Tools



Asked: 2018-04-27 07:17:45 -0500

Seen: 524 times

Last updated: Apr 27 '18