Skip to content

Commit 9c745a4

Browse files
author
Nate Koenig
committed
Merge branch 'ign-gazebo4' into imu_orientation
2 parents 59a2760 + 3fbddd1 commit 9c745a4

File tree

9 files changed

+299
-19
lines changed

9 files changed

+299
-19
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
33
#============================================================================
44
# Initialize the project
55
#============================================================================
6-
project(ignition-gazebo4 VERSION 4.10.0)
6+
project(ignition-gazebo4 VERSION 4.11.0)
77

88
#============================================================================
99
# Find ignition-cmake

Changelog.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
## Ignition Gazebo 4.x
22

3-
### Ignition Gazebo 4.x.x (202x-xx-xx)
3+
### Ignition Gazebo 4.11.x (2021-09-23)
44

5-
### Ignition Gazebo 4.x.x (2021-09-15)
5+
1. Support locked entities, and headless video recording using sim time.
6+
* [Pull Request 862](https://github.com/ignitionrobotics/ign-gazebo/pull/862)
7+
8+
### Ignition Gazebo 4.10.x (2021-09-15)
69

710
1. Fixed GUI's ComponentInspector light parameter
811
* [Pull Request 1018](https://github.com/ignitionrobotics/ign-gazebo/pull/1018)
@@ -40,6 +43,14 @@
4043
1. Using math::SpeedLimiter on the ackermann_steering controller.
4144
* [Pull Request 837](https://github.com/ignitionrobotics/ign-gazebo/pull/837)
4245

46+
1. All changes merged forward from ign-gazebo3
47+
* [Pull Request 866](https://github.com/ignitionrobotics/ign-gazebo/pull/866)
48+
* [Pull Request 916](https://github.com/ignitionrobotics/ign-gazebo/pull/916)
49+
* [Pull Request 933](https://github.com/ignitionrobotics/ign-gazebo/pull/933)
50+
* [Pull Request 946](https://github.com/ignitionrobotics/ign-gazebo/pull/946)
51+
* [Pull Request 973](https://github.com/ignitionrobotics/ign-gazebo/pull/973)
52+
* [Pull Request 1017](https://github.com/ignitionrobotics/ign-gazebo/pull/1017)
53+
4354
### Ignition Gazebo 4.9.1 (2021-05-24)
4455

4556
1. Make halt motion act like a brake.

include/ignition/gazebo/EntityComponentManager.hh

+29
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,35 @@ namespace ignition
9191
public: void RequestRemoveEntity(const Entity _entity,
9292
bool _recursive = true);
9393

94+
/// \brief Prevent an entity and optionally its children from
95+
/// being removed.
96+
///
97+
/// This function can be useful when seek operations during log
98+
/// playback are used in conjunciton with spawned entities. For
99+
/// example, you may want to record a video based on a log file
100+
/// using a headless simulation instance. This requires a
101+
/// camera sensor which would be spawned during log playback. If
102+
/// a seek backward in time is performed during log playback, then the
103+
/// spawned camera would be removed. Use this function to prevent the
104+
/// camera from automatic removal.
105+
///
106+
/// \param[in] _entity Entity to be pinned.
107+
/// \param[in] _recursive Whether to recursively pin all child
108+
/// entities. True by default.
109+
public: void PinEntity(const Entity _entity, bool _recursive = true);
110+
111+
/// \brief Allow an entity, and optionally its children, previously
112+
/// marked as pinned to be removed.
113+
/// \param[in] _entity Entity to be unpinned.
114+
/// \param[in] _recursive Whether to recursively unpin all child
115+
/// entities. True by default.
116+
/// \sa void PinEntity(const Entity, bool)
117+
public: void UnpinEntity(const Entity _entity, bool _recursive = true);
118+
119+
/// \brief Allow all previously pinned entities to be removed.
120+
/// \sa void PinEntity(const Entity, bool)
121+
public: void UnpinAllEntities();
122+
94123
/// \brief Request to remove all entities. This will insert the request
95124
/// into a queue. The queue is processed toward the end of a simulation
96125
/// update step.

src/EntityComponentManager.cc

+105-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class ignition::gazebo::EntityComponentManagerPrivate
4545
public: void InsertEntityRecursive(Entity _entity,
4646
std::unordered_set<Entity> &_set);
4747

48+
/// \brief Recursively erase an entity and all its descendants from a given
49+
/// set.
50+
/// \param[in] _entity Entity to be erased.
51+
/// \param[in, out] _set Set to erase from.
52+
public: void EraseEntityRecursive(Entity _entity,
53+
std::unordered_set<Entity> &_set);
54+
4855
/// \brief Register a new component type.
4956
/// \param[in] _typeId Type if of the new component.
5057
/// \return True if created successfully.
@@ -156,6 +163,9 @@ class ignition::gazebo::EntityComponentManagerPrivate
156163
/// which belongs the component, and the value is the component being
157164
/// removed.
158165
std::unordered_multimap<Entity, ComponentKey> removedComponents;
166+
167+
/// \brief Set of entities that are prevented from removal.
168+
public: std::unordered_set<Entity> pinnedEntities;
159169
};
160170

161171
//////////////////////////////////////////////////
@@ -236,6 +246,17 @@ void EntityComponentManagerPrivate::InsertEntityRecursive(Entity _entity,
236246
_set.insert(_entity);
237247
}
238248

249+
/////////////////////////////////////////////////
250+
void EntityComponentManagerPrivate::EraseEntityRecursive(Entity _entity,
251+
std::unordered_set<Entity> &_set)
252+
{
253+
for (const auto &vertex : this->entities.AdjacentsFrom(_entity))
254+
{
255+
this->EraseEntityRecursive(vertex.first, _set);
256+
}
257+
_set.erase(_entity);
258+
}
259+
239260
/////////////////////////////////////////////////
240261
void EntityComponentManager::RequestRemoveEntity(Entity _entity,
241262
bool _recursive)
@@ -252,6 +273,23 @@ void EntityComponentManager::RequestRemoveEntity(Entity _entity,
252273
this->dataPtr->InsertEntityRecursive(_entity, tmpToRemoveEntities);
253274
}
254275

276+
// Remove entities from tmpToRemoveEntities that are marked as
277+
// unremovable.
278+
for (auto iter = tmpToRemoveEntities.begin();
279+
iter != tmpToRemoveEntities.end();)
280+
{
281+
if (std::find(this->dataPtr->pinnedEntities.begin(),
282+
this->dataPtr->pinnedEntities.end(), *iter) !=
283+
this->dataPtr->pinnedEntities.end())
284+
{
285+
iter = tmpToRemoveEntities.erase(iter);
286+
}
287+
else
288+
{
289+
++iter;
290+
}
291+
}
292+
255293
{
256294
std::lock_guard<std::mutex> lock(this->dataPtr->entityRemoveMutex);
257295
this->dataPtr->toRemoveEntities.insert(tmpToRemoveEntities.begin(),
@@ -267,11 +305,41 @@ void EntityComponentManager::RequestRemoveEntity(Entity _entity,
267305
/////////////////////////////////////////////////
268306
void EntityComponentManager::RequestRemoveEntities()
269307
{
308+
if (this->dataPtr->pinnedEntities.empty())
270309
{
271-
std::lock_guard<std::mutex> lock(this->dataPtr->entityRemoveMutex);
272-
this->dataPtr->removeAllEntities = true;
310+
{
311+
std::lock_guard<std::mutex> lock(this->dataPtr->entityRemoveMutex);
312+
this->dataPtr->removeAllEntities = true;
313+
}
314+
this->RebuildViews();
315+
}
316+
else
317+
{
318+
std::unordered_set<Entity> tmpToRemoveEntities;
319+
320+
// Store the to-be-removed entities in a temporary set so we can call
321+
// UpdateViews on each of them
322+
for (const auto &vertex : this->dataPtr->entities.Vertices())
323+
{
324+
if (std::find(this->dataPtr->pinnedEntities.begin(),
325+
this->dataPtr->pinnedEntities.end(), vertex.first) ==
326+
this->dataPtr->pinnedEntities.end())
327+
{
328+
tmpToRemoveEntities.insert(vertex.first);
329+
}
330+
}
331+
332+
{
333+
std::lock_guard<std::mutex> lock(this->dataPtr->entityRemoveMutex);
334+
this->dataPtr->toRemoveEntities.insert(tmpToRemoveEntities.begin(),
335+
tmpToRemoveEntities.end());
336+
}
337+
338+
for (const auto &removedEntity : tmpToRemoveEntities)
339+
{
340+
this->UpdateViews(removedEntity);
341+
}
273342
}
274-
this->RebuildViews();
275343
}
276344

277345
/////////////////////////////////////////////////
@@ -1514,3 +1582,37 @@ void EntityComponentManagerPrivate::AddModifiedComponent(const Entity &_entity)
15141582

15151583
this->modifiedComponents.insert(_entity);
15161584
}
1585+
1586+
/////////////////////////////////////////////////
1587+
void EntityComponentManager::PinEntity(const Entity _entity, bool _recursive)
1588+
{
1589+
if (_recursive)
1590+
{
1591+
this->dataPtr->InsertEntityRecursive(_entity,
1592+
this->dataPtr->pinnedEntities);
1593+
}
1594+
else
1595+
{
1596+
this->dataPtr->pinnedEntities.insert(_entity);
1597+
}
1598+
}
1599+
1600+
/////////////////////////////////////////////////
1601+
void EntityComponentManager::UnpinEntity(const Entity _entity, bool _recursive)
1602+
{
1603+
if (_recursive)
1604+
{
1605+
this->dataPtr->EraseEntityRecursive(_entity,
1606+
this->dataPtr->pinnedEntities);
1607+
}
1608+
else
1609+
{
1610+
this->dataPtr->pinnedEntities.erase(_entity);
1611+
}
1612+
}
1613+
1614+
/////////////////////////////////////////////////
1615+
void EntityComponentManager::UnpinAllEntities()
1616+
{
1617+
this->dataPtr->pinnedEntities.clear();
1618+
}

src/EntityComponentManager_TEST.cc

+58
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,64 @@ TEST_P(EntityComponentManagerFixture, RemovedComponentsSyncBetweenServerAndGUI)
25712571
}
25722572
}
25732573

2574+
//////////////////////////////////////////////////
2575+
TEST_P(EntityComponentManagerFixture, PinnedEntity)
2576+
{
2577+
// Create some entities
2578+
auto e1 = manager.CreateEntity();
2579+
EXPECT_EQ(1u, e1);
2580+
EXPECT_TRUE(manager.HasEntity(e1));
2581+
2582+
auto e2 = manager.CreateEntity();
2583+
EXPECT_TRUE(manager.SetParentEntity(e2, e1));
2584+
EXPECT_EQ(2u, e2);
2585+
EXPECT_TRUE(manager.HasEntity(e2));
2586+
2587+
auto e3 = manager.CreateEntity();
2588+
EXPECT_EQ(3u, e3);
2589+
EXPECT_TRUE(manager.HasEntity(e3));
2590+
2591+
EXPECT_EQ(3u, manager.EntityCount());
2592+
2593+
// Mark e1 as unremovable, which should also lock its child entity e2
2594+
manager.PinEntity(e1);
2595+
2596+
// Try to remove e1, which is locked entity
2597+
manager.RequestRemoveEntity(e1);
2598+
EXPECT_EQ(3u, manager.EntityCount());
2599+
EXPECT_FALSE(manager.HasEntitiesMarkedForRemoval());
2600+
manager.ProcessEntityRemovals();
2601+
EXPECT_EQ(3u, manager.EntityCount());
2602+
2603+
// Try to remove e2, which has been locked recursively
2604+
manager.RequestRemoveEntity(e2);
2605+
EXPECT_EQ(3u, manager.EntityCount());
2606+
EXPECT_FALSE(manager.HasEntitiesMarkedForRemoval());
2607+
manager.ProcessEntityRemovals();
2608+
EXPECT_EQ(3u, manager.EntityCount());
2609+
2610+
// Try to remove all entities, which should leave just e1 and e2
2611+
manager.RequestRemoveEntities();
2612+
EXPECT_TRUE(manager.HasEntitiesMarkedForRemoval());
2613+
manager.ProcessEntityRemovals();
2614+
EXPECT_EQ(2u, manager.EntityCount());
2615+
2616+
// Unmark e2, and now it should be removable.
2617+
manager.UnpinEntity(e2);
2618+
manager.RequestRemoveEntity(e2);
2619+
EXPECT_EQ(2u, manager.EntityCount());
2620+
EXPECT_TRUE(manager.HasEntitiesMarkedForRemoval());
2621+
manager.ProcessEntityRemovals();
2622+
EXPECT_EQ(1u, manager.EntityCount());
2623+
2624+
// Unmark all entities, and now it should be removable.
2625+
manager.UnpinAllEntities();
2626+
manager.RequestRemoveEntities();
2627+
EXPECT_TRUE(manager.HasEntitiesMarkedForRemoval());
2628+
manager.ProcessEntityRemovals();
2629+
EXPECT_EQ(0u, manager.EntityCount());
2630+
}
2631+
25742632
// Run multiple times. We want to make sure that static globals don't cause
25752633
// problems.
25762634
INSTANTIATE_TEST_SUITE_P(EntityComponentManagerRepeat,

src/gui/plugins/scene3d/Scene3D.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
157157
/// only used in lockstep mode and recording in sim time.
158158
public: std::chrono::steady_clock::time_point recordVideoUpdateTime;
159159

160-
/// \brief Start tiem of video recording
160+
/// \brief Start time of video recording
161161
public: std::chrono::steady_clock::time_point recordStartTime;
162162

163-
/// \brief Camera pose publisher
163+
/// \brief Video recording statistics publisher
164164
public: transport::Node::Publisher recorderStatsPub;
165165

166166
/// \brief Target to move the user camera to

0 commit comments

Comments
 (0)