Skip to content

Commit

Permalink
Keep compatibility with earlier Gazebo version
Browse files Browse the repository at this point in the history
  • Loading branch information
awesome-manuel committed Jan 9, 2020
1 parent 6d931c8 commit 1ede6e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/RealSensePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ void RealSensePlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)

// Setup Transport Node
this->transportNode = transport::NodePtr(new transport::Node());
#if GAZEBO_MAJOR_VERSION >= 9
this->transportNode->Init(this->world->Name());
#else
this->transportNode->Init(this->world->GetName());
#endif

// Setup Publishers
std::string rsTopicRoot =
Expand Down Expand Up @@ -166,7 +170,11 @@ void RealSensePlugin::OnNewFrame(const rendering::CameraPtr cam,
msgs::ImageStamped msg;

// Set Simulation Time
#if GAZEBO_MAJOR_VERSION >= 9
msgs::Set(msg.mutable_time(), this->world->SimTime());
#else
msgs::Set(msg.mutable_time(), this->world->GetSimTime());
#endif

// Set Image Dimensions
msg.mutable_image()->set_width(cam->ImageWidth());
Expand Down Expand Up @@ -215,7 +223,11 @@ void RealSensePlugin::OnNewDepthFrame()
}

// Pack realsense scaled depth map
#if GAZEBO_MAJOR_VERSION >= 9
msgs::Set(msg.mutable_time(), this->world->SimTime());
#else
msgs::Set(msg.mutable_time(), this->world->GetSimTime());
#endif
msg.mutable_image()->set_width(this->depthCam->ImageWidth());
msg.mutable_image()->set_height(this->depthCam->ImageHeight());
msg.mutable_image()->set_pixel_format(common::Image::L_INT16);
Expand Down
8 changes: 8 additions & 0 deletions src/gazebo_ros_realsense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ void GazeboRosRealsense::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
void GazeboRosRealsense::OnNewFrame(const rendering::CameraPtr cam,
const transport::PublisherPtr pub)
{
#if GAZEBO_MAJOR_VERSION >= 9
common::Time current_time = this->world->SimTime();
#else
common::Time current_time = this->world->GetSimTime();
#endif

// identify camera
std::string camera_id = extractCameraName(cam->Name());
Expand Down Expand Up @@ -96,7 +100,11 @@ void GazeboRosRealsense::OnNewFrame(const rendering::CameraPtr cam,
void GazeboRosRealsense::OnNewDepthFrame()
{
// get current time
#if GAZEBO_MAJOR_VERSION >= 9
common::Time current_time = this->world->SimTime();
#else
common::Time current_time = this->world->GetSimTime();
#endif

RealSensePlugin::OnNewDepthFrame();

Expand Down

0 comments on commit 1ede6e3

Please sign in to comment.