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

Visualze Frustum #491

Open
wants to merge 2 commits into
base: gz-sensors9
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions include/gz/sensors/LogicalCameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ namespace gz
/// \return True if there are subscribers, false otherwise
public: virtual bool HasConnections() const override;

/// \brief Check if there are any image subscribers
/// \return True if there are image subscribers, false otherwise
public: virtual bool HasImageConnections() const;

/// \brief Check if there are any frustum subscribers
/// \return True if there are info subscribers, false otherwise
public: virtual bool HasFrustumConnections() const;

/// \brief Get the latest image. An image is an instance of
/// msgs::LogicalCameraImage, which contains a list of detected models.
/// \return List of detected models.
Expand Down
40 changes: 40 additions & 0 deletions src/LogicalCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ class gz::sensors::LogicalCameraSensorPrivate
/// \brief node to create publisher
public: transport::Node node;

public: transport::Node node_logic;

/// \brief publisher to publish logical camera messages.
public: transport::Node::Publisher pub;

public: transport::Node::Publisher pub_logic;

/// \brief true if Load() has been called and was successful
public: bool initialized = false;

Expand All @@ -56,6 +60,8 @@ class gz::sensors::LogicalCameraSensorPrivate

/// \brief Msg containg info on models detected by logical camera
msgs::LogicalCameraImage msg;

msgs::LogicalCameraSensor msg_logic;
};

//////////////////////////////////////////////////
Expand Down Expand Up @@ -110,12 +116,22 @@ bool LogicalCameraSensor::Load(sdf::ElementPtr _sdf)
this->dataPtr->node.Advertise<msgs::LogicalCameraImage>(
this->Topic());

this->dataPtr->pub_logic =
this->dataPtr->node_logic.Advertise<msgs::LogicalCameraSensor>(
this->Topic() + "/frustum");

if (!this->dataPtr->pub)
{
gzerr << "Unable to create publisher on topic[" << this->Topic() << "].\n";
return false;
}

if (!this->dataPtr->pub_logic)
{
gzerr << "Unable to create publisher on topic[" << this->Topic() << "].\n";
return false;
}

gzdbg << "Logical images for [" << this->Name() << "] advertised on ["
<< this->Topic() << "]" << std::endl;

Expand Down Expand Up @@ -166,9 +182,22 @@ bool LogicalCameraSensor::Update(
frame->set_key("frame_id");
frame->add_value(this->FrameId());

*this->dataPtr->msg_logic.mutable_header()->mutable_stamp() = msgs::Convert(_now);
this->dataPtr->msg_logic.mutable_header()->clear_data();
auto frame_log = this->dataPtr->msg_logic.mutable_header()->add_data();

frame_log->set_key("frame_id");
frame_log->add_value(this->FrameId());

// publish
this->dataPtr->msg_logic.set_near_clip(this->dataPtr->frustum.Near());
this->dataPtr->msg_logic.set_far_clip(this->dataPtr->frustum.Far());
this->dataPtr->msg_logic.set_horizontal_fov(this->dataPtr->frustum.FOV().Radian());
this->dataPtr->msg_logic.set_aspect_ratio(this->dataPtr->frustum.AspectRatio());
this->AddSequence(this->dataPtr->msg.mutable_header());

this->dataPtr->pub.Publish(this->dataPtr->msg);
this->dataPtr->pub_logic.Publish(this->dataPtr->msg_logic);

return true;
}
Expand Down Expand Up @@ -206,7 +235,18 @@ msgs::LogicalCameraImage LogicalCameraSensor::Image() const

//////////////////////////////////////////////////
bool LogicalCameraSensor::HasConnections() const
{
return this->HasImageConnections() || this->HasFrustumConnections();
}

//////////////////////////////////////////////////
bool LogicalCameraSensor::HasImageConnections() const
{
return this->dataPtr->pub && this->dataPtr->pub.HasConnections();
}

//////////////////////////////////////////////////
bool LogicalCameraSensor::HasFrustumConnections() const
{
return this->dataPtr->pub_logic && this->dataPtr->pub_logic.HasConnections();
}
Loading