LCOV - code coverage report
Current view: top level - src/situation - RssUnstructuredSceneChecker.hpp (source / functions) Hit Total Coverage
Test: ad_rss Lines: 2 2 100.0 %
Date: 2024-04-23 14:35:54 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2020-2021 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: LGPL-2.1-only
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : 
       9                 :            : /**
      10                 :            :  * @file
      11                 :            :  */
      12                 :            : 
      13                 :            : #pragma once
      14                 :            : 
      15                 :            : #include <cstdint>
      16                 :            : #include <map>
      17                 :            : #include "ad/rss/situation/Situation.hpp"
      18                 :            : #include "ad/rss/state/RssState.hpp"
      19                 :            : #include "ad/rss/unstructured/Geometry.hpp"
      20                 :            : #include "ad/rss/world/TimeIndex.hpp"
      21                 :            : 
      22                 :            : /*!
      23                 :            :  * @brief namespace ad
      24                 :            :  */
      25                 :            : namespace ad {
      26                 :            : /*!
      27                 :            :  * @brief namespace rss
      28                 :            :  */
      29                 :            : namespace rss {
      30                 :            : /*!
      31                 :            :  * @brief namespace situation
      32                 :            :  */
      33                 :            : namespace situation {
      34                 :            : 
      35                 :            : /**
      36                 :            :  * @brief Class to check whether an unstructured scene is safe and to determine the proper response for the situation
      37                 :            :  *
      38                 :            :  * Note: Implements the checks and responses given by the definitions 19-22 of the RSS paper (arXiv:1708.06374v6)
      39                 :            :  *
      40                 :            :  * Class performs required check to if situation is safe
      41                 :            :  * Class will maintain the previous state of the situation in order to provide the proper response.
      42                 :            :  */
      43                 :            : class RssUnstructuredSceneChecker
      44                 :            : {
      45                 :            : public:
      46                 :            :   enum class SafeState
      47                 :            :   {
      48                 :            :     safe,
      49                 :            :     unsafeBrakeOtherHasPrio,
      50                 :            :     unsafeBrakeEgoHasPrio,
      51                 :            :     unsafeBrakeBoth
      52                 :            :   };
      53                 :            : 
      54                 :            :   enum class DrivingMode
      55                 :            :   {
      56                 :            :     DriveAway,
      57                 :            :     ContinueForward,
      58                 :            :     Brake,
      59                 :            :     Invalid
      60                 :            :   };
      61                 :            :   /**
      62                 :            :    * @brief Constructor
      63                 :            :    */
      64                 :        712 :   RssUnstructuredSceneChecker() = default;
      65                 :            : 
      66                 :            :   /**
      67                 :            :    * @brief Destructor
      68                 :            :    */
      69                 :        712 :   ~RssUnstructuredSceneChecker() = default;
      70                 :            : 
      71                 :            :   /**
      72                 :            :    * @brief Calculate safety checks and determine required rssState for unstructured situations
      73                 :            :    *
      74                 :            :    * @param[in]  timeIndex the time index of the situation
      75                 :            :    * @param[in]  situation situation to analyze
      76                 :            :    * @param[out] egoStateInfo  rssState of the ego vehicle (Be aware: only calculated/updated once per timestep)
      77                 :            :    * @param[out] rssState  rssState of the vehicle
      78                 :            :    *
      79                 :            :    * @returns false if a failure occurred during calculations, true otherwise
      80                 :            :    */
      81                 :            :   bool calculateRssStateUnstructured(world::TimeIndex const &timeIndex,
      82                 :            :                                      Situation const &situation,
      83                 :            :                                      state::UnstructuredSceneStateInformation &egoStateInfo,
      84                 :            :                                      state::RssState &rssState);
      85                 :            : 
      86                 :            : private:
      87                 :            :   /**
      88                 :            :    * @brief Calculate the unstructured scene state info
      89                 :            :    *
      90                 :            :    * @param[in]  egoState state of the vehicle
      91                 :            :    * @param[out] stateInfo the calculated state info
      92                 :            :    *
      93                 :            :    * @returns false if a failure occurred during calculations, true otherwise
      94                 :            :    */
      95                 :            :   bool calculateUnstructuredSceneStateInfo(situation::VehicleState const &egoState,
      96                 :            :                                            state::UnstructuredSceneStateInformation &stateInfo) const;
      97                 :            : 
      98                 :            :   /**
      99                 :            :    * @brief Calculate the unstructured scene state
     100                 :            :    *
     101                 :            :    * @param[in]  situation situation to analyze
     102                 :            :    * @param[in]  egoStateInfo the trajectory sets of the ego vehicle
     103                 :            :    * @param[in]  otherStateInfo the trajectory sets of the other traffic participant
     104                 :            :    * @param[out] rssState the calculated rss state
     105                 :            :    *
     106                 :            :    * @returns false if a failure occurred during calculations, true otherwise
     107                 :            :    */
     108                 :            :   bool calculateState(Situation const &situation,
     109                 :            :                       state::UnstructuredSceneStateInformation const &egoStateInfo,
     110                 :            :                       state::UnstructuredSceneStateInformation const &otherStateInfo,
     111                 :            :                       state::UnstructuredSceneRssState &rssState);
     112                 :            : 
     113                 :            :   /**
     114                 :            :    * @brief calculate the angle range that is allowed to drive away
     115                 :            :    *
     116                 :            :    * @param[in]  egoVehicleLocation the location of the ego vehicle
     117                 :            :    * @param[in]  otherVehicleLocation the location of the other vehicle
     118                 :            :    * @param[in]  maxAllowedAngleWhenBothStopped the maximum angle for calculation
     119                 :            :    * @param[out] range resulting heading range
     120                 :            :    *
     121                 :            :    * @returns false if a failure occurred during calculations, true otherwise
     122                 :            :    */
     123                 :            :   bool calculateDriveAwayAngle(unstructured::Point const &egoVehicleLocation,
     124                 :            :                                unstructured::Point const &otherVehicleLocation,
     125                 :            :                                physics::Angle const &maxAllowedAngleWhenBothStopped,
     126                 :            :                                state::HeadingRange &range) const;
     127                 :            : 
     128                 :            :   /**
     129                 :            :    * @brief typedef for the mapping of situation id to the corresponding otherMustBrake value before the danger
     130                 :            :    * threshold time
     131                 :            :    */
     132                 :            :   typedef std::map<situation::SituationId, bool> OtherMustBrakeStateBeforeDangerThresholdTimeMap;
     133                 :            : 
     134                 :            :   /**
     135                 :            :    * @brief the state of each situation before the danger threshold time
     136                 :            :    *
     137                 :            :    * Needs to be stored to check which is the required behaviour to solve the situation
     138                 :            :    */
     139                 :            :   OtherMustBrakeStateBeforeDangerThresholdTimeMap mOtherMustBrakeStatesBeforeDangerThresholdTime;
     140                 :            : 
     141                 :            :   /**
     142                 :            :    * @brief the new states to be considered in next time step
     143                 :            :    */
     144                 :            :   OtherMustBrakeStateBeforeDangerThresholdTimeMap mNewOtherMustBrakeStatesBeforeDangerThresholdTime;
     145                 :            : 
     146                 :            :   /**
     147                 :            :    * @brief time index of the current processing step
     148                 :            :    * If time index increases we need to update the state maps
     149                 :            :    */
     150                 :            :   world::TimeIndex mCurrentTimeIndex{0u};
     151                 :            : 
     152                 :            :   /**
     153                 :            :    * @brief Store required data for drive away calculations between timesteps
     154                 :            :    */
     155                 :            :   struct DriveAwayState
     156                 :            :   {
     157                 :            :     state::HeadingRange allowedHeadingRange;
     158                 :            :     physics::Distance2D otherPosition;
     159                 :            :   };
     160                 :            : 
     161                 :            :   /**
     162                 :            :    * @brief map to state drive-away data for situations
     163                 :            :    */
     164                 :            :   std::map<situation::SituationId, DriveAwayState> mDriveAwayStateMap;
     165                 :            : };
     166                 :            : 
     167                 :            : } // namespace situation
     168                 :            : } // namespace rss
     169                 :            : } // namespace ad

Generated by: LCOV version 1.14