How to create a ros::MessageEvent object

asked 2020-11-16 09:48:01 -0500

Malkecero gravatar image

updated 2020-11-16 09:49:56 -0500

Hi,

I want to test a method which is called after a callback, receiving as argument a ros::MessageEvent<std_msgs::float32> variable. I looked at the documentation here, but couldn't see a clear way to create such object.

Based on my callback function:

void NodeSubscriber::topicCallback(const ros::MessageEvent<std_msgs::Float32 const>& message)
{
  nodeObject_.updateObjectData(message);
}

and following the public method of the class MessageEvent:

MessageEvent (const ConstMessagePtr &message, ros::Time receipt_time);

I tried something along the lines of:

double value = 1.5;
ros::Time timestamp(5);
ros::MessageEvent<std_msgs::Float32> message(value, timestamp);

without success.

What am I missing here ?

Thanks for your help.

edit retag flag offensive close merge delete

Comments

Just a note: a MessagEvent != a message. It's more than that.

I know, this is semantics (ie: naming), but important.

Could you clarify why you pass the MessageEvent itself, and not the Float32?

gvdhoorn gravatar image gvdhoorn  ( 2020-11-16 10:55:32 -0500 )edit

The topic I'm listening doesn't have an header with a timestamp. I do need to have an approximate idea of when the message is published. I am aware that with MessageEvent I'll be getting a timestamp when the node received the message and not when it was published.

Malkecero gravatar image Malkecero  ( 2020-11-22 03:20:10 -0500 )edit