@@ -29,6 +29,10 @@ PID_Control::PID_Control(ros::NodeHandle node, ros::NodeHandle private_nh)
29
29
/* ---ROS Topics Init--------------*/
30
30
_odom_sub = node.subscribe (_odometry_subscriber, 1 , &PID_Control::odomCallback, this );
31
31
_cmd_pub = node.advertise <geometry_msgs::Twist>(_cmd_vel_publisher, 10 );
32
+ _edist_pub = node.advertise <std_msgs::Float64 >(" /dist_error" , 10 );
33
+ _eangle_pub = node.advertise <std_msgs::Float64 >(" /angle_error" , 10 );
34
+
35
+ /* ---ROS Services-----------------*/
32
36
ros::service::waitForService (" gazebo/spawn_sdf_model" );
33
37
_spawn = node.serviceClient <gazebo_msgs::SpawnModel>(" gazebo/spawn_sdf_model" );
34
38
_dspawn = node.serviceClient <gazebo_msgs::DeleteModel>(" gazebo/delete_model" );
@@ -132,9 +136,9 @@ double PID_Control::calculateTargetDistance(const Orientation& pose, const Orien
132
136
133
137
double PID_Control::linearControl (const Orientation& pose, const Orientation& target)
134
138
{
135
- double distance, out_control;
136
- distance = calculateTargetDistance (_pose, _target);
137
- out_control = _pid.p_x * distance ;
139
+ double out_control;
140
+ _pid. dist_error = calculateTargetDistance (_pose, _target);
141
+ out_control = _pid.p_x * _pid. dist_error ;
138
142
if (out_control > _pid.x_max_vel )
139
143
{
140
144
out_control = _pid.x_max_vel ;
@@ -149,7 +153,8 @@ double PID_Control::angularControl(const Orientation& pose, const Orientation& t
149
153
150
154
goal_angle = atan2 (target.y - pose.y , target.x - pose.x );
151
155
152
- out_control = _pid.p_yaw * (goal_angle - _pose.yaw );
156
+ _pid.angle_error = (goal_angle - _pose.yaw );
157
+ out_control = _pid.p_yaw * _pid.angle_error ;
153
158
if (abs (out_control) > _pid.yaw_max_vel )
154
159
{
155
160
if (out_control < 0 )
@@ -166,6 +171,7 @@ double PID_Control::angularControl(const Orientation& pose, const Orientation& t
166
171
bool PID_Control::moveTarget ()
167
172
{
168
173
geometry_msgs::Twist cmd_vel;
174
+ std_msgs::Float64 error;
169
175
auto target_tol = calculateTargetDistance (_pose, _target);
170
176
171
177
if ((target_tol > 0.01 ))
@@ -174,6 +180,10 @@ bool PID_Control::moveTarget()
174
180
cmd_vel.angular .z = angularControl (_pose, _target);
175
181
176
182
_cmd_pub.publish (cmd_vel);
183
+ error.data = _pid.dist_error ;
184
+ _edist_pub.publish (error);
185
+ error.data = _pid.angle_error ;
186
+ _eangle_pub.publish (error);
177
187
}
178
188
else
179
189
{
0 commit comments