Skip to content

Commit 54ba448

Browse files
authored
Merge pull request gazebosim#437 from gazebosim/merge_8_main_20240528
Merge 8 -> main
2 parents bdb7e16 + 357ed54 commit 54ba448

20 files changed

+1013
-353
lines changed

.github/workflows/package_xml.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Validate package.xml
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
package-xml:
8+
runs-on: ubuntu-latest
9+
name: Validate package.xml
10+
steps:
11+
- uses: gazebo-tooling/action-gz-ci/validate_package_xml@jammy

Changelog.md

+35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@
44

55
## Gazebo Sensors 8
66

7+
### Gazebo Sensors 8.1.0 (2024-05-16)
8+
9+
1. Set camera projection matrix based on lens params for other types of cameras
10+
* [Pull request #432](https://github.com/gazebosim/gz-sensors/pull/432)
11+
12+
1. Move trigger logic to base Sensor class and enable trigger for all camera sensors
13+
* [Pull request #431](https://github.com/gazebosim/gz-sensors/pull/431)
14+
15+
1. Add package.xml
16+
* [Pull request #422](https://github.com/gazebosim/gz-sensors/pull/422)
17+
18+
### Gazebo Sensors 8.0.1 (2024-03-15)
19+
20+
1. Avoid calling DblNormal with invalid standard deviation
21+
* [Pull request #396](https://github.com/gazebosim/gz-sensors/pull/396)
22+
23+
1. DepthCamera and RGBDCamera - optimize RGB point cloud connection
24+
* [Pull request #413](https://github.com/gazebosim/gz-sensors/pull/413)
25+
26+
1. Update CI badges to point to release branch job
27+
* [Pull request #406](https://github.com/gazebosim/gz-sensors/pull/406)
28+
* [Pull request #405](https://github.com/gazebosim/gz-sensors/pull/405)
29+
30+
1. Infrastructure
31+
* [Pull request #401](https://github.com/gazebosim/gz-sensors/pull/401)
32+
33+
1. Clean up rendering resources
34+
* [Pull request #324](https://github.com/gazebosim/gz-sensors/pull/324)
35+
36+
1. Destroy rendering sensors when sensor is removed
37+
* [Pull request #169](https://github.com/gazebosim/gz-sensors/pull/169)
38+
39+
1. Support protobuf >= 22
40+
* [Pull request #351](https://github.com/gazebosim/gz-sensors/pull/351)
41+
742
### Gazebo Sensors 8.0.0 (2023-09-29)
843

944
1. Documentation fixes

include/gz/sensors/BoundingBoxCameraSensor.hh

-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ namespace gz
103103
/// \return True on success.
104104
private: bool CreateCamera();
105105

106-
/// \brief Callback for triggered subscription
107-
/// \param[in] _msg Boolean message
108-
private: void OnTrigger(const gz::msgs::Boolean &/*_msg*/);
109-
110106
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
111107
/// \brief Data pointer for private data
112108
/// \internal

include/gz/sensors/CameraSensor.hh

+11-4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ namespace gz
148148
/// \return The camera optical frame
149149
public: const std::string& OpticalFrameId() const;
150150

151+
/// \brief Set camera lens intrinsics and projection based on
152+
/// values from SDF. If the camera SDF does not contain intrinsic or
153+
/// projection parameters, the camera will not be updated. Instead, the
154+
/// camera SDF will be updated with intrinsic and projection values
155+
/// computed manually from current camera intrinsic properties.
156+
/// \param[in] _camera Camera to set intrinsic and projection params.
157+
/// \param[in,out] _cameraSdf Camera sdf with intrinisc and projection
158+
/// parameters.
159+
public: void UpdateLensIntrinsicsAndProjection(
160+
rendering::CameraPtr _camera, sdf::Camera &_cameraSdf);
161+
151162
/// \brief Advertise camera info topic.
152163
/// \return True if successful.
153164
protected: bool AdvertiseInfo();
@@ -178,10 +189,6 @@ namespace gz
178189
/// \param[in] _scene Pointer to the new scene.
179190
private: void OnSceneChange(gz::rendering::ScenePtr /*_scene*/);
180191

181-
/// \brief Callback for triggered subscription
182-
/// \param[in] _msg Boolean message
183-
private: void OnTrigger(const gz::msgs::Boolean &/*_msg*/);
184-
185192
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
186193
/// \brief Data pointer for private data
187194
/// \internal

include/gz/sensors/Sensor.hh

+24-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ namespace gz
113113
/// subclasses' Update() method will be called.
114114
/// \param[in] _now The current time
115115
/// \param[in] _force Force the update to happen even if it's not time
116-
/// \return True if the update was triggered (_force was true or _now
117-
/// >= next_update_time) and the sensor's
116+
/// \return True if the update was performed (_force was true or _now
117+
/// >= next_update_time or sensor had a pending trigger) and the sensor's
118118
/// bool Sensor::Update(std::chrono::steady_clock::time_point)
119119
/// function returned true.
120120
/// False otherwise.
@@ -231,6 +231,28 @@ namespace gz
231231
/// \return True if there are subscribers, false otherwise
232232
public: virtual bool HasConnections() const;
233233

234+
/// \brief Enable or disable triggered mode. In this mode,
235+
/// - the sensor will only update if a new message has been published to
236+
/// the passed _triggerTopic since the last update,
237+
/// - until the next message is published on _triggerTopic, all Update
238+
/// calls will return false, and
239+
/// - if the sensor has a pending trigger, the next Update call will
240+
/// ignore the sensor's update rate and try generate data immediately.
241+
/// \param[in] _triggered Sets triggered mode if true and disables it if
242+
/// false.
243+
/// \param[in] _triggerTopic The topic on which the sensor will listen
244+
/// for trigger messages in triggered mode. If _triggered is true, this
245+
/// value should not be empty. If _triggered is false, this value is
246+
/// ignored.
247+
/// \return True if the operation succeeded.
248+
public: bool SetTriggered(bool _triggered,
249+
const std::string &_triggerTopic = "");
250+
251+
/// \brief Whether the sensor has a pending trigger.
252+
/// \return True if the sensor is in trigger mode and has a pending
253+
/// trigger.
254+
public: bool HasPendingTrigger() const;
255+
234256
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
235257
/// \internal
236258
/// \brief Data pointer for private data

package.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="2">
4+
<name>gz-sensors9</name>
5+
<version>9.0.0</version>
6+
<description>Gazebo Sensors : Sensor models for simulation</description>
7+
<maintainer email="[email protected]">Ian Chen</maintainer>
8+
<license>Apache License 2.0</license>
9+
<url type="website">https://github.com/gazebosim/gz-sensors</url>
10+
11+
<buildtool_depend>cmake</buildtool_depend>
12+
13+
<build_depend>gz-cmake4</build_depend>
14+
15+
<depend>gz-common6</depend>
16+
<depend>gz-math8</depend>
17+
<depend>gz-msgs11</depend>
18+
<depend>gz-rendering9</depend>
19+
<depend>gz-tools2</depend>
20+
<depend>gz-transport14</depend>
21+
<depend>sdformat15</depend>
22+
23+
<test_depend>xvfb</test_depend>
24+
25+
<export>
26+
<build_type>cmake</build_type>
27+
</export>
28+
</package>

src/BoundingBoxCameraSensor.cc

+16-56
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717

1818
#include <mutex>
19+
#include <ostream>
20+
#include <string>
1921

2022
#include <gz/msgs/boolean.pb.h>
2123
#include <gz/msgs/image.pb.h>
@@ -32,6 +34,7 @@
3234
#include <gz/rendering/BoundingBoxCamera.hh>
3335
#include <gz/transport/Node.hh>
3436
#include <gz/transport/Publisher.hh>
37+
#include <gz/transport/TopicUtils.hh>
3538

3639
#include "gz/sensors/BoundingBoxCameraSensor.hh"
3740
#include "gz/sensors/RenderingEvents.hh"
@@ -88,15 +91,6 @@ class gz::sensors::BoundingBoxCameraSensorPrivate
8891
/// \brief Just a mutex for thread safety
8992
public: std::mutex mutex;
9093

91-
/// \brief True if camera is triggered by a topic
92-
public: bool isTriggeredCamera{false};
93-
94-
/// \brief True if camera has been triggered by a topic
95-
public: bool isTriggered{false};
96-
97-
/// \brief Topic for camera trigger
98-
public: std::string triggerTopic{""};
99-
10094
/// \brief BoundingBoxes type
10195
public: rendering::BoundingBoxType type
10296
{rendering::BoundingBoxType::BBT_VISIBLEBOX2D};
@@ -231,30 +225,13 @@ bool BoundingBoxCameraSensor::Load(const sdf::Sensor &_sdf)
231225

232226
if (_sdf.CameraSensor()->Triggered())
233227
{
234-
if (!_sdf.CameraSensor()->TriggerTopic().empty())
235-
{
236-
this->dataPtr->triggerTopic = _sdf.CameraSensor()->TriggerTopic();
237-
}
238-
else
228+
std::string triggerTopic = _sdf.CameraSensor()->TriggerTopic();
229+
if (triggerTopic.empty())
239230
{
240-
this->dataPtr->triggerTopic =
241-
transport::TopicUtils::AsValidTopic(
242-
this->Topic() + "/trigger");
243-
244-
if (this->dataPtr->triggerTopic.empty())
245-
{
246-
gzerr << "Invalid trigger topic name [" <<
247-
this->dataPtr->triggerTopic << "]" << std::endl;
248-
return false;
249-
}
231+
triggerTopic = transport::TopicUtils::AsValidTopic(this->Topic() +
232+
"/trigger");
250233
}
251-
252-
this->dataPtr->node.Subscribe(this->dataPtr->triggerTopic,
253-
&BoundingBoxCameraSensor::OnTrigger, this);
254-
255-
gzdbg << "Camera trigger messages for [" << this->Name() << "] subscribed"
256-
<< " on [" << this->dataPtr->triggerTopic << "]" << std::endl;
257-
this->dataPtr->isTriggeredCamera = true;
234+
this->SetTriggered(true, triggerTopic);
258235
}
259236

260237
if (!this->AdvertiseInfo())
@@ -303,9 +280,6 @@ bool BoundingBoxCameraSensor::CreateCamera()
303280
return false;
304281
}
305282

306-
// Camera Info Msg
307-
this->PopulateInfo(sdfCamera);
308-
309283
if (!this->dataPtr->rgbCamera)
310284
{
311285
// Create rendering camera
@@ -356,6 +330,14 @@ bool BoundingBoxCameraSensor::CreateCamera()
356330
this->AddSensor(this->dataPtr->boundingboxCamera);
357331
this->AddSensor(this->dataPtr->rgbCamera);
358332

333+
this->UpdateLensIntrinsicsAndProjection(this->dataPtr->rgbCamera,
334+
*sdfCamera);
335+
this->UpdateLensIntrinsicsAndProjection(this->dataPtr->boundingboxCamera,
336+
*sdfCamera);
337+
338+
// Camera Info Msg
339+
this->PopulateInfo(sdfCamera);
340+
359341
// Create the directory to store frames
360342
if (sdfCamera->SaveFrames())
361343
{
@@ -430,16 +412,6 @@ bool BoundingBoxCameraSensor::Update(
430412
this->PublishInfo(_now);
431413
}
432414

433-
// render only if necessary
434-
{
435-
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
436-
if (this->dataPtr->isTriggeredCamera &&
437-
!this->dataPtr->isTriggered)
438-
{
439-
return true;
440-
}
441-
}
442-
443415
// don't render if there are no subscribers nor saving
444416
if (!this->dataPtr->imagePublisher.HasConnections() &&
445417
!this->dataPtr->boxesPublisher.HasConnections() &&
@@ -578,11 +550,6 @@ bool BoundingBoxCameraSensor::Update(
578550
++this->dataPtr->saveCounter;
579551
}
580552

581-
if (this->dataPtr->isTriggeredCamera)
582-
{
583-
return this->dataPtr->isTriggered = false;
584-
}
585-
586553
return true;
587554
}
588555

@@ -598,13 +565,6 @@ unsigned int BoundingBoxCameraSensor::ImageWidth() const
598565
return this->dataPtr->rgbCamera->ImageWidth();
599566
}
600567

601-
//////////////////////////////////////////////////
602-
void BoundingBoxCameraSensor::OnTrigger(const gz::msgs::Boolean &/*_msg*/)
603-
{
604-
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
605-
this->dataPtr->isTriggered = true;
606-
}
607-
608568
//////////////////////////////////////////////////
609569
void BoundingBoxCameraSensorPrivate::SaveImage()
610570
{

0 commit comments

Comments
 (0)