ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
setpointrequestswath.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ß - simple conversion from SetPointRequest to OccupancyCylinderTree
13  ********************************************************************************/
14 #pragma once
17 #include <adore/mad/adoremath.h>
18 
19 
20 namespace adore
21 {
22 namespace fun
23 {
24 
26 {
27 private:
28  double l_;
29  double w_;
30  double p_;
32  double lat_error_;
33  double lon_error_;
34  double duration_;
35  double a_e_;
36 public:
37  void setL(double value){l_=value;}
38  void setW(double value){w_=value;}
39  void setP(double value){p_=value;}
40  void setLatPrecision(double value){lat_precision_=value;}
41  void setLatError(double value){lat_error_=value;}
42  void setLonError(double value){lon_error_=value;}
43  void setDuration(double value){duration_=value;}
44  void setAccelerationErrorSlow(double value){a_e_=value;}
45  SetPointRequestSwath(double l,double w,double p,double lat_precision,double lat_error=0.0,double lon_error=0.0)
46  :l_(l),w_(w),p_(p),lat_precision_(lat_precision),lat_error_(lat_error),lon_error_(lon_error),duration_(10.0),a_e_(0.0){}
47 
55  void append_cylinder_swath_linear(const SetPointRequest& spr, adore::mad::OccupancyCylinderTree& prediction,bool terminal=false)
56  {
57  const double b = w_*0.5 + lat_error_;
58  const double r0 = b+lat_precision_;
59  const double ds = 2.0 * std::sqrt(r0*r0-b*b);
60  int n = spr.setPoints.size();
64  path.getData().set_size( 4 + 1, n + 2 );
65  rear_end.getData().set_size( 1 + 1, n );
66  front_end.getData().set_size( 1 + 1, n );
67  //set initial path point at rear end of vehicle at t0
68  double cpsi = std::cos(spr.setPoints[0].x0ref.getPSI());
69  double spsi = std::sin(spr.setPoints[0].x0ref.getPSI());
70  path.getData()(0,0) = -p_ - lon_error_;//s0
71  path.getData()(1,0) = cpsi * (-p_ - lon_error_) + spr.setPoints[0].x0ref.getX();//x0
72  path.getData()(2,0) = spsi * (-p_ - lon_error_) + spr.setPoints[0].x0ref.getY();//y0
73  path.getData()(3,0) = spr.setPoints[0].tStart;//t0
74  //set second path point at reference point of vehicle at t0
75  path.getData()(0,1) = 0.0;//s1
76  path.getData()(1,1) = spr.setPoints[0].x0ref.getX();//x1
77  path.getData()(2,1) = spr.setPoints[0].x0ref.getY();//y1
78  path.getData()(3,1) = spr.setPoints[0].tStart;//t1
79  for(int i=1;i<n;i++)
80  {
81  path.getData()(1,i+1) = spr.setPoints[i].x0ref.getX();//xi
82  path.getData()(2,i+1) = spr.setPoints[i].x0ref.getY();;//yi
83  path.getData()(3,i+1) = spr.setPoints[i].tStart;//ti
84  double dx = path.getData()(1,i+1)-path.getData()(1,i);
85  double dy = path.getData()(2,i+1)-path.getData()(2,i);
86  path.getData()(0,i+1) = std::max(path.getData()(0,i) + std::sqrt(dx*dx+dy*dy),path.getData()(0,i)+0.0000001);
87  }
88  cpsi = std::cos(spr.setPoints[n-1].x0ref.getPSI());
89  spsi = std::sin(spr.setPoints[n-1].x0ref.getPSI());
90  //set last path point at at front end of vehicle at tend
91  path.getData()(0,n+1) = path.getData()(0,n) + l_ -p_ + lon_error_;//send
92  path.getData()(1,n+1) = cpsi * (l_ -p_ + lon_error_) + spr.setPoints[n-1].x0ref.getX();//xend
93  path.getData()(2,n+1) = spsi * (l_ -p_ + lon_error_) + spr.setPoints[n-1].x0ref.getY();//yend
94  path.getData()(3,n+1) = spr.setPoints[n-1].tStart;//tend
95  //compute the time bounds for front end and rear end
96  for(int i=0;i<n;i++)
97  {
98  rear_end.getData()(0,i) = path.getData()(0,i+1) - p_ - lon_error_;
99  rear_end.getData()(1,i) = path.getData()(3,i+1);
100  front_end.getData()(0,i) = path.getData()(0,i+1) - p_ + l_ + lon_error_;
101  front_end.getData()(1,i) = path.getData()(3,i+1);
102  if( i > 0 )
103  {
104  double t = path.getData()(3,i+1)-path.getData()(3,0);
105  double s_e = 0.5 * a_e_ * t * t;
106  //apply position error due to breaking error
107  rear_end.getData()(0,i) = std::max(rear_end.getData()(0,i) + s_e,rear_end.getData()(0,i-1)+0.01);//do not move backwards
108  }
109  }
110  //extend the lower bound in time, if a terminating maneuver
111  if(terminal)
112  {
113  //if the trajectory terminates at endpoint, prolong standstill until maximum duration
114  rear_end.getData()(1,n-1) = std::max(rear_end.getData()(1,n-1),rear_end.getData()(1,0)+duration_);
115  }
116 
117  double s0 = rear_end.limitLo() + ds * 0.5;
118  double s1 = front_end.limitHi() - ds * 0.5;
119  s1 = s0 + std::ceil((s1-s0)/ds)*ds + ds * 0.00001;
120  // std::cout<<"s-interval=["<<s0<<";"<<s1<<"]"<<std::endl;
121  for(double s = s0;s<=s1;s += ds)
122  {
123  double r = r0;//@TODO: recompute r to account for body rotation
124  auto pos = path.f(adore::mad::bound(path.limitLo(),s,path.limitHi()));
125  double t0i = front_end.f(adore::mad::bound(front_end.limitLo(),s-r,front_end.limitHi()));
126  double t1i = rear_end.f(adore::mad::bound(rear_end.limitLo(),s+r,rear_end.limitHi()));
127  prediction.insert(adore::mad::OccupancyCylinder(r,pos(0),pos(1),t0i,t1i));
128  }
129 
130  }
131 
132 };
133 
134 }
135 }
Definition: setpointrequestswath.h:26
void setL(double value)
Definition: setpointrequestswath.h:37
void append_cylinder_swath_linear(const SetPointRequest &spr, adore::mad::OccupancyCylinderTree &prediction, bool terminal=false)
Definition: setpointrequestswath.h:55
void setLatPrecision(double value)
Definition: setpointrequestswath.h:40
void setP(double value)
Definition: setpointrequestswath.h:39
void setLonError(double value)
Definition: setpointrequestswath.h:42
double lat_error_
Definition: setpointrequestswath.h:32
double p_
Definition: setpointrequestswath.h:30
double lat_precision_
Definition: setpointrequestswath.h:31
SetPointRequestSwath(double l, double w, double p, double lat_precision, double lat_error=0.0, double lon_error=0.0)
Definition: setpointrequestswath.h:45
double l_
Definition: setpointrequestswath.h:28
void setAccelerationErrorSlow(double value)
Definition: setpointrequestswath.h:44
double w_
Definition: setpointrequestswath.h:29
double a_e_
Definition: setpointrequestswath.h:35
double lon_error_
Definition: setpointrequestswath.h:33
void setDuration(double value)
Definition: setpointrequestswath.h:43
void setW(double value)
Definition: setpointrequestswath.h:38
double duration_
Definition: setpointrequestswath.h:34
void setLatError(double value)
Definition: setpointrequestswath.h:41
Definition: setpointrequest.h:35
std::vector< SetPoint > setPoints
Definition: setpointrequest.h:38
virtual CT f(DT x) const override
Definition: llinearpiecewisefunction.h:251
virtual DT limitLo() const override
Definition: llinearpiecewisefunction.h:264
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
virtual DT limitHi() const override
Definition: llinearpiecewisefunction.h:259
Definition: occupancycylinder.h:84
void insert(const VolumeType &volume)
Definition: vectorbasedvolumetree.h:90
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
T bound(T lb, T value, T ub)
Definition: adoremath.h:569
interval< T > sin(interval< T > x)
Definition: intervalarithmetic.h:204
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
w
Definition: adore_set_pose.py:40
r
Definition: adore_suppress_lanechanges.py:209
Definition: areaofeffectconverter.h:20
Definition: occupancycylinder.h:25