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

Conversion into ROS compatible timestamp

asked 2011-10-27 05:01:46 -0600

alfa_80 gravatar image

updated 2011-10-28 08:50:53 -0600

kwc gravatar image

I was following a tutorial on laser scanner. But then, there is time-related stuff that I need to modify so that the time is not considered taken real-time(as shown in tutorial, it uses

  • ros::Time scan_time = ros::Time::now();
  • scan.header.stamp = scan_time;

to realize it. Instead, I want to take time values from a dataset(logfile).

I've tried to do as the following:

for (int i = 0; i < num_row; i++)
{
    scan.header.stamp =  data_set[i][1];
}

but, it doesn't work..for the line "scan.header.stamp = data_set[i][1];", I receive the following error:

"no match for ‘operator=’ in ‘scan.sensor_msgs::LaserScan_<std::allocator<void>     >::header.std_msgs::Header_<std::allocator<void> >::stamp = (((std::vector<double,     std::allocator<double> >*)((PointCloud*)this)-
 >PointCloud::data_set.std::vector<_Tp, _Alloc>::operator[] [with _Tp =     std::vector<double, std::allocator<double> >, _Alloc = std::allocator<std::vector<double,     std::allocator<double> > >](((long unsigned int)i)))->std::vector<_Tp, 
 _Alloc>::operator[] [with _Tp = double, _Alloc = std::allocator<double>](1ul) / 1.0e+3)’"

I cannot see the culprit..

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2011-10-27 05:20:14 -0600

dornhege gravatar image

Check out the constructors in the ROS Time API.

You can either pass in a Time in seconds (as double) or the single components directly - both as unix timestamp.

What you need depends on the datatype of your data_set.

edit flag offensive delete link more

Comments

The time in my dataset is in milliseconds, that means I need to convert it to seconds, am I right that way? It is in int, I perhaps can just type-cast it to double..
alfa_80 gravatar image alfa_80  ( 2011-10-27 06:03:48 -0600 )edit
The two argument constructor takes seconds and nano seconds. That's likely the easiest way to use your number.
tfoote gravatar image tfoote  ( 2011-10-27 13:55:14 -0600 )edit
@tfoote: I've tried to use the one takes 2 constructor like this: "scan.header.stamp = ((data_set[z][1])/1000, (data_set[z][1])*pow(10,6)) ;", but then it says that "value computed is not used" on that line of code.
alfa_80 gravatar image alfa_80  ( 2011-10-27 15:42:13 -0600 )edit
It seems OK now, but is it true just to convert like that? I input those 2 "identical" arguments in s and ns? I have only one timestamp anyway in my dataset..
alfa_80 gravatar image alfa_80  ( 2011-10-27 15:55:52 -0600 )edit
got error: error: no match for ‘operator=’ in ‘scan.sensor_msgs::LaserScan_<std::allocator<void> >::header.std_msgs::Header_<std::allocator<void> >::stamp = (((void)(((std::vector<double, std::allocator<double> >*)((PointCloud*)this)->PointCloud::data_set.std::vector<_Tp, _Alloc>::operator[] [with _
alfa_80 gravatar image alfa_80  ( 2011-10-27 16:02:30 -0600 )edit
When using the the two argument constructor, the nsec parameter represents the microseconds component of time, ie. it is always smaller than 1e9, so if you want to pass 1.5 seconds, it would be: sec=1, nsec=5e8 (and not nsec=1.5e9).
Adolfo Rodriguez T gravatar image Adolfo Rodriguez T  ( 2011-10-27 19:37:36 -0600 )edit
Thanks a lot, it now works, the problem is because I don't pass the input argument to the the constructor of the object..
alfa_80 gravatar image alfa_80  ( 2011-10-28 01:53:50 -0600 )edit

Question Tools

Stats

Asked: 2011-10-27 05:01:46 -0600

Seen: 6,495 times

Last updated: Oct 27 '11