RefValJS_PTP.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
19 
20 inline double sqr(double x)
21 {
22  return x*x;
23 }
24 
25 const double RefValJS_PTP::weigths[] = { 1.5, 1.5, 1.0, 1.0, 0.8, 0.8, 0.7 };
26 
27 
28 RefValJS_PTP::RefValJS_PTP(const std::vector<double>& start, const std::vector<double>& ziel, double v_rad_s, double a_rad_s2)
29 {
30  m_start = start;
31  m_ziel = ziel;
32 
33  m_direction.resize(start.size());
34  for(unsigned int i = 0; i < start.size(); i++)
35  m_direction.at(i) = ziel.at(i) - start.at(i);
36  double max = m_direction.at(0);
37  double min = m_direction.at(0);
38  for(unsigned int i = 0; i < m_direction.size(); i++)
39  {
40  if(max < m_direction.at(i))
41  max = m_direction.at(i);
42  if(min > m_direction.at(i))
43  min = m_direction.at(i);
44  }
45  max = fabs(max);
46  min = fabs(min);
47 
48  //m_length = (max>min)?max:min;
50 
51  m_v_rad_s = v_rad_s;
52  m_a_rad_s2 = a_rad_s2;
53 
54  /* Parameter für Beschl.begrenzte Fahrt: */
55  double a = fabs(m_a_rad_s2);
56  double v = fabs(m_v_rad_s);
57 
58  if (m_length > v*v/a)
59  {
60  // Phase mit konst. Geschw. wird erreicht:
61  m_T1 = m_T3 = v / a;
62  m_T2 = (m_length - v*v/a) / v;
63 
64  // Wegparameter s immer positiv, deswegen keine weitere Fallunterscheidung nötig:
65  m_sv2 = 1.0 / (m_T1 + m_T2);
66  m_sa1 = m_sv2 / m_T1;
67  m_sa3 = -m_sa1;
68  }
69  else {
70  // Phase konst. Geschw. wird nicht erreicht:
71  m_T2 = 0.0;
72  m_T1 = m_T3 = sqrt(m_length / a);
73 
74  m_sv2 = 1.0 / m_T1;
75  m_sa1 = m_sv2 / m_T1;
76  m_sa3 = -m_sa1;
77 
78  }
79  // Bewegung vollständig charakterisiert.
80 
81 }
82 
83 
84 std::vector<double> RefValJS_PTP::r(double s) const
85 {
86  std::vector<double> soll;
87  soll.resize(m_start.size());
88  if (s <= 0)
89  {
90  soll = m_start;
91  } else
92  if (s < 1)
93  {
94  for(unsigned int i = 0; i < m_start.size(); i++)
95  soll.at(i) = m_start.at(i) + m_direction.at(i) * s;
96  }
97  else
98  {
99  soll = m_ziel;
100  }
101  return soll;
102 }
103 
104 double RefValJS_PTP::s(double t) const
105 {
106  if (t >= m_T1 + m_T2 + m_T3)
107  return 1.0;
108  else if (t >= m_T1 + m_T2)
109  {
110  return 0.5*m_sa1*m_T1*m_T1 + m_sv2*m_T2 + m_sv2*(t-m_T1-m_T2) + 0.5*m_sa3*sqr(t-m_T1-m_T2);
111  }
112  else if (t >= m_T1)
113  {
114  return 0.5*m_sa1*m_T1*m_T1 + m_sv2*(t-m_T1);
115  }
116  else if (t > 0.0)
117  {
118  return 0.5*m_sa1*t*t;
119  }
120  else return 0.0;
121 }
122 
123 double RefValJS_PTP::ds_dt(double t) const
124 {
125  if (t >= m_T1 + m_T2 + m_T3)
126  return 0.0;
127  else if (t >= m_T1 + m_T2)
128  {
129  return m_sv2 + m_sa3*(t-m_T1-m_T2);
130  }
131  else if (t >= m_T1)
132  {
133  return m_sv2;
134  }
135  else if (t > 0.0)
136  {
137  return m_sa1*t;
138  }
139  else return 0.0;
140 }
141 
142 std::vector<double> RefValJS_PTP::dr_ds(double s) const
143 {
144  std::vector<double> result = m_start;
145  if (s < 0.0 || s >= 1.0)
146  {
147  for(unsigned int i = 0; i<result.size(); i++)
148  result.at(i) = 0.0;
149  }
150  else
151  {
152  result = m_direction;
153  }
154 
155  return result;
156 }
157 
158 
virtual std::vector< double > dr_ds(double s) const
virtual double s(double t) const
RefValJS_PTP(const std::vector< double > &start, const std::vector< double > &ziel, double v_rad_s, double a_rad_s2)
std::vector< double > m_start
Definition: RefValJS_PTP.h:45
double norm(const std::vector< double > &j)
Definition: RefValJS_PTP.h:66
double m_length
Definition: RefValJS_PTP.h:49
double sqr(double x)
std::vector< double > m_ziel
Definition: RefValJS_PTP.h:46
double m_sa1
Definition: RefValJS_PTP.h:58
static const double weigths[]
Definition: RefValJS_PTP.h:62
virtual std::vector< double > r(double s) const
int min(int a, int b)
double m_sv2
Definition: RefValJS_PTP.h:59
double m_v_rad_s
Definition: RefValJS_PTP.h:51
std::vector< double > m_direction
Definition: RefValJS_PTP.h:47
virtual double ds_dt(double t) const
double m_a_rad_s2
Definition: RefValJS_PTP.h:52
double m_sa3
Definition: RefValJS_PTP.h:60


cob_trajectory_controller
Author(s): Alexander Bubeck
autogenerated on Thu Apr 8 2021 02:39:55