@@ -49,6 +49,9 @@ namespace ignition::gazebo
49
49
// / map key: string contains EntityID + "," + ComponentID
50
50
public: std::map<std::string,
51
51
std::shared_ptr<PlotComponent>> components;
52
+
53
+ // / \brief Mutex to protect the components map.
54
+ public: std::recursive_mutex componentsMutex;
52
55
};
53
56
54
57
class PlotComponentPrivate
@@ -194,7 +197,7 @@ ComponentTypeId PlotComponent::TypeId()
194
197
}
195
198
196
199
// ////////////////////////////////////////////////
197
- Plotting ::Plotting () : GuiSystem(),
200
+ Plotting::Plotting () : GuiSystem(),
198
201
dataPtr(std::make_unique<PlottingPrivate>())
199
202
{
200
203
this ->dataPtr ->plottingIface = std::make_unique<gui::PlottingInterface>();
@@ -215,7 +218,7 @@ Plotting ::Plotting() : GuiSystem(),
215
218
}
216
219
217
220
// ////////////////////////////////////////////////
218
- Plotting ::~Plotting ()
221
+ Plotting::~Plotting ()
219
222
{
220
223
}
221
224
@@ -229,13 +232,16 @@ void Plotting::LoadConfig(const tinyxml2::XMLElement *)
229
232
// ////////////////////////////////////////////////
230
233
void Plotting::SetData (std::string _Id, const ignition::math::Vector3d &_vector)
231
234
{
235
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
232
236
this ->dataPtr ->components [_Id]->SetAttributeValue (" x" , _vector.X ());
233
237
this ->dataPtr ->components [_Id]->SetAttributeValue (" y" , _vector.Y ());
234
238
this ->dataPtr ->components [_Id]->SetAttributeValue (" z" , _vector.Z ());
235
239
}
236
240
241
+ // ////////////////////////////////////////////////
237
242
void Plotting::SetData (std::string _Id, const ignition::msgs::Light &_light)
238
243
{
244
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
239
245
if (_light.has_specular ())
240
246
{
241
247
this ->dataPtr ->components [_Id]->SetAttributeValue (" specularR" ,
@@ -290,6 +296,7 @@ void Plotting::SetData(std::string _Id, const ignition::msgs::Light &_light)
290
296
// ////////////////////////////////////////////////
291
297
void Plotting::SetData (std::string _Id, const ignition::math::Pose3d &_pose)
292
298
{
299
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
293
300
this ->dataPtr ->components [_Id]->SetAttributeValue (" x" , _pose.Pos ().X ());
294
301
this ->dataPtr ->components [_Id]->SetAttributeValue (" y" , _pose.Pos ().Y ());
295
302
this ->dataPtr ->components [_Id]->SetAttributeValue (" z" , _pose.Pos ().Z ());
@@ -302,6 +309,7 @@ void Plotting::SetData(std::string _Id, const ignition::math::Pose3d &_pose)
302
309
// ////////////////////////////////////////////////
303
310
void Plotting::SetData (std::string _Id, const sdf::Physics &_physics)
304
311
{
312
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
305
313
this ->dataPtr ->components [_Id]->SetAttributeValue (" stepSize" ,
306
314
_physics.MaxStepSize ());
307
315
this ->dataPtr ->components [_Id]->SetAttributeValue (" realTimeFactor" ,
@@ -311,6 +319,7 @@ void Plotting::SetData(std::string _Id, const sdf::Physics &_physics)
311
319
// ////////////////////////////////////////////////
312
320
void Plotting::SetData (std::string _Id, const double &_value)
313
321
{
322
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
314
323
this ->dataPtr ->components [_Id]->SetAttributeValue (" value" , _value);
315
324
}
316
325
@@ -321,6 +330,7 @@ void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId,
321
330
std::string _attribute,
322
331
int _chart)
323
332
{
333
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
324
334
std::string Id = std::to_string (_entity) + " ," + std::to_string (_typeId);
325
335
326
336
if (this ->dataPtr ->components .count (Id) == 0 )
@@ -336,6 +346,7 @@ void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId,
336
346
void Plotting::UnRegisterChartFromComponent (uint64_t _entity, uint64_t _typeId,
337
347
std::string _attribute, int _chart)
338
348
{
349
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
339
350
std::string id = std::to_string (_entity) + " ," + std::to_string (_typeId);
340
351
igndbg << " UnRegister [" << id << " ]" << std::endl;
341
352
@@ -345,7 +356,7 @@ void Plotting::UnRegisterChartFromComponent(uint64_t _entity, uint64_t _typeId,
345
356
this ->dataPtr ->components [id]->UnRegisterChart (_attribute, _chart);
346
357
347
358
if (!this ->dataPtr ->components [id]->HasCharts ())
348
- this ->dataPtr ->components .erase (id);
359
+ this ->dataPtr ->components .erase (id);
349
360
}
350
361
351
362
// ////////////////////////////////////////////////
@@ -362,9 +373,10 @@ std::string Plotting::ComponentName(const uint64_t &_typeId)
362
373
}
363
374
364
375
// ////////////////////////////////////////////////
365
- void Plotting ::Update (const ignition::gazebo::UpdateInfo &_info,
376
+ void Plotting::Update (const ignition::gazebo::UpdateInfo &_info,
366
377
ignition::gazebo::EntityComponentManager &_ecm)
367
378
{
379
+ std::lock_guard<std::recursive_mutex> lock (this ->dataPtr ->componentsMutex );
368
380
for (auto component : this ->dataPtr ->components )
369
381
{
370
382
auto entity = component.second ->Entity ();
@@ -509,6 +521,6 @@ void Plotting ::Update(const ignition::gazebo::UpdateInfo &_info,
509
521
}
510
522
511
523
// Register this plugin
512
- IGNITION_ADD_PLUGIN (ignition::gazebo::Plotting ,
524
+ IGNITION_ADD_PLUGIN (ignition::gazebo::Plotting,
513
525
ignition::gazebo::GuiSystem,
514
526
ignition::gui::Plugin)
0 commit comments