File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
gazebo/dave_gazebo_model_plugins
include/dave_gazebo_model_plugins Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 36
36
#include < string>
37
37
#include < vector>
38
38
#include < thread>
39
+ #include < mutex>
39
40
#include " ros/callback_queue.h"
40
41
#include " ros/subscribe_options.h"
41
42
@@ -108,6 +109,9 @@ namespace gazebo
108
109
// / \brief A thread the keeps running the rosQueue
109
110
private: std::thread databaseSubQueueThread;
110
111
112
+ // / \brief A thread mutex to lock
113
+ private: std::mutex lock_;
114
+
111
115
// / \brief Period after which we should publish a message via ROS.
112
116
private: gazebo::common::Time rosPublishPeriod;
113
117
Original file line number Diff line number Diff line change @@ -250,6 +250,8 @@ void TransientCurrentPlugin::Update(const gazebo::common::UpdateInfo &)
250
250
void TransientCurrentPlugin::UpdateDatabase (
251
251
const dave_gazebo_ros_plugins::StratifiedCurrentDatabase::ConstPtr &_msg)
252
252
{
253
+ this ->lock_ .lock ();
254
+
253
255
this ->database .clear ();
254
256
for (int i = 0 ; i < _msg->depths .size (); i++)
255
257
{
@@ -299,11 +301,15 @@ void TransientCurrentPlugin::UpdateDatabase(
299
301
this ->world_start_time [3 ] = _msg->worldStartTimeHour ;
300
302
this ->world_start_time [4 ] = _msg->worldStartTimeMinute ;
301
303
}
304
+
305
+ this ->lock_ .unlock ();
302
306
}
303
307
304
308
// ///////////////////////////////////////////////
305
309
void TransientCurrentPlugin::CalculateOceanCurrent ()
306
310
{
311
+ this ->lock_ .lock ();
312
+
307
313
// Update vehicle position
308
314
double vehicleDepth = - this ->model ->WorldPose ().Pos ().Z ();
309
315
@@ -442,6 +448,8 @@ void TransientCurrentPlugin::CalculateOceanCurrent()
442
448
// Update time stamp
443
449
this ->lastUpdate = time;
444
450
}
451
+
452
+ this ->lock_ .unlock ();
445
453
}
446
454
447
455
// ///////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments