Skip to content

Commit

Permalink
Merge pull request #213 from Field-Robotics-Lab/lock_stratified_curre…
Browse files Browse the repository at this point in the history
…nt_update

Lock ocean current calculation function.
  • Loading branch information
woensug-choi authored Feb 23, 2022
2 parents 5e2271f + 32c4955 commit 61d7801
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <string>
#include <vector>
#include <thread>
#include <mutex>
#include "ros/callback_queue.h"
#include "ros/subscribe_options.h"

Expand Down Expand Up @@ -108,6 +109,9 @@ namespace gazebo
/// \brief A thread the keeps running the rosQueue
private: std::thread databaseSubQueueThread;

/// \brief A thread mutex to lock
private: std::mutex lock_;

/// \brief Period after which we should publish a message via ROS.
private: gazebo::common::Time rosPublishPeriod;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ void TransientCurrentPlugin::Update(const gazebo::common::UpdateInfo &)
void TransientCurrentPlugin::UpdateDatabase(
const dave_gazebo_ros_plugins::StratifiedCurrentDatabase::ConstPtr &_msg)
{
this->lock_.lock();

this->database.clear();
for (int i = 0; i < _msg->depths.size(); i++)
{
Expand Down Expand Up @@ -299,11 +301,15 @@ void TransientCurrentPlugin::UpdateDatabase(
this->world_start_time[3] = _msg->worldStartTimeHour;
this->world_start_time[4] = _msg->worldStartTimeMinute;
}

this->lock_.unlock();
}

/////////////////////////////////////////////////
void TransientCurrentPlugin::CalculateOceanCurrent()
{
this->lock_.lock();

// Update vehicle position
double vehicleDepth = - this->model->WorldPose().Pos().Z();

Expand Down Expand Up @@ -442,6 +448,8 @@ void TransientCurrentPlugin::CalculateOceanCurrent()
// Update time stamp
this->lastUpdate = time;
}

this->lock_.unlock();
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 61d7801

Please sign in to comment.