Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional optical frame id to camera sensors #259

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ set(IGN_MSGS_VER ${ignition-msgs8_VERSION_MAJOR})

#--------------------------------------
# Find SDFormat
ign_find_package(sdformat12 REQUIRED VERSION 12.5.0)
ign_find_package(sdformat12 REQUIRED VERSION 12.6.0)
set(SDF_VER ${sdformat12_VERSION_MAJOR})

set(IGN_SENSORS_PLUGIN_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
Expand Down
20 changes: 16 additions & 4 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class ignition::sensors::CameraSensorPrivate
/// \brief Camera information message.
public: msgs::CameraInfo infoMsg;

/// \brief The frame this camera uses in its camera_info topic.
public: std::string opticalFrameId{""};

/// \brief Topic for info message.
public: std::string infoTopic{""};

Expand Down Expand Up @@ -462,7 +465,7 @@ bool CameraSensor::Update(const std::chrono::steady_clock::duration &_now)
*msg.mutable_header()->mutable_stamp() = msgs::Convert(_now);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->FrameId());
frame->add_value(this->dataPtr->opticalFrameId);
msg.set_data(data, this->dataPtr->camera->ImageMemorySize());
}

Expand Down Expand Up @@ -676,11 +679,20 @@ void CameraSensor::PopulateInfo(const sdf::Camera *_cameraSdf)

// Note: while Gazebo interprets the camera frame to be looking towards +X,
// other tools, such as ROS, may interpret this frame as looking towards +Z.
// TODO(anyone) Expose the `frame_id` as an SDF parameter so downstream users
// can populate it with arbitrary frames.
// To make this configurable the user has the option to set an optical frame.
// If the user has set <optical_frame_id> in the cameraSdf use it,
// otherwise fall back to the sensor frame.
if (_cameraSdf->OpticalFrameId().empty())
{
this->dataPtr->opticalFrameId = this->FrameId();
}
else
{
this->dataPtr->opticalFrameId = _cameraSdf->OpticalFrameId();
}
auto infoFrame = this->dataPtr->infoMsg.mutable_header()->add_data();
infoFrame->set_key("frame_id");
infoFrame->add_value(this->FrameId());
infoFrame->add_value(this->dataPtr->opticalFrameId);

this->dataPtr->infoMsg.set_width(width);
this->dataPtr->infoMsg.set_height(height);
Expand Down
23 changes: 20 additions & 3 deletions src/RgbdCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class ignition::sensors::RgbdCameraSensorPrivate
/// point cloud.
public: unsigned int channels = 4;

/// \brief Frame ID the camera_info message header is expressed.
public: std::string opticalFrameId{""};

/// \brief Pointer to an image to be published
public: ignition::rendering::Image image;

Expand Down Expand Up @@ -258,7 +261,7 @@ bool RgbdCameraSensor::Load(const sdf::Sensor &_sdf)
// the xyz and rgb fields to be aligned to memory boundaries. This is need
// by ROS1: https://github.com/ros/common_msgs/pull/77. Ideally, memory
// alignment should be configured.
msgs::InitPointCloudPacked(this->dataPtr->pointMsg, this->Name(), true,
msgs::InitPointCloudPacked(this->dataPtr->pointMsg, this->FrameId(), true,
{{"xyz", msgs::PointCloudPacked::Field::FLOAT32},
{"rgb", msgs::PointCloudPacked::Field::FLOAT32}});

Expand Down Expand Up @@ -299,6 +302,20 @@ bool RgbdCameraSensor::CreateCameras()
this->dataPtr->depthCamera->SetNearClipPlane(cameraSdf->NearClip());
this->dataPtr->depthCamera->SetFarClipPlane(cameraSdf->FarClip());

// Note: while Gazebo interprets the camera frame to be looking towards +X,
// other tools, such as ROS, may interpret this frame as looking towards +Z.
// To make this configurable the user has the option to set an optical frame.
// If the user has set <optical_frame_id> in the cameraSdf use it,
// otherwise fall back to the sensor frame.
if (cameraSdf->OpticalFrameId().empty())
{
this->dataPtr->opticalFrameId = this->FrameId();
}
else
{
this->dataPtr->opticalFrameId = cameraSdf->OpticalFrameId();
}

// Depth camera clip params are new and only override the camera clip
// params if specified.
if (cameraSdf->HasDepthCamera())
Expand Down Expand Up @@ -477,7 +494,7 @@ bool RgbdCameraSensor::Update(const std::chrono::steady_clock::duration &_now)
*msg.mutable_header()->mutable_stamp() = msgs::Convert(_now);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->FrameId());
frame->add_value(this->dataPtr->opticalFrameId);

std::lock_guard<std::mutex> lock(this->dataPtr->mutex);

Expand Down Expand Up @@ -589,7 +606,7 @@ bool RgbdCameraSensor::Update(const std::chrono::steady_clock::duration &_now)
*msg.mutable_header()->mutable_stamp() = msgs::Convert(_now);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->FrameId());
frame->add_value(this->dataPtr->opticalFrameId);
msg.set_data(data, rendering::PixelUtil::MemorySize(rendering::PF_R8G8B8,
width, height));

Expand Down