Skip to content

Commit 583826a

Browse files
got the code to compile. still needs testing.
added mutex ro dynamic reconfig parameters. added header for mutex. now using yocs_msgs
1 parent 10cd9dd commit 583826a

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

yocs_diff_drive_pose_controller/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.3)
22
project(yocs_diff_drive_pose_controller)
33

44
find_package(catkin REQUIRED COMPONENTS ecl_threads
5+
dynamic_reconfigure
56
geometry_msgs
67
nodelet
78
pluginlib
@@ -11,11 +12,13 @@ find_package(catkin REQUIRED COMPONENTS ecl_threads
1112
tf
1213
yocs_controllers
1314
yocs_math_toolkit
15+
yocs_msgs
1416
)
1517

1618
catkin_package(INCLUDE_DIRS include
1719
LIBRARIES yocs_diff_drive_pose_controller yocs_diff_drive_pose_controller_nodelet
1820
CATKIN_DEPENDS ecl_threads
21+
dynamic_reconfigure
1922
geometry_msgs
2023
nodelet
2124
pluginlib
@@ -25,6 +28,7 @@ catkin_package(INCLUDE_DIRS include
2528
tf
2629
yocs_controllers
2730
yocs_math_toolkit
31+
yocs_msgs
2832
)
2933

3034
include_directories(include ${catkin_INCLUDE_DIRS})

yocs_diff_drive_pose_controller/include/yocs_diff_drive_pose_controller/diff_drive_pose_controller.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <string>
55
#include <yocs_controllers/default_controller.hpp>
6+
#include <ecl/threads/mutex.hpp>
67

78
namespace yocs
89
{
@@ -171,6 +172,8 @@ class DiffDrivePoseController : public Controller
171172
double orient_eps_;
172173
/// Enable or disable ros messages.
173174
bool verbose_;
175+
176+
ecl::Mutex controller_mutex_;
174177
};
175178

176179
} /* end namespace */

yocs_diff_drive_pose_controller/include/yocs_diff_drive_pose_controller/diff_drive_pose_controller_ros.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@
3838
** Includes
3939
*****************************************************************************/
4040
#include <ros/ros.h>
41+
#include <ecl/threads/mutex.hpp>
4142
#include <std_msgs/Empty.h>
4243
#include <std_msgs/Float32.h>
4344
#include <std_msgs/String.h>
4445
#include <tf/transform_listener.h>
46+
#include <boost/shared_ptr.hpp>
47+
#include <dynamic_reconfigure/server.h>
48+
#include <yocs_msgs/PoseControllerConfig.h>
4549

4650
#include "yocs_diff_drive_pose_controller/diff_drive_pose_controller.hpp"
4751

@@ -132,6 +136,8 @@ class DiffDrivePoseControllerROS : public DiffDrivePoseController
132136
*/
133137
void disableCB(const std_msgs::EmptyConstPtr msg);
134138

139+
void reconfigCB(yocs_msgs::PoseControllerConfig &config, uint32_t level);
140+
135141
// basics
136142
ros::NodeHandle nh_;
137143
std::string name_;
@@ -156,6 +162,17 @@ class DiffDrivePoseControllerROS : public DiffDrivePoseController
156162
std::string base_frame_name_;
157163
/// frame name of the goal (pose)
158164
std::string goal_frame_name_;
165+
166+
///dynamic reconfigure server
167+
boost::shared_ptr<dynamic_reconfigure::Server<yocs_msgs::PoseControllerConfig> > reconfig_server_;
168+
169+
///dynamic reconfigure server callback type
170+
dynamic_reconfigure::Server<yocs_msgs::PoseControllerConfig>::CallbackType reconfig_callback_func_;
171+
172+
yocs_msgs::PoseControllerConfig test_;
173+
174+
ecl::Mutex dynamic_reconfig_mutex_;
175+
159176
};
160177

161178
} // namespace yocs

yocs_diff_drive_pose_controller/package.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
<url type="website">http://ros.org/wiki/yocs_diff_drive_pose_controller</url>
1313
<url type="repository">https://github.com/yujinrobot/yujin_ocs</url>
1414
<url type="bugtracker">https://github.com/yujinrobot/yujin_ocs/issues</url>
15-
15+
1616
<buildtool_depend>catkin</buildtool_depend>
1717

1818
<build_depend>ecl_threads</build_depend>
19+
<build_depend>dynamic_reconfigure</build_depend>
1920
<build_depend>geometry_msgs</build_depend>
2021
<build_depend>nodelet</build_depend>
2122
<build_depend>pluginlib</build_depend>
@@ -25,8 +26,11 @@
2526
<build_depend>tf</build_depend>
2627
<build_depend>yocs_controllers</build_depend>
2728
<build_depend>yocs_math_toolkit</build_depend>
29+
<build_depend>yocs_msgs</build_depend>
30+
2831

2932
<run_depend>ecl_threads</run_depend>
33+
<run_depend>dynamic_reconfigure</run_depend>
3034
<run_depend>geometry_msgs</run_depend>
3135
<run_depend>nodelet</run_depend>
3236
<run_depend>pluginlib</run_depend>
@@ -36,7 +40,8 @@
3640
<run_depend>tf</run_depend>
3741
<run_depend>yocs_controllers</run_depend>
3842
<run_depend>yocs_math_toolkit</run_depend>
39-
43+
<run_depend>yocs_msgs</run_depend>
44+
4045
<export>
4146
<nodelet plugin="${prefix}/plugins/nodelets.xml"/>
4247
</export>

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ bool DiffDrivePoseControllerROS::init()
133133
"base_frame_name = " << base_frame_name_ <<", goal_frame_name = " << goal_frame_name_ << " [" << name_ <<"]");
134134
ROS_DEBUG_STREAM(
135135
"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_ <<"]");
136+
137+
reconfig_server_ = boost::shared_ptr<dynamic_reconfigure::Server<yocs_msgs::PoseControllerConfig> >(
138+
new dynamic_reconfigure::Server<yocs_msgs::PoseControllerConfig>(nh_));
139+
reconfig_callback_func_ = boost::bind(&DiffDrivePoseControllerROS::reconfigCB, this, _1, _2);
140+
reconfig_server_->setCallback(reconfig_callback_func_);
141+
136142
return true;
137143
}
138144

@@ -248,4 +254,22 @@ void DiffDrivePoseControllerROS::disableCB(const std_msgs::EmptyConstPtr msg)
248254
}
249255
}
250256

257+
void DiffDrivePoseControllerROS::reconfigCB(yocs_msgs::PoseControllerConfig &config, uint32_t level)
258+
{
259+
dynamic_reconfig_mutex_.lock();
260+
v_min_movement_ = config.v_min;
261+
v_max_ = config.v_max;
262+
w_max_ = config.w_max;
263+
w_min_ = config.w_min;
264+
k_1_ = config.k_1;
265+
k_2_ = config.k_2;
266+
beta_ = config.beta;
267+
lambda_ = config.lambda;
268+
dist_thres_ = config.dist_thres;
269+
orient_thres_ = config.orient_thres;
270+
dist_eps_ = config.dist_eps;
271+
orient_eps_ = config.orient_eps;
272+
dynamic_reconfig_mutex_.unlock();
273+
}
274+
251275
} // namespace yocs

0 commit comments

Comments
 (0)