|
@@ -60,19 +60,19 @@ void horizontallyMoveMiddle(float left_dis,float right_dis,float tolerance)
|
|
{
|
|
{
|
|
float diff = left_dis - right_dis;
|
|
float diff = left_dis - right_dis;
|
|
//ROS_INFO("left right diff:%f", diff);
|
|
//ROS_INFO("left right diff:%f", diff);
|
|
- if(fabs(diff) > tolerance)
|
|
|
|
|
|
+ if((fabs(diff) > tolerance)&&(left_dis != 0.300000)&&(right_dis != 0.300000))
|
|
{
|
|
{
|
|
if(diff < 0) //move right
|
|
if(diff < 0) //move right
|
|
{
|
|
{
|
|
- ROS_INFO("move right horizontally !");
|
|
|
|
|
|
+ ROS_WARN("move Right horizontally !");
|
|
publishTwistCmd(0, -linear_y_speed, 0);
|
|
publishTwistCmd(0, -linear_y_speed, 0);
|
|
}
|
|
}
|
|
else //move left
|
|
else //move left
|
|
{
|
|
{
|
|
- ROS_INFO("move left horizontally !");
|
|
|
|
|
|
+ ROS_WARN("move Left horizontally !");
|
|
publishTwistCmd(0, linear_y_speed, 0);
|
|
publishTwistCmd(0, linear_y_speed, 0);
|
|
}
|
|
}
|
|
- ros::Duration(0.1).sleep(); //100 ms
|
|
|
|
|
|
+ ros::Duration(0.2).sleep(); //delay 200 ms
|
|
}
|
|
}
|
|
else //stop move
|
|
else //stop move
|
|
{
|
|
{
|
|
@@ -151,8 +151,8 @@ int controlTurn(int flag)
|
|
last_angle = rotation;
|
|
last_angle = rotation;
|
|
//ROS_INFO("turn_angle:%f",turn_angle);
|
|
//ROS_INFO("turn_angle:%f",turn_angle);
|
|
}
|
|
}
|
|
- ros::Duration(0.2).sleep(); //200 ms
|
|
|
|
ROS_INFO("Turning finish !!!");
|
|
ROS_INFO("Turning finish !!!");
|
|
|
|
+ ros::Duration(0.3).sleep(); //300 ms
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -165,24 +165,36 @@ void checkInfraredDist(float infrared_f,float infrared_l,float infrared_r,
|
|
{
|
|
{
|
|
if(infrared_f < warn_dist*2.0) //前边距离小于警告值
|
|
if(infrared_f < warn_dist*2.0) //前边距离小于警告值
|
|
{
|
|
{
|
|
|
|
+ if(infrared_l > infrared_r)
|
|
|
|
+ {
|
|
|
|
+ ROS_WARN("turn Left !");
|
|
|
|
+ controlTurn(TURN_LEFT);
|
|
|
|
+ }
|
|
|
|
+ else if(infrared_l < infrared_r)
|
|
|
|
+ {
|
|
|
|
+ ROS_WARN("turn Right !");
|
|
|
|
+ controlTurn(TURN_RIGHT);
|
|
|
|
+ }
|
|
|
|
+#if 0
|
|
if(fabs(infrared_l - infrared_r) > tolerance)
|
|
if(fabs(infrared_l - infrared_r) > tolerance)
|
|
{
|
|
{
|
|
if(infrared_l > infrared_r)
|
|
if(infrared_l > infrared_r)
|
|
{
|
|
{
|
|
- ROS_WARN("turn left !");
|
|
|
|
|
|
+ ROS_WARN("turn Left !");
|
|
controlTurn(TURN_LEFT);
|
|
controlTurn(TURN_LEFT);
|
|
}
|
|
}
|
|
else if(infrared_l < infrared_r)
|
|
else if(infrared_l < infrared_r)
|
|
{
|
|
{
|
|
- ROS_WARN("turn right !");
|
|
|
|
|
|
+ ROS_WARN("turn Right !");
|
|
controlTurn(TURN_RIGHT);
|
|
controlTurn(TURN_RIGHT);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- ROS_WARN("turn back !");
|
|
|
|
|
|
+ ROS_WARN("turn Back !");
|
|
controlTurn(TURN_BACK);
|
|
controlTurn(TURN_BACK);
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|