00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "navigator_internal.h"
00012 #include "Controller.h"
00013 #include "course.h"
00014 #include "obstacle.h"
00015 #include "passing.h"
00016
00017 #include "avoid.h"
00018 #include "halt.h"
00019 #include "lane_heading.h"
00020 #include "follow_safely.h"
00021 #include "slow_for_curves.h"
00022
00023 #include <art/DARPA_rules.h>
00024
00025 Passing::Passing(Navigator *navptr, int _verbose):
00026 Controller(navptr, _verbose)
00027 {
00028 avoid = new Avoid(navptr, _verbose);
00029 halt = new Halt(navptr, _verbose);
00030 follow_safely = new FollowSafely(navptr, _verbose);
00031 lane_heading = new LaneHeading(navptr, _verbose);
00032 slow_for_curves = new SlowForCurves(navptr, _verbose);
00033 reset_me();
00034 };
00035
00036 Passing::~Passing()
00037 {
00038 delete avoid;
00039 delete halt;
00040 delete follow_safely;
00041 delete lane_heading;
00042 delete slow_for_curves;
00043 };
00044
00045 void Passing::configure()
00046 {
00047
00048
00049 passing_distance = cf->ReadFloat(section, "passing_distance", 10.0);
00050 ART_MSG(2, "\tminimum passing distance is %.3f m", passing_distance);
00051
00052
00053 passing_distance_ahead = cf->ReadFloat(section, "passing_distance_ahead",
00054 DARPA_rules::front_limit_after_pass
00055 + ArtVehicle::front_bumper_px
00056 + ArtVehicle::length);
00057 ART_MSG(2, "\tpassing distance ahead is %.3f m", passing_distance_ahead);
00058
00059 passing_distance_behind = cf->ReadFloat(section, "passing_distance_behind",
00060 DARPA_rules::min_rear_sep_after_pass
00061 - ArtVehicle::rear_bumper_px
00062 - ArtVehicle::halflength);
00063 ART_MSG(2, "\tpassing distance behind is %.3f m", passing_distance_behind);
00064
00065 passing_speed = cf->ReadFloat(section, "passing_speed", 3.0);
00066 ART_MSG(2, "\tpassing speed is %.1f m/s", passing_speed);
00067
00068 avoid->configure(cf, section);
00069 halt->configure(cf, section);
00070 follow_safely->configure(cf, section);
00071 slow_for_curves->configure(cf, section);
00072 lane_heading->configure(cf, section);
00073 }
00074
00075
00076
00077
00078
00079
00080
00081 Controller::result_t Passing::control(pilot_command_t &pcmd)
00082 {
00083 pilot_command_t incmd = pcmd;
00084
00085 if (!in_passing_lane
00086 && course->in_lane(estimate->pos))
00087 in_passing_lane = true;
00088
00089 if (!in_passing_lane
00090 && !obstacle->passing_lane_clear())
00091 {
00092 trace("passing (not clear) controller", pcmd);
00093 return halt->control(pcmd);
00094 }
00095
00096 if (verbose >= 2)
00097 {
00098 ART_MSG(5, "Go to waypoint %s in passing lane",
00099 order->waypt[1].id.name().str);
00100 }
00101
00102
00103 nav->reduce_speed_with_min(pcmd, passing_speed);
00104
00105
00106 result_t result = follow_safely->control(pcmd);
00107
00108 slow_for_curves->control(pcmd);
00109
00110 if (done_passing())
00111 {
00112 ART_MSG(1, "passing completed");
00113 result = Finished;
00114 }
00115
00116
00117 lane_heading->control(pcmd);
00118
00119 course->lane_waypoint_reached();
00120
00121 result_t avoid_result = avoid->control(pcmd, incmd);
00122 if (result == OK)
00123 {
00124 result = avoid_result;
00125 }
00126
00127 trace("passing controller", pcmd, result);
00128
00129 return result;
00130 };
00131
00132
00133 bool Passing::done_passing(void)
00134 {
00135 bool done = false;
00136 if (course->distance_in_plan(course->start_pass_location, estimate->pos)
00137 > passing_distance+DARPA_rules::min_forw_sep_travel
00138 + ArtVehicle::front_bumper_px);
00139 {
00140
00141
00142
00143 float ahead, behind;
00144 obstacle->closest_in_lane(course->passed_lane, ahead, behind);
00145 if (ahead >= passing_distance_ahead
00146 && behind >= passing_distance_behind)
00147 {
00148 done = true;
00149 }
00150 }
00151 return done;
00152 }
00153
00154
00155 void Passing::reset(void)
00156 {
00157 trace_reset("Passing");
00158 reset_me();
00159 avoid->reset();
00160 halt->reset();
00161 follow_safely->reset();
00162 lane_heading->reset();
00163 slow_for_curves->reset();
00164 }
00165
00166
00167 void Passing::reset_me(void)
00168 {
00169 navdata->reverse = false;
00170 in_passing_lane = false;
00171 }