Skip to content

Commit 19f7bd1

Browse files
committed
Visualize Frustum: logical camera publisher
1 parent aaef365 commit 19f7bd1

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

include/gz/sensors/Sensor.hh

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ namespace gz
161161
/// \return Topic sensor publishes data to
162162
public: std::string Topic() const;
163163

164+
/// \brief Get topic where sensor data is published.
165+
/// \return Topic sensor publishes data to
166+
public: std::string Topic_logic() const;
167+
164168
/// \brief Set topic where sensor data is published.
165169
/// \param[in] _topic Topic sensor publishes data to.
166170
/// \return True if a valid topic was set.

src/LogicalCameraSensor.cc

+31-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ class gz::sensors::LogicalCameraSensorPrivate
3636
/// \brief node to create publisher
3737
public: transport::Node node;
3838

39+
public: transport::Node node_logic;
40+
3941
/// \brief publisher to publish logical camera messages.
4042
public: transport::Node::Publisher pub;
4143

44+
public: transport::Node::Publisher pub_logic;
45+
4246
/// \brief true if Load() has been called and was successful
4347
public: bool initialized = false;
4448

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

5761
/// \brief Msg containg info on models detected by logical camera
5862
msgs::LogicalCameraImage msg;
63+
64+
msgs::LogicalCameraSensor msg_logic;
5965
};
6066

6167
//////////////////////////////////////////////////
@@ -104,18 +110,28 @@ bool LogicalCameraSensor::Load(sdf::ElementPtr _sdf)
104110
return false;
105111

106112
if (this->Topic().empty())
107-
this->SetTopic("/logical_camera");
113+
this->SetTopic("/camera/logical");
108114

109115
this->dataPtr->pub =
110116
this->dataPtr->node.Advertise<msgs::LogicalCameraImage>(
111117
this->Topic());
112118

119+
this->dataPtr->pub_logic =
120+
this->dataPtr->node_logic.Advertise<msgs::LogicalCameraSensor>(
121+
this->Topic() + "/frustum");
122+
113123
if (!this->dataPtr->pub)
114124
{
115125
gzerr << "Unable to create publisher on topic[" << this->Topic() << "].\n";
116126
return false;
117127
}
118128

129+
if (!this->dataPtr->pub_logic)
130+
{
131+
gzerr << "Unable to create publisher on topic[" << this->Topic() << "].\n";
132+
return false;
133+
}
134+
119135
gzdbg << "Logical images for [" << this->Name() << "] advertised on ["
120136
<< this->Topic() << "]" << std::endl;
121137

@@ -166,9 +182,22 @@ bool LogicalCameraSensor::Update(
166182
frame->set_key("frame_id");
167183
frame->add_value(this->FrameId());
168184

185+
*this->dataPtr->msg_logic.mutable_header()->mutable_stamp() = msgs::Convert(_now);
186+
this->dataPtr->msg_logic.mutable_header()->clear_data();
187+
auto frame_log = this->dataPtr->msg_logic.mutable_header()->add_data();
188+
189+
frame_log->set_key("frame_id");
190+
frame_log->add_value(this->FrameId());
191+
169192
// publish
193+
this->dataPtr->msg_logic.set_near_clip(this->dataPtr->frustum.Near());
194+
this->dataPtr->msg_logic.set_far_clip(this->dataPtr->frustum.Far());
195+
this->dataPtr->msg_logic.set_horizontal_fov(this->dataPtr->frustum.FOV().Radian());
196+
this->dataPtr->msg_logic.set_aspect_ratio(this->dataPtr->frustum.AspectRatio());
170197
this->AddSequence(this->dataPtr->msg.mutable_header());
198+
171199
this->dataPtr->pub.Publish(this->dataPtr->msg);
200+
this->dataPtr->pub_logic.Publish(this->dataPtr->msg_logic);
172201

173202
return true;
174203
}
@@ -207,6 +236,6 @@ msgs::LogicalCameraImage LogicalCameraSensor::Image() const
207236
//////////////////////////////////////////////////
208237
bool LogicalCameraSensor::HasConnections() const
209238
{
210-
return this->dataPtr->pub && this->dataPtr->pub.HasConnections();
239+
return this->dataPtr->pub_logic && this->dataPtr->pub_logic.HasConnections();
211240
}
212241

0 commit comments

Comments
 (0)