00001
00002
00003
00004 #ifndef CAJUN_STATE_MACHINE_H
00005 #define CAJUN_STATE_MACHINE_H
00006
00007 #include "base_state_machine.H"
00008 #include "simple_states.H"
00009 #include "task_plan_handler.H"
00010
00011 #include "world_state.H"
00012 #include "rndf.H"
00013 #include "task_plan_handler.H"
00014 #include "mission_handler.H"
00015
00016 #include "uc_planner_param.H"
00017
00018 namespace cajun
00019 {
00020 class base_state_machine_t;
00021
00022 class state_machine_t
00023 {
00024
00025 bool m_bot_stop;
00026
00027
00028 double m_bot_stop_time;
00029
00030 base_state_machine_t *m_state;
00031
00032 task_plan_handler_t *m_tp_handler;
00033 mission_handler_t *m_mission_handler;
00034
00035 tp_plan_t *m_tp_plan;
00036
00037 world_state_t *m_ws;
00038 rndf_t const *m_rndf;
00039 mdf_t const *m_mdf;
00040
00041
00042
00043
00044
00045
00046 bool m_tp_blocked;
00047
00048 blocked_lane_data_t m_blk_data;
00049 unsigned m_blk_tp_ind;
00050
00051
00052 unsigned m_path_blk_ind;
00053
00054 unsigned m_LA_tp_ind;
00055 unsigned m_LA_path_ind;
00056
00057 double m_LA_blk_x;
00058 double m_LA_blk_y;
00059
00060 unsigned m_LA_blk_sid;
00061 unsigned m_LA_blk_lid;
00062 unsigned m_LA_blk_wid;
00063
00064 const uc_planner_param_t *m_uc_param;
00065 public:
00066 state_machine_t (task_plan_handler_t *tp_handler_,
00067 mission_handler_t *mission_handler_,
00068 tp_plan_t *tp_plan_, world_state_t *ws_,
00069 rndf_t const *rndf_, mdf_t const *mdf_);
00070
00071 bool update_state ();
00072
00073
00074
00075
00076
00077
00078 bool is_bot_stopped () const { return m_bot_stop;}
00079
00080
00081 bool lane_blocked () const;
00082
00083 void tp_blocked (blocked_lane_data_t const &blk_data_,
00084 unsigned blk_tp_ind_, unsigned path_blk_ind_,
00085 unsigned LA_tp_ind_, unsigned LA_path_ind_);
00086
00087 bool active_TP_blocked () const;
00088 bool tp_blocked_is_LF () const;
00089
00090
00091 bool drove_to_blk_safety_distance () const;
00092
00093 bool blk_before_stop_intersection () const;
00094
00095 bool blk_after_stop_intersection () const;
00096
00097 bool blk_at_intersection () const;
00098
00099
00100 bool blk_in_safety_region () const;
00101
00102 bool blk_just_before_stop_intersection () const;
00103
00104
00105 bool no_blockage () const;
00106
00107
00108 bool completed_CL () const;
00109
00110 bool completed_PL () const;
00111
00112 bool completed_UT () const;
00113
00114 bool lane_for_CL (unsigned &change_lid_) const;
00115
00116 bool passing_lane_exist (unsigned &passing_lid_) const;
00117
00118 bool enough_passing_lane_exist (unsigned passing_lid_) const;
00119
00120 bool passing_lane_blocked (unsigned passing_lid_) const;
00121
00122 bool enough_uturn_region (unsigned passing_lid_) const;
00123
00124 bool uturn_region_blocked (unsigned lane_id_) const;
00125
00126 bool uturn_takes_to_next_checkpoint (unsigned passing_lid_) const;
00127
00128
00129
00130 void change_lane ();
00131
00132 void pass_lane ();
00133
00134 bool set_road_blocked ();
00135
00136 void uturn_lane ();
00137 bool nudge_path ()
00138 { return m_uc_param->m_nudge_path;}
00139 private:
00140 void update_bot_stopped ();
00141
00142
00143 bool changing_lane_on_one_side (
00144 unsigned sid_, unsigned start_lid_, unsigned end_lid_,
00145 int del_lid_, double x_, double y_, unsigned &best_lid_,
00146 rndf_t::lane_t::direction_t direction_)
00147 const ;
00148
00149
00150 bool switch_lane_possible (
00151 unsigned sid_, unsigned org_lid_, unsigned new_lid_,
00152 double x_, double y_, double &ch_x_, double &ch_y) const;
00153
00154
00155 void create_new_state (state_machine_id_t state_id_);
00156
00157 bool rndf_point_after_uturn (
00158 rndf_point_t* &start_wp_id,
00159 unsigned sid_, unsigned new_lid, double x_, double y_)
00160 const;
00161
00162 void point_after_blk (unsigned &aft_blk_sid_,
00163 unsigned &aft_blk_lid_,
00164 unsigned &aft_blk_wid_,
00165 double &aft_blk_x_, double &aft_blk_y_);
00166
00167 void start_new_mission_from (rndf_point_t *start_rp_);
00168
00169
00170 };
00171 };
00172
00173
00174
00175 #endif