ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
speedlimit_provider.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  * Thomas Lobig - initial implementation
13  ********************************************************************************/
14 
15 #pragma once
16 #include <adore/params/afactory.h>
19 #include <adore/env/afactory.h>
21 #include <adore/mad/com_patterns.h>
22 #include <string>
23 #include <sstream>
24 #include <vector>
25 #include <iostream>
26 #include <fstream>
27 #include <filesystem>
28 
29 #include "if_plotlab/plot_shape.h"
30 
31 namespace adore
32 {
33  namespace apps
34  {
40  {
41  //TODO vector only for quick prototyping, should be efficient geospatial data structure
42  // using SpeedLimitBundle=adore::env::TSpeedLimitBundle;
44  std::string file_watch_path_;
47 
48  public:
49 
50  SpeedLimitProvider(std::string file_watch_path) : file_watch_path_(file_watch_path)
51  {
54  auto read_result = adore::mad::CsvReader::get_data<double>(file_watch_path);
55 
56  if (read_result.size() % 5 == 0)
57  {
58  int index = 0;
59  int id = 0;
60  adore::env::SpeedLimit datapoint;
61  while(index < read_result.size())
62  {
63  datapoint.value = read_result[index++];
64  datapoint.startX = read_result[index++];
65  datapoint.startY = read_result[index++];
66  datapoint.stopX = read_result[index++];
67  datapoint.stopY = read_result[index++];
68  datapoint.id = id++;
69  limits.push_back(datapoint);
70  }
71  }
72  else
73  {
74  std::cerr << "ERROR speedlimit csv might be corrupted, the count of numbers is not divisible by 5";
75  }
76  }
77 
78  void run()
79  {
81 
82  motion_state_reader_->getData(motion_state);
84 
85  double x = motion_state.getX();
86  double y = motion_state.getY();
87 
88 
89  // TODO might think about caching which speed limit data points were already sent and only send new ones and
90  // maybe resend other less frequently, similar to how the map provider handles borders
91  // adore::env::TSpeedLimitBundle msg;
92 
93  for (auto item : limits)
94  {
95  double abs1 = std::abs(x - item.startX);
96  double abs2 = std::abs(y - item.startY);
97  double abs3 = std::abs(x - item.stopX);
98  double abs4 = std::abs(y - item.stopY);
99 
100  if (((abs1*abs1 + abs2*abs2) < visibilty_radius*visibilty_radius) or ((abs3*abs3 + abs4*abs4) < visibilty_radius*visibilty_radius))
101  {
103  {
104  speed_limit_writer_->write(item);
105  }
106  else
107  {
108  std::cout << "Speed_limit_feed was full, data lost\n";
109  }
110 
111  }
112  }
113  // if (msg.size() > 0)
114  // {
115 
116  // speed_limit_writer_->write(msg);
117  // }
118  }
119  };
120  }
121 }
A node to gather speed limit data and provide it e.g. for laneview computation.
Definition: speedlimit_provider.h:40
adore::env::TSpeedLimitBundle limits
Definition: speedlimit_provider.h:43
adore::env::AFactory::TSpeedLimitWriter * speed_limit_writer_
Definition: speedlimit_provider.h:46
SpeedLimitProvider(std::string file_watch_path)
Definition: speedlimit_provider.h:50
void run()
Definition: speedlimit_provider.h:78
std::string file_watch_path_
Definition: speedlimit_provider.h:44
adore::env::AFactory::TVehicleMotionStateReader * motion_state_reader_
Definition: speedlimit_provider.h:45
virtual TSpeedLimitWriter * getSpeedLimitWriter()=0
virtual TVehicleMotionStateReader * getVehicleMotionStateReader()=0
static adore::env::AFactory * get()
Definition: afactory.h:236
Definition: com_patterns.h:68
virtual void getData(T &value)=0
Definition: com_patterns.h:97
virtual void write(const T &value)=0
virtual bool canWriteMore() const =0
virtual APMapProvider * getMapProvider() const =0
virtual double getVisibiltyRadius() const =0
static adore::params::AFactory * get()
Definition: afactory.h:103
std::vector< SpeedLimit > TSpeedLimitBundle
Definition: speedlimit.h:49
x
Definition: adore_set_goal.py:30
y
Definition: adore_set_goal.py:31
Definition: areaofeffectconverter.h:20
Definition: speedlimit.h:31
double startX
Definition: speedlimit.h:41
double value
Definition: speedlimit.h:40
double stopY
Definition: speedlimit.h:44
TSpeedLimitID id
Definition: speedlimit.h:45
double stopX
Definition: speedlimit.h:43
double startY
Definition: speedlimit.h:42
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