ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
monitor0.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial implementation
13  ********************************************************************************/
14 
15 #pragma once
16 
17 #include <adore/env/afactory.h>
18 #include <adore/sim/afactory.h>
19 #include <adore/params/afactory.h>
20 #include <unordered_map>
21 
22 
23 namespace adore
24 {
25  namespace apps
26  {
31  {
32  private:
36  public:
41  ):
42  goal_reader_(goal_reader),
43  position_reader_(position_reader),
44  proposition_writer_(proposition_writer)
45  {}
46  void run()
47  {
49  {
52  goal_reader_->getData(nav_goal);
54  double dx = nav_goal.target_.x_ - pos.getX();
55  double dy = nav_goal.target_.y_ - pos.getY();
56  double dz = nav_goal.target_.z_ - pos.getZ();
57  double d = 50.0;//m
58  adore::env::Proposition p("NEAR_GOAL",dx*dx+dy*dy+dz*dz<d*d);
60  }
61  }
62  };
67  {
68  private:
71  std::unordered_map<adore::env::traffic::Participant::TTrackingID,adore::env::traffic::Participant> participants_;
73  public:
76  adore::env::AFactory::TPropositionWriter* proposition_writer,
78  ):
79  participant_feed_(participant_feed),
80  proposition_writer_(proposition_writer),
81  egoID_(egoID)
82  {}
83  void run()
84  {
85  bool changed = false;
86  bool in_collision = false;
87  while(participant_feed_->hasNext())
88  {
91  participants_.emplace(p.getTrackingID(), p).first->second = p;
92  changed = true;
93  }
94  if(changed)
95  {
96  auto ego_it = participants_.find(egoID_);
97  if(ego_it!=participants_.end())
98  {
99  auto& ego = ego_it->second;
100  auto& egopos = ego.getCenter();
101  const double Re = std::sqrt(ego.getWidth()*ego.getWidth()+ego.getLength()*ego.getLength())*0.5;
102  for(auto it:participants_)
103  {
104  if(it.first!=egoID_)
105  {
106  auto& other = it.second;
107  auto& otherpos = other.getCenter();
108  const double Ro = std::sqrt(other.getWidth()*other.getWidth()+other.getLength()*other.getLength())*0.5;
109  auto d = otherpos-egopos;
110  if(std::sqrt(d(0)*d(0)+d(1)*d(1)+d(2)*d(2))-Re-Ro<0.0)
111  {
112  //@TODO: separating axis test
113  in_collision = true;
114  break;
115  }
116  }
117  }
118  adore::env::Proposition p("IN_COLLISION",in_collision);
120  }
121  }
122  }
123  };
124 
125  class Monitor0
126  {
127  private:
134  public:
136  adore::env::AFactory* envFactory,
137  adore::sim::AFactory* simFactory,
138  int simulationID
139  )
140  {
141  participant_feed_ = simFactory->getParticipantFeed();
143  goal_reader_ = envFactory->getNavigationGoalReader();
147  }
148  virtual ~Monitor0()
149  {
150  delete goalAttainmentMonitor_;
151  delete collisionMonitor_;
152  }
153  void run()
154  {
157  }
158  };
159  }
160 }
A class, which monitors for collisions between ego and other objects.
Definition: monitor0.h:67
adore::env::AFactory::TPropositionWriter * proposition_writer_
Definition: monitor0.h:70
std::unordered_map< adore::env::traffic::Participant::TTrackingID, adore::env::traffic::Participant > participants_
Definition: monitor0.h:71
void run()
Definition: monitor0.h:83
CollisionMonitor(adore::sim::AFactory::TParticipantFeed *participant_feed, adore::env::AFactory::TPropositionWriter *proposition_writer, adore::env::traffic::Participant::TTrackingID egoID)
Definition: monitor0.h:74
adore::env::traffic::Participant::TTrackingID egoID_
Definition: monitor0.h:72
adore::sim::AFactory::TParticipantFeed * participant_feed_
Definition: monitor0.h:69
A class, which monitors distance between vehicle and goal.
Definition: monitor0.h:31
adore::env::AFactory::TPropositionWriter * proposition_writer_
Definition: monitor0.h:35
void run()
Definition: monitor0.h:46
adore::env::AFactory::TVehicleMotionStateReader * position_reader_
Definition: monitor0.h:34
adore::env::AFactory::TNavigationGoalReader * goal_reader_
Definition: monitor0.h:33
GoalAttainmentMonitor(adore::env::AFactory::TNavigationGoalReader *goal_reader, adore::env::AFactory::TVehicleMotionStateReader *position_reader, adore::env::AFactory::TPropositionWriter *proposition_writer)
Definition: monitor0.h:37
Definition: monitor0.h:126
adore::env::AFactory::TVehicleMotionStateReader * position_reader_
Definition: monitor0.h:131
Monitor0(adore::env::AFactory *envFactory, adore::sim::AFactory *simFactory, int simulationID)
Definition: monitor0.h:135
GoalAttainmentMonitor * goalAttainmentMonitor_
Definition: monitor0.h:132
adore::env::AFactory::TPropositionWriter * proposition_writer_
Definition: monitor0.h:129
adore::env::AFactory::TNavigationGoalReader * goal_reader_
Definition: monitor0.h:130
adore::sim::AFactory::TParticipantFeed * participant_feed_
Definition: monitor0.h:128
void run()
Definition: monitor0.h:153
virtual ~Monitor0()
Definition: monitor0.h:148
CollisionMonitor * collisionMonitor_
Definition: monitor0.h:133
abstract factory for adore::env communication
Definition: afactory.h:41
virtual TPropositionWriter * getPropositionWriter()=0
virtual TNavigationGoalReader * getNavigationGoalReader()=0
virtual TVehicleMotionStateReader * getVehicleMotionStateReader()=0
virtual void getNext(T &value)=0
virtual bool hasNext() const =0
virtual void getData(T &value)=0
virtual bool hasData() const =0
Definition: com_patterns.h:97
virtual void write(const T &value)=0
abstract factory for adore::sim communication
Definition: afactory.h:43
virtual TParticipantFeed * getParticipantFeed()=0
get state updates from all vehicles
Definition: areaofeffectconverter.h:20
A logical proposition, with a possible timeout for the information.
Definition: proposition.h:27
This struct holds the motion state of the vehicle in 9d.
Definition: vehiclemotionstate9d.h:39
double getX() const
Get the x-coordinate.
Definition: vehiclemotionstate9d.h:54
double getY() const
Get the y-coordinate.
Definition: vehiclemotionstate9d.h:60
double getZ() const
Get the z-coordinate.
Definition: vehiclemotionstate9d.h:66
Struct for representing a participant in traffic.
Definition: participant.h:30
TTrackingID getTrackingID() const
Definition: participant.h:109
int TTrackingID
Definition: participant.h:32
Definition: navigationgoal.h:26
adore::mad::GlobalPosition target_
Definition: navigationgoal.h:28
double z_
Definition: globalposition.h:23
double x_
Definition: globalposition.h:23
double y_
Definition: globalposition.h:23