00001
00002
00003
00004 #ifndef CAJUN_MISSION_PLANNER_H
00005 #define CAJUN_MISSION_PLANNER_H
00006
00007 #include "rndf.H"
00008 #include "graph.H"
00009 #include "graph_search.H"
00010
00011 #include "uc_planner_param.H"
00012 #include "rndf_point.H"
00013 #include"world_state.H"
00014
00015 #include <queue>
00016 #include <vector>
00017
00018 namespace cajun
00019 {
00020 typedef std::deque<rndf_point_t*> mission_plan_t;
00021 typedef graph_t<rp_containter_t>::vertex_t graph_node_t;
00022
00023 class mdf_t;
00024
00025 class mission_planner_t
00026 {
00027 friend class mission_handler_t;
00028 private:
00029 class wp_node_t
00030 {
00031
00032 public:
00033 wp_node_t (double dist_, rndf_point_t *wp_id_) :
00034 m_dist (dist_), m_wp_id (wp_id_) { }
00035 bool operator < (wp_node_t const &n_) const
00036 { return (m_dist > n_.m_dist); }
00037
00038 double dist () { return m_dist;}
00039 rndf_point_t* wp_id () {return m_wp_id; }
00040 private:
00041 double m_dist;
00042 rndf_point_t *m_wp_id;
00043 };
00044
00045 const uc_planner_param_t *m_uc_param;
00046
00047 rndf_t const *m_rndf;
00048 mdf_t const *m_mdf;
00049 world_state_t *m_ws;
00050 graph_t <rp_containter_t> m_graph;
00051 graph_search_t<rp_containter_t> *m_g_search;
00052
00053 std::deque<rndf_point_t*> m_intermediate_rps;
00054
00055 double distance_between_rps (rndf_point_t const *rp_1_,
00056 rndf_point_t const *rp_2_);
00057
00059 double compute_cost (rndf_point_t *id_1_, rndf_point_t *id_2_);
00060
00061
00062 void get_lanes_to_merge_with (
00063 rndf_t::segment_t const &seg_,
00064 unsigned li_, std::vector<unsigned> &lanes_to_merge_);
00065
00066 bool can_pass_between_lanes (
00067 rndf_t::segment_t const &seg_, unsigned li1_,
00068 unsigned li2_);
00069
00070
00071 void merge_lanes (unsigned sid_,
00072 std::vector<unsigned> const &lane_to_merge,
00073 std::deque<wp_node_t> &seg_wps);
00074
00075
00077 bool should_be_graph_node (rndf_point_t const *wp_id_);
00078
00081 bool is_mission_checkpoint (rndf_point_t const *rp_);
00082
00086 bool create_graph ();
00087
00089 void add_zone_to_graph (rndf_t::zone_t const &zone_);
00090
00093 void create_road_edges (std::deque <wp_node_t> &seg_wps);
00094
00098 void create_edges_from_wp (std::deque <wp_node_t> &seg_wps_,
00099 unsigned wp_i);
00100
00101 void create_edge (rndf_t::waypoint_id_t wp_id_,
00102 rndf_t::waypoint_id_t neighbor_id_);
00103
00104 void create_edge (rndf_point_t *rp, rndf_point_t *neigh_rp);
00105
00106 bool edge_exist (graph_node_t *v1, graph_node_t *v2);
00107
00108 bool not_close (std::deque <wp_node_t> &seg_wps_,
00109 unsigned ind1_, unsigned ind2_);
00110
00111 void print_wp_node (std::deque<wp_node_t> &seg_wps_,
00112 unsigned wp_i);
00113
00114
00116 bool mission_spot (rndf_t::spot_t const &spot_);
00117
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00138 bool lanes_in_same_direction (rndf_t::lane_t const &lane_,
00139 rndf_t::lane_t const &n_lane_);
00140
00141 bool is_next_checkpoint (rndf_point_t *rp_, unsigned next_ckpt_);
00142
00143 bool keep_as_individual_rp_in_plan (rndf_point_t *rp_,
00144 unsigned next_ckpt_);
00145
00146 bool is_entry_exit_pair (rndf_point_t *exit_rp_,
00147 rndf_point_t *entry_rp_);
00148
00149 bool is_entry_exit_pair_to_keep (rndf_point_t *exit_rp_,
00150 rndf_point_t *entry_rp_);
00151
00152 void filter_detail_plan (
00153 mission_plan_t const &input_plan_,
00154 mission_plan_t &ouput_plan_,
00155 unsigned next_checkpoint_);
00156
00157 bool is_active_node (graph_node_t const *gn);
00158 void get_inter_rp_in_wp_seg (
00159 rndf_t::waypoint_id_t const &wp_id_,
00160 std::vector<rndf_point_t *> rp_list_);
00161 public:
00162 mission_planner_t (rndf_t const *rndf_, mdf_t const *mdf_,
00163 world_state_t *ws_);
00164
00168 bool update_plan (unsigned next_checkpoint_,
00169 mission_plan_t &detail_plan_,
00170 mission_plan_t &filter_plan_);
00171
00172 graph_node_t* graph_node_at_wp (
00173 rndf_t::waypoint_id_t const &wp_id_);
00174
00175 graph_node_t* graph_node_at_wp (unsigned sid_, unsigned lid_,
00176 unsigned wid_);
00177
00178 graph_node_t* active_graph_node_on_or_before (
00179 unsigned sid_, unsigned lid_, unsigned wid_);
00180
00181 graph_node_t* active_graph_node_on_or_after (
00182 unsigned sid_, unsigned lid_, unsigned wid_);
00183
00184 graph_node_t* active_graph_node_on_or_before (
00185 rndf_point_t *rp_);
00186
00187 graph_node_t* active_graph_node_after (rndf_point_t *rp_);
00188
00189 graph_node_t* active_graph_node_before (
00190 double x_, double y_,
00191 rndf_t::waypoint_id_t const &before_wp_id);
00192
00193 graph_node_t* graph_node_at_rp (rndf_point_t *rp_);
00194
00195 bool comes_later_on_wp_seg (rndf_point_t *rp_,
00196 double x_, double y_);
00197
00198
00199 rndf_point_t* rndf_point_at_wp (
00200 rndf_t::waypoint_id_t const &wp_id_);
00201
00202 rndf_point_t* rndf_point_at_wp (unsigned sid_, unsigned lid_,
00203 unsigned wid_);
00204
00205
00206 rndf_point_t* active_rndf_point_on_or_before (
00207 unsigned sid_, unsigned lid_, unsigned wid_);
00208
00209 rndf_point_t* active_rndf_point_on_or_after (
00210 unsigned sid_, unsigned lid_, unsigned wid_);
00211
00212 rndf_point_t* active_rndf_point_before (rndf_point_t *rp_);
00213 rndf_point_t* active_rndf_point_after (rndf_point_t *rp_);
00214
00215 rndf_point_t* active_rndf_point_on_or_before (
00216 rndf_point_t *rp_);
00217
00218 rndf_point_t* active_rndf_point_before (
00219 double x_, double y_,
00220 rndf_t::waypoint_id_t const &before_wp_id);
00221
00222
00223 private:
00224
00225 class blocked_edge_t
00226 {
00227 double m_tstamp_blocked;
00228 double m_orig_cost;
00229 graph_node_t *m_src_vertex;
00230 graph_node_t *m_des_vertex;
00231
00232 public:
00233 blocked_edge_t (
00234 double tstamp_,
00235 double orig_cost_,
00236 graph_node_t *src_vertex_,
00237 graph_node_t *des_vertex_) :
00238 m_tstamp_blocked (tstamp_),
00239 m_orig_cost (orig_cost_),
00240 m_src_vertex (src_vertex_),
00241 m_des_vertex (des_vertex_)
00242 {
00243 }
00244 graph_node_t* const get_src_vertex ()
00245 {return m_src_vertex;}
00246 graph_node_t* const get_des_vertex ()
00247 {return m_des_vertex;}
00248 };
00249
00250 std::deque<blocked_edge_t> m_blocked_edges;
00251 unsigned block_index (
00252 graph_node_t const *src_vertex_,
00253 graph_node_t const *des_vertex_);
00254 bool unset_first_blockage ();
00255
00256 rndf_point_t* create_rndf_point (rndf_t const *rndf_,
00257 rndf_t::waypoint_id_t const &wp_id);
00258
00259 rndf_point_t* create_rndf_point (rndf_t const *rndf_,
00260 unsigned sid_, unsigned lid_,
00261 unsigned wid_);
00262 rndf_point_t* insert_graph_node (unsigned sid_, unsigned lid_,
00263 unsigned wid_,
00264 double x_, double y_);
00265
00266 rndf_point_t* terminate_road_at (unsigned sid_, unsigned lid_,
00267 unsigned wid_, double x_,
00268 double y_);
00269
00270 rndf_point_t* start_road_at (unsigned sid_, unsigned lid_,
00271 unsigned wid_, double x_, double y_);
00272
00273 rndf_point_t* already_added_inter_rp_for_blk (
00274 unsigned sid_, unsigned lid_, unsigned wid_,
00275 double x_, double y_);
00276
00277 void move_existing_inter_rp (rndf_point_t *blk_rp,
00278 unsigned wid_, double x_, double y_);
00279
00280 bool get_other_end_inter_rp (rndf_point_t *rp_,
00281 unsigned other_lid_,
00282 rndf_point_t* &neigh_rp_,
00283 rndf_point_t* &follow_rp_);
00284
00285 void print_mission (mission_plan_t const &plan_);
00286
00287
00288 public:
00289 void unset_all_blockages ();
00290
00291 void set_unblocked_till (rndf_point_t *wp_id_1_,
00292 rndf_point_t *wp_id_2_);
00293
00296 bool set_blocked (rndf_point_t *wp_id_1_, rndf_point_t *wp_id_2_);
00297
00300 bool get_plan (rndf_point_t *start_, rndf_point_t *end_,
00301 mission_plan_t &path_);
00302 void print_graph ()
00303 { m_graph.print_graph (); }
00304
00305 };
00306 };
00307
00308
00309 #endif