Skip to content

Commit

Permalink
Changed realtime publisher from unique_ptr to direct member
Browse files Browse the repository at this point in the history
  • Loading branch information
t-schnell committed Dec 19, 2019
1 parent 806576b commit 296b42b
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions ur_robot_driver/include/ur_robot_driver/ros/data_field_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ class DirectDataPublisher : public DataFieldPublisher
* \param nh The used ROS node handle
*/
DirectDataPublisher(const std::string& data_field_identifier, ros::NodeHandle& nh)
: data_field_identifier_(data_field_identifier)
: data_field_identifier_(data_field_identifier), pub_(nh, "rtde_data/" + data_field_identifier_, 1)
{
pub_.reset(new realtime_tools::RealtimePublisher<MsgT>(nh, "rtde_data/" + data_field_identifier_, 1));
}

/*!
Expand All @@ -97,14 +96,11 @@ class DirectDataPublisher : public DataFieldPublisher
{
if (data_package.getData(data_field_identifier_, data_))
{
if (pub_)
if (pub_.trylock())
{
if (pub_->trylock())
{
pub_->msg_.data = data_;
pub_->unlockAndPublish();
return true;
}
pub_.msg_.data = data_;
pub_.unlockAndPublish();
return true;
}
}
return false;
Expand All @@ -113,7 +109,7 @@ class DirectDataPublisher : public DataFieldPublisher
private:
DataT data_;
std::string data_field_identifier_;
std::unique_ptr<realtime_tools::RealtimePublisher<MsgT>> pub_;
realtime_tools::RealtimePublisher<MsgT> pub_;
};

/*!
Expand All @@ -132,10 +128,8 @@ class ArrayDataPublisher : public DataFieldPublisher
* \param nh The used ROS node handle
*/
ArrayDataPublisher(const std::string& data_field_identifier, ros::NodeHandle& nh)
: data_field_identifier_(data_field_identifier)
: data_field_identifier_(data_field_identifier), pub_(nh, "rtde_data/" + data_field_identifier_, 1)
{
pub_.reset(new realtime_tools::RealtimePublisher<MsgT>(nh, "rtde_data/" + data_field_identifier_, 1));
pub_->msg_.data.resize(N);
}

/*!
Expand All @@ -149,17 +143,14 @@ class ArrayDataPublisher : public DataFieldPublisher
{
if (data_package.getData(data_field_identifier_, data_))
{
if (pub_)
if (pub_.trylock())
{
if (pub_->trylock())
for (size_t i = 0; i < N; i++)
{
for (size_t i = 0; i < N; i++)
{
pub_->msg_.data[i] = data_[i];
}
pub_->unlockAndPublish();
return true;
pub_.msg_.data[i] = data_[i];
}
pub_.unlockAndPublish();
return true;
}
}
return false;
Expand All @@ -168,7 +159,7 @@ class ArrayDataPublisher : public DataFieldPublisher
private:
std::array<DataT, N> data_;
std::string data_field_identifier_;
std::unique_ptr<realtime_tools::RealtimePublisher<MsgT>> pub_;
realtime_tools::RealtimePublisher<MsgT> pub_;
};
} // namespace rtde_interface
} // namespace ur_driver
Expand Down

0 comments on commit 296b42b

Please sign in to comment.