Why is header.stamp truncated as a C++ class member?

asked 2017-12-05 20:29:21 -0500

M@t gravatar image

updated 2017-12-07 16:27:17 -0500

I want to store pointers to various ROS sensor messages inside a C++ class, E.g.

class MetaData {
  public:
    sensor_msgs::NavSatFix::Ptr navsat;
    // some other variables I want to associate with this NavSatFix
}

However, when I then go to print the header stamp on the NavSatFix message, it's type changes and it gets truncated. So that the following code:

// Original message
cout << "Stamp " << msgPtr->header.stamp << " is of type: " 
     << typeid(msgPtr->header.stamp).name() << endl;

// Same message but now called from inside a class as a member variable.
MetaData myMetaData;
myMetaData.navsat = msgPtr 
cout << "Stamp " << myMetaData.navsat->header.stamp 
     << " is of type: " << typeid(myMetaData.navsat->header.stamp).name() << endl;

Returns:

Stamp 1505942380.370968000 is of type N3ros4TimeE
Stamp 1505942380370968 is of type m

So my questions are:

  1. Why has the type changed from ros::Time (I assume that's what "N3ros4TimeE" stands for) to m? (for "member variable" I think)
  2. Why has cout then truncated one but not the other? (using std::setprecision() has no effect)
  3. What syntax should I use to get the full header stamp when outputting the stamp from the class member?
  4. Will the answer to 1 likely affect variables in other ROS messages? (I'm not at the stage where I can test this for myself)

Thanks in advance for any help or advice. If this questions is more relevant to general C++ than ROS, let me know and I will shift it to StackOverflow.

edit retag flag offensive close merge delete

Comments

1

The standard seems non-specific on the implementation of std::type_info::name() : http://en.cppreference.com/w/cpp/type... .

ahendrix gravatar imageahendrix ( 2017-12-05 21:08:47 -0500 )edit