DecisionMaker.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /// \file DecisionMaker.h
  2. /// \brief Initialize behaviors state machine, and calculate required parameters for the state machine transition conditions
  3. /// \author Hatem Darweesh
  4. /// \date Dec 14, 2016
  5. #ifndef BEHAVIOR_DECISION_MAKER
  6. #define BEHAVIOR_DECISION_MAKER
  7. #include "op_planner/BehaviorStateMachine.h"
  8. #include "op_planner/PlannerCommonDef.h"
  9. #include "op_planner/RoadNetwork.h"
  10. namespace PlannerHNS
  11. {
  12. class DecisionMaker
  13. {
  14. public:
  15. WayPoint state;
  16. CAR_BASIC_INFO m_CarInfo;
  17. ControllerParams m_ControlParams;
  18. std::vector<WayPoint> m_Path;
  19. PlannerHNS::RoadNetwork m_Map;
  20. double m_MaxLaneSearchDistance;
  21. int m_iCurrentTotalPathId;
  22. std::vector<std::vector<WayPoint> > m_RollOuts;
  23. Lane* pLane;
  24. BehaviorStateMachine* m_pCurrentBehaviorState;
  25. StopState* m_pStopState;
  26. WaitState* m_pWaitState;
  27. SwerveStateII* m_pAvoidObstacleState;
  28. TrafficLightStopStateII* m_pTrafficLightStopState;
  29. TrafficLightWaitStateII* m_pTrafficLightWaitState;
  30. ForwardStateII * m_pGoToGoalState;;
  31. InitStateII* m_pInitState;
  32. MissionAccomplishedStateII* m_pMissionCompleteState;
  33. GoalStateII* m_pGoalState;
  34. FollowStateII* m_pFollowState;
  35. StopSignStopStateII* m_pStopSignStopState;
  36. StopSignWaitStateII* m_pStopSignWaitState;
  37. void InitBehaviorStates();
  38. //For Simulation
  39. UtilityHNS::PIDController m_pidVelocity;
  40. UtilityHNS::PIDController m_pidStopping;
  41. UtilityHNS::PIDController m_pidFollowing;
  42. public:
  43. DecisionMaker();
  44. virtual ~DecisionMaker();
  45. void Init(const ControllerParams& ctrlParams, const PlanningParams& params, const CAR_BASIC_INFO& carInfo);
  46. void CalculateImportantParameterForDecisionMaking(const VehicleState& car_state,
  47. const int& goalID, const bool& bEmergencyStop, const std::vector<TrafficLight>& detectedLights,
  48. const TrajectoryCost& bestTrajectory);
  49. void SetNewGlobalPath(const std::vector<std::vector<WayPoint> >& globalPath);
  50. BehaviorState DoOneStep(
  51. const double& dt,
  52. const PlannerHNS::WayPoint currPose,
  53. const PlannerHNS::VehicleState& vehicleState,
  54. const int& goalID,
  55. const std::vector<TrafficLight>& trafficLight,
  56. const TrajectoryCost& tc,
  57. const bool& bEmergencyStop);
  58. protected:
  59. bool GetNextTrafficLight(const int& prevTrafficLightId, const std::vector<TrafficLight>& trafficLights, TrafficLight& trafficL);
  60. void UpdateCurrentLane(const double& search_distance);
  61. bool SelectSafeTrajectory();
  62. BehaviorState GenerateBehaviorState(const VehicleState& vehicleState);
  63. double UpdateVelocityDirectlyToTrajectory(const BehaviorState& beh, const VehicleState& CurrStatus, const double& dt);
  64. bool ReachEndOfGlobalPath(const double& min_distance, const int& iGlobalPathIndex);
  65. std::vector<PlannerHNS::WayPoint> t_centerTrajectorySmoothed;
  66. std::vector<std::vector<WayPoint> > m_TotalOriginalPath;
  67. std::vector<std::vector<WayPoint> > m_TotalPath;
  68. PlannerHNS::PlanningParams m_params;
  69. };
  70. } /* namespace PlannerHNS */
  71. #endif /* BEHAVIOR_DECISION_MAKER */