Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "navigator_internal.h"
00011 #include "Controller.h"
00012 #include "obstacle.h"
00013 #include "follow_safely.h"
00014
00015 #include <art/DARPA_rules.h>
00016
00017 FollowSafely::FollowSafely(Navigator *navptr, int _verbose):
00018 Controller(navptr, _verbose) {};
00019
00020 FollowSafely::~FollowSafely() {};
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 Controller::result_t FollowSafely::control(pilot_command_t &pcmd)
00042 {
00043 bool was_blocked = navdata->lane_blocked;
00044 navdata->lane_blocked = false;
00045
00046 result_t result = OK;
00047 art_msgs::Observation fobs =
00048 obstacle->observation(art_msgs::Observation::Nearest_forward);
00049
00050 ROS_DEBUG("Nearest_forward: C%d A%d, dist %.3f, time %.3f, vel %.3f",
00051 fobs.clear, fobs.applicable,
00052 fobs.distance, fobs.time, fobs.velocity);
00053
00054 if (!fobs.applicable
00055 || fobs.distance >= obstacle->maximum_range())
00056 {
00057
00058 ROS_DEBUG("no obstacle ahead");
00059 return result;
00060 }
00061
00062 ROS_DEBUG("obstacle is %.3f sec ahead, closing at %.3f m/s",
00063 fobs.time, fobs.velocity);
00064
00065
00066
00067
00068 if ((fobs.time <= config_->min_following_time)
00069 || (fobs.distance <= config_->close_stopping_distance))
00070 {
00071
00072 pcmd.velocity = 0.0;
00073 ROS_DEBUG("Obstacle avoidance requesting immediate halt");
00074
00075
00076
00077 if (navdata->stopped)
00078 {
00079 navdata->lane_blocked = true;
00080 if (!was_blocked)
00081 {
00082
00083 ROS_INFO("New obstacle detected!");
00084 }
00085 result = Blocked;
00086 }
00087 }
00088 else if (fobs.time < config_->desired_following_time)
00089 {
00090 adjust_speed(pcmd, fobs.distance);
00091 }
00092 else if (nav->navdata.stopped
00093 || (fobs.time > config_->desired_following_time))
00094 {
00095 adjust_speed(pcmd, fobs.distance);
00096 }
00097
00098
00099
00100
00101
00102 if (obstacle->car_approaching())
00103 {
00104 ROS_ERROR("Possible collision ahead!");
00105 result = Collision;
00106 }
00107
00108 trace("follow_safely controller", pcmd, result);
00109 return result;
00110 };
00111
00112
00113
00114
00115
00116 void FollowSafely::adjust_speed(pilot_command_t &pcmd, float obs_dist)
00117 {
00118
00119
00120 float adjusted_speed = fminf(obs_dist / config_->desired_following_time,
00121 order->max_speed);
00122
00123
00124 pcmd.velocity = fminf(pcmd.velocity, adjusted_speed);
00125 }