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

Conform to ros format for header field frame_id of sensor msgs #195

Merged
merged 6 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions include/ignition/sensors/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ namespace ignition
/// \return Name of sensor.
public: std::string Name() const;

/// \brief FrameID.
/// \return FrameID of sensor.
public: std::string FrameID() const;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Get topic where sensor data is published.
/// \return Topic sensor publishes data to
public: std::string Topic() const;
Expand Down
2 changes: 1 addition & 1 deletion src/AirPressureSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ bool AirPressureSensor::Update(const ignition::common::Time &_now)
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

// This block of code comes from RotorS:
// https://github.com/ethz-asl/rotors_simulator/blob/master/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/AltimeterSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool AltimeterSensor::Update(const ignition::common::Time &_now)
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

// Apply altimeter vertical position noise
if (this->dataPtr->noises.find(ALTIMETER_VERTICAL_POSITION_NOISE_METERS) !=
Expand Down
4 changes: 2 additions & 2 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ bool CameraSensor::Update(const ignition::common::Time &_now)
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());
msg.set_data(data, this->dataPtr->camera->ImageMemorySize());
}

Expand Down Expand Up @@ -606,7 +606,7 @@ void CameraSensor::PopulateInfo(const sdf::Camera *_cameraSdf)
// can populate it with arbitrary frames.
auto infoFrame = this->dataPtr->infoMsg.mutable_header()->add_data();
infoFrame->set_key("frame_id");
infoFrame->add_value(this->Name());
infoFrame->add_value(this->FrameID());

this->dataPtr->infoMsg.set_width(width);
this->dataPtr->infoMsg.set_height(height);
Expand Down
2 changes: 1 addition & 1 deletion src/DepthCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ bool DepthCameraSensor::Update(const ignition::common::Time &_now)
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
msg.set_data(this->dataPtr->depthBuffer,
Expand Down
2 changes: 1 addition & 1 deletion src/ImuSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ bool ImuSensor::Update(const ignition::common::Time &_now)
msg.set_entity_name(this->Name());
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

msgs::Set(msg.mutable_orientation(), this->dataPtr->orientation);
msgs::Set(msg.mutable_angular_velocity(), this->dataPtr->angularVel);
Expand Down
5 changes: 4 additions & 1 deletion src/Lidar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ bool Lidar::PublishLidarScan(const ignition::common::Time &_now)
this->dataPtr->laserMsg.mutable_header()->clear_data();
auto frame = this->dataPtr->laserMsg.mutable_header()->add_data();
frame->set_key("frame_id");
// keeping here the sensor name instead of frame_id because the visualizeLidar
// plugin relies on this value to get the position of the lidar.
// the ros_ign plugin is using the laserscan.proto 'frame' field
frame->add_value(this->Name());
this->dataPtr->laserMsg.set_frame(this->Name());
this->dataPtr->laserMsg.set_frame(this->FrameID());

// Store the latest laser scans into laserMsg
msgs::Set(this->dataPtr->laserMsg.mutable_world_pose(),
Expand Down
2 changes: 1 addition & 1 deletion src/LogicalCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool LogicalCameraSensor::Update(const ignition::common::Time &_now)
this->dataPtr->msg.mutable_header()->clear_data();
auto frame = this->dataPtr->msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

// publish
this->AddSequence(this->dataPtr->msg.mutable_header());
Expand Down
2 changes: 1 addition & 1 deletion src/MagnetometerSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ bool MagnetometerSensor::Update(const ignition::common::Time &_now)
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

// Apply magnetometer noise after converting to body frame
if (this->dataPtr->noises.find(MAGNETOMETER_X_NOISE_TESLA) !=
Expand Down
4 changes: 2 additions & 2 deletions src/RgbdCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ bool RgbdCameraSensor::Update(const ignition::common::Time &_now)
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

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

Expand Down Expand Up @@ -583,7 +583,7 @@ bool RgbdCameraSensor::Update(const ignition::common::Time &_now)
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());
msg.set_data(data, rendering::PixelUtil::MemorySize(rendering::PF_R8G8B8,
width, height));

Expand Down
21 changes: 21 additions & 0 deletions src/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class ignition::sensors::SensorPrivate
/// A map is used so that a single sensor can have multiple sensor
/// streams each with a sequence counter.
public: std::map<std::string, uint64_t> sequences;

/// \brief frame id
public: std::string frame_id;
};

SensorId SensorPrivate::idCounter = 0;
Expand Down Expand Up @@ -121,6 +124,19 @@ bool SensorPrivate::PopulateFromSDF(const sdf::Sensor &_sdf)
return false;
}

sdf::ElementPtr element = _sdf.Element();
if (element)
{
if (element->HasElement("ignition:frame_id"))
{
this->frame_id = element->Get<std::string>("ignition:frame_id");
}
else
{
this->frame_id = this->name;
}
}

// Try resolving the pose first, and only use the raw pose if that fails
auto semPose = _sdf.SemanticPose();
sdf::Errors errors = semPose.Resolve(this->pose);
Expand Down Expand Up @@ -192,6 +208,11 @@ std::string Sensor::Name() const
return this->dataPtr->name;
}

//////////////////////////////////////////////////
std::string Sensor::FrameID() const
{
return this->dataPtr->frame_id;
}
//////////////////////////////////////////////////
std::string Sensor::Topic() const
{
Expand Down
2 changes: 1 addition & 1 deletion src/ThermalCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ bool ThermalCameraSensor::Update(const ignition::common::Time &_now)
stamp->set_nsec(_now.nsec);
auto frame = this->dataPtr->thermalMsg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
frame->add_value(this->FrameID());

std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
this->dataPtr->thermalMsg.set_data(this->dataPtr->thermalBuffer,
Expand Down