Home | Tutorials | Wiki | Issues
Ask Your Question

How to get msgs::LogicalCameraImage timestamp?

asked 2018-06-22 09:05:36 -0600

federico.nardi gravatar image

Hi all,

I wrote an urdf for a diff-drive robot with a logical camera sensor.

To publish its messages over ROS I wrote a simple plugin:

#include "logical_camera_plugin.h"

using namespace gazebo;
using namespace std;
using namespace ros;


void LogicalCameraPlugin::Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf){
  // Get the parent sensor.
  this->parentSensor = std::dynamic_pointer_cast<sensors::LogicalCameraSensor>(_sensor);

  // Make sure the parent sensor is valid.
  if (!this->parentSensor){
    gzerr << "LogicalCameraPlugin requires a LogicalCameraSensor.\n";

  // Connect to the sensor update event.
  this->updateConnection = this->parentSensor->ConnectUpdated(std::bind(&LogicalCameraPlugin::OnUpdate, this));

  // Make sure the parent sensor is active.


  nh = new ros::NodeHandle("~");
  image_pub = nh->advertise<lucrezio_simulation_environments::LogicalImage>("logical_camera_image", 1, true);

void LogicalCameraPlugin::OnUpdate(){
  msgs::LogicalCameraImage logical_image;
  lucrezio_simulation_environments::LogicalImage msg;

  logical_image = this->parentSensor->Image();
  gazebo::rendering::ScenePtr scene = gazebo::rendering::get_scene();
  if (!scene || !scene->Initialized())

  msg.header.stamp = ros::Time::now();
  msg.header.frame_id = "logical_camera_link";



My only concern was:

Is it possible to get from the msgs::LogicalCameraImage a timestamp?

Because, right now, I'm giving ros::Time::now() to the ROS message and I guess this is not the right solution.


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-06-22 09:46:18 -0600

updated 2018-06-22 10:19:11 -0600

That LogicalCameraImage message is not stamped (i.e. it doesn't have a header), so I think it's not possible to know the exact time from the message itself.

I think you're doing the right thing by connecting to the ConnectUpdated event. From that callback, I think you'll get the correct time for when the last image message was generated with:

auto lastUpdateTime = this->parentSensor->LastUpdateTime();

edit flag offensive delete link more


the LogicalCameraPlugin is a `SensorPlugin`, I'm afraid I didn't get what you mean!

federico.nardi gravatar imagefederico.nardi ( 2018-06-22 10:01:55 -0600 )edit

Ah sorry, you're right, I woke up too early to watch football. Updating the answer.

chapulina gravatar imagechapulina ( 2018-06-22 10:11:09 -0600 )edit

Thanks, I'll try! "Come on Iceland"!!!!!

federico.nardi gravatar imagefederico.nardi ( 2018-06-22 10:27:47 -0600 )edit

It doesn't compile because lastUpdateTime is protected within that context

federico.nardi gravatar imagefederico.nardi ( 2018-06-22 10:30:54 -0600 )edit

my fault, LastUpdateTime should be called!

federico.nardi gravatar imagefederico.nardi ( 2018-06-22 10:35:55 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-06-22 09:05:36 -0600

Seen: 70 times

Last updated: Jun 22 '18