LocalPlannerH.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /// \file LocalPlannerH.h
  2. /// \brief OpenPlanner's local planing functions combines in one process, used in simulation vehicle and OpenPlanner old implementation like dp_planner node.
  3. /// \author Hatem Darweesh
  4. /// \date Dec 14, 2016
  5. #ifndef LOCALPLANNERH_H_
  6. #define LOCALPLANNERH_H_
  7. #include "BehaviorStateMachine.h"
  8. #include "PlannerCommonDef.h"
  9. #include "RoadNetwork.h"
  10. #include "TrajectoryCosts.h"
  11. #define AVOIDANCE_SPEED_FACTOR 0.75
  12. namespace PlannerHNS
  13. {
  14. class LocalPlannerH
  15. {
  16. public:
  17. WayPoint state;
  18. CAR_BASIC_INFO m_CarInfo;
  19. ControllerParams m_ControlParams;
  20. std::vector<GPSPoint> m_CarShapePolygon;
  21. std::vector<WayPoint> m_Path;
  22. std::vector<WayPoint> m_OriginalLocalPath;
  23. std::vector<std::vector<WayPoint> > m_TotalPath;
  24. std::vector<std::vector<WayPoint> > m_TotalOriginalPath;
  25. std::vector<DetectedObject> m_PredictedTrajectoryObstacles;
  26. int m_iCurrentTotalPathId;
  27. int m_iSafeTrajectory;
  28. double m_InitialFollowingDistance;
  29. // int m_iGlobalPathPrevID;
  30. // std::vector<std::vector<WayPoint> > m_PredictedPath;
  31. std::vector<std::vector<std::vector<WayPoint> > > m_RollOuts;
  32. std::string carId;
  33. Lane* pLane;
  34. double m_SimulationSteeringDelayFactor; //second , time that every degree change in the steering wheel takes
  35. timespec m_SteerDelayTimer;
  36. double m_PredictionTime;
  37. double m_CostCalculationTime;
  38. double m_BehaviorGenTime;
  39. double m_RollOutsGenerationTime;
  40. int m_PrevBrakingWayPoint;
  41. BehaviorStateMachine* m_pCurrentBehaviorState;
  42. ForwardState * m_pGoToGoalState;
  43. StopState* m_pStopState;
  44. WaitState* m_pWaitState;
  45. InitState* m_pInitState;
  46. MissionAccomplishedState* m_pMissionCompleteState;
  47. GoalState* m_pGoalState;
  48. FollowState* m_pFollowState;
  49. SwerveState* m_pAvoidObstacleState;
  50. TrafficLightStopState* m_pTrafficLightStopState;
  51. TrafficLightWaitState* m_pTrafficLightWaitState;
  52. StopSignStopState* m_pStopSignStopState;
  53. StopSignWaitState* m_pStopSignWaitState;
  54. TrajectoryCosts m_TrajectoryCostsCalculatotor;
  55. //for debugging
  56. std::vector<WayPoint> m_SampledPoints;
  57. void InitBehaviorStates();
  58. void ReInitializePlanner(const WayPoint& start_pose);
  59. void SetSimulatedTargetOdometryReadings(const double& velocity_d, const double& steering_d, const SHIFT_POS& shift_d)
  60. {
  61. m_CurrentVelocityD = velocity_d;
  62. m_CurrentSteeringD = steering_d;
  63. m_CurrentShiftD = shift_d;
  64. }
  65. double GetSimulatedVelocity()
  66. {
  67. return m_CurrentVelocity;
  68. }
  69. double GetSimulatedSteering()
  70. {
  71. return m_CurrentSteering;
  72. }
  73. double GetSimulatedShift()
  74. {
  75. return m_CurrentShift;
  76. }
  77. //For Simulation
  78. WayPoint m_OdometryState;
  79. double m_CurrentVelocity, m_CurrentVelocityD; //meter/second
  80. double m_CurrentSteering, m_CurrentSteeringD; //radians
  81. SHIFT_POS m_CurrentShift , m_CurrentShiftD;
  82. double m_CurrentAccSteerAngle; //degrees steer wheel range
  83. double m_CurrentAccVelocity; // kilometer/hour
  84. //std::vector<TrafficLight> m_TrafficLights;
  85. UtilityHNS::PIDController m_pidVelocity;
  86. UtilityHNS::PIDController m_pidStopping;
  87. public:
  88. LocalPlannerH();
  89. virtual ~LocalPlannerH();
  90. void Init(const ControllerParams& ctrlParams, const PlanningParams& params, const CAR_BASIC_INFO& carInfo);
  91. void InitPolygons();
  92. void FirstLocalizeMe(const WayPoint& initCarPos);
  93. void LocalizeMe(const double& dt); // in seconds
  94. void UpdateState(const VehicleState& state, const bool& bUseDelay = false);
  95. void CalculateImportantParameterForDecisionMaking(const VehicleState& car_state,
  96. const int& goalID, const bool& bEmergencyStop, const vector<TrafficLight>& detectedLights,
  97. const TrajectoryCost& bestTrajectory);
  98. BehaviorState DoOneStep(
  99. const double& dt,
  100. const VehicleState& state,
  101. const std::vector<DetectedObject>& obj_list,
  102. const int& goalID,
  103. RoadNetwork& map,
  104. const bool& bEmergencyStop,
  105. const std::vector<TrafficLight>& trafficLight,
  106. const bool& bLive = false);
  107. void SimulateOdoPosition(const double& dt, const VehicleState& vehicleState);
  108. private:
  109. //Obstacle avoidance functionalities
  110. // bool CalculateObstacleCosts(RoadNetwork& map, const VehicleState& vstatus, const std::vector<DetectedObject>& obj_list);
  111. //
  112. // double PredictTimeCostForTrajectory(std::vector<WayPoint>& path,
  113. // const VehicleState& vstatus,
  114. // const WayPoint& currState);
  115. //
  116. // void PredictObstacleTrajectory(RoadNetwork& map,
  117. // const WayPoint& pos,
  118. // const double& predTime,
  119. // std::vector<std::vector<WayPoint> >& paths);
  120. //
  121. // bool CalculateIntersectionVelocities(std::vector<WayPoint>& path,
  122. // std::vector<std::vector<WayPoint> >& predctedPath,
  123. // const DetectedObject& obj);
  124. bool GetNextTrafficLight(const int& prevTrafficLightId, const std::vector<TrafficLight>& trafficLights, TrafficLight& trafficL);
  125. void UpdateCurrentLane(RoadNetwork& map, const double& search_distance);
  126. bool SelectSafeTrajectoryAndSpeedProfile(const VehicleState& vehicleState);
  127. BehaviorState GenerateBehaviorState(const VehicleState& vehicleState);
  128. void TransformPoint(const WayPoint& refPose, GPSPoint& p);
  129. void AddAndTransformContourPoints(const DetectedObject& obj, std::vector<WayPoint>& contourPoints);
  130. double UpdateVelocityDirectlyToTrajectory(const BehaviorState& beh, const VehicleState& CurrStatus, const double& dt);
  131. void ExtractHorizonAndCalculateRecommendedSpeed();
  132. bool NoWayTest(const double& min_distance, const int& iGlobalPathIndex);
  133. PlannerHNS::PlanningParams m_params;
  134. };
  135. } /* namespace PlannerHNS */
  136. #endif /* LOCALPLANNERH_H_ */