Skip to content

Commit 4e1b265

Browse files
added mutex ro dynamic reconfig parameters.
1 parent c9b72f8 commit 4e1b265

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

yocs_diff_drive_pose_controller/include/yocs_diff_drive_pose_controller/diff_drive_pose_controller.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <string>
55
#include <yocs_controllers/default_controller.hpp>
6-
6+
#include <ecl/threads/mutex.hpp>
77
namespace yocs
88
{
99

@@ -171,6 +171,8 @@ class DiffDrivePoseController : public Controller
171171
double orient_eps_;
172172
/// Enable or disable ros messages.
173173
bool verbose_;
174+
175+
ecl::Mutex controller_mutex_;
174176
};
175177

176178
} /* end namespace */

yocs_diff_drive_pose_controller/src/diff_drive_pose_controller.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bool DiffDrivePoseController::step()
6262

6363
void DiffDrivePoseController::calculateControls()
6464
{
65+
controller_mutex_.lock();
6566
double angle_diff = mtk::wrapAngle(theta_ - delta_);
6667

6768
if (r_ > dist_thres_)
@@ -97,10 +98,12 @@ void DiffDrivePoseController::calculateControls()
9798
}
9899
}
99100
}
101+
controller_mutex_.unlock();
100102
}
101103

102104
void DiffDrivePoseController::controlPose()
103105
{
106+
controller_mutex_.lock();
104107
double atan2_k1_theta = std::atan2(-k_1_*theta_, 1.0);
105108
cur_ = (-1 / r_)
106109
* (k_2_ * (delta_ - atan2_k1_theta) + (1 + (k_1_ / (1 + std::pow((k_1_ * theta_), 2)))) * sin(delta_));
@@ -122,16 +125,20 @@ void DiffDrivePoseController::controlPose()
122125
v_ = enforceMinMax(v_, v_min_, v_max_);
123126

124127
// ROS_WARN_STREAM("r_: " << r_ << " dist_thres_: " << dist_thres_ << ", delta_-theta_: " << delta_ - theta_ << ", orient_thres_" << orient_thres_);
128+
controller_mutex_.unlock();
125129
}
126130

127131
void DiffDrivePoseController::controlOrientation(double angle_difference)
128132
{
133+
controller_mutex_.lock();
129134

130135
w_ = orientation_gain_ * (angle_difference);
131136

132137
//enforce limits on angular velocity
133138
w_ = enforceMinVelocity(w_, w_min_movement_);
134139
w_ = enforceMinMax(w_, w_min_, w_max_);
140+
141+
controller_mutex_.unlock();
135142
}
136143

137144
double DiffDrivePoseController::enforceMinMax(double& value, double min, double max)

yocs_diff_drive_pose_controller/src/diff_drive_pose_controller_ros.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ bool DiffDrivePoseControllerROS::init()
4141
{
4242
enable_controller_subscriber_ = nh_.subscribe("enable", 10, &DiffDrivePoseControllerROS::enableCB, this);
4343
disable_controller_subscriber_ = nh_.subscribe("disable", 10, &DiffDrivePoseControllerROS::disableCB, this);
44-
control_velocity_subscriber_ = nh_.subscribe("control_max_vel", 10, &DiffDrivePoseControllerROS::controlMaxVelCB,this);
44+
control_velocity_subscriber_ = nh_.subscribe("control_max_vel", 10, &DiffDrivePoseControllerROS::controlMaxVelCB,
45+
this);
4546
command_velocity_publisher_ = nh_.advertise<geometry_msgs::Twist>("command_velocity", 10);
4647
pose_reached_publisher_ = nh_.advertise<std_msgs::Bool>("pose_reached", 10);
4748

@@ -134,10 +135,9 @@ bool DiffDrivePoseControllerROS::init()
134135
"v_max = " << v_max_ <<", k_1 = " << k_1_ << ", k_2 = " << k_2_ << ", beta = " << beta_ << ", lambda = " << lambda_ << ", dist_thres = " << dist_thres_ << ", orient_thres = " << orient_thres_ <<" [" << name_ <<"]");
135136

136137
reconfig_server_ = boost::shared_ptr<dynamic_reconfigure::Server<gopher_navi_msgs::PoseControllerConfig> >(
137-
new dynamic_reconfigure::Server<gopher_navi_msgs::PoseControllerConfig>(nh_));
138-
reconfig_callback_func_ = boost::bind(&DiffDrivePoseControllerROS::reconfigCB, this, _1, _2);
139-
reconfig_server_->setCallback(reconfig_callback_func_);
140-
138+
new dynamic_reconfigure::Server<gopher_navi_msgs::PoseControllerConfig>(nh_));
139+
reconfig_callback_func_ = boost::bind(&DiffDrivePoseControllerROS::reconfigCB, this, _1, _2);
140+
reconfig_server_->setCallback(reconfig_callback_func_);
141141

142142
return true;
143143
}

0 commit comments

Comments
 (0)