Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
z
Variables
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
x
y
Typedefs
a
b
c
d
f
h
i
n
o
p
q
r
s
t
u
Enumerations
a
c
d
e
f
i
m
n
p
q
r
s
t
u
Enumerator
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
z
Classes
Class List
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Enumerations
a
b
c
d
e
f
g
i
l
m
n
p
r
s
t
u
w
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
y
Related Functions
c
e
h
i
m
o
p
q
s
t
v
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
x
z
Variables
a
b
c
e
g
i
l
m
n
p
r
s
t
v
x
y
Typedefs
a
b
c
d
e
f
h
i
l
m
n
p
q
r
s
t
u
Enumerator
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Examples
src
optimal_control
test
test_single_shooting_grid.cpp
Go to the documentation of this file.
1
/*********************************************************************
2
*
3
* Software License Agreement
4
*
5
* Copyright (c) 2018,
6
* TU Dortmund - Institute of Control Theory and Systems Engineering.
7
* All rights reserved.
8
*
9
* This software is currently not released.
10
* Redistribution and use in source and binary forms,
11
* with or without modification, are prohibited.
12
*
13
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
17
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
23
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24
* POSSIBILITY OF SUCH DAMAGE.
25
*
26
* Authors: Christoph Rösmann
27
*********************************************************************/
28
29
#include <corbo-optimal-control/structured_ocp/discretization_grids/single_shooting_grid.h>
30
31
#include <
corbo-core/reference_trajectory.h
>
32
33
#include <
corbo-core/console.h
>
34
#include <
corbo-core/macros.h
>
35
#include <
corbo-core/value_comparison.h
>
36
37
#include "gtest/gtest.h"
38
39
using
corbo::SingleShootingGrid;
40
using
corbo::StaticReference
;
41
using
corbo::ZeroReference
;
42
using
corbo::VectorVertex
;
43
44
class
TestSingleShootingGrid
:
public
testing::Test
45
{
46
protected
:
47
// You can do set-up work for each test here.
48
TestSingleShootingGrid
() {}
49
// You can do clean-up work that doesn't throw exceptions here.
50
virtual
~TestSingleShootingGrid
() {}
51
// If the constructor and destructor are not enough for setting up
52
// and cleaning up each test, you can define the following methods:
53
54
// Code here will be called immediately after the constructor (right
55
// before each test).
56
void
SetUp
()
override
{}
57
// Code here will be called immediately after each test (right
58
// before the destructor).
59
// virtual void TearDown();
60
61
SingleShootingGrid
grid
;
62
};
63
64
// #ifndef NDEBUG
65
// // check if we have only unique vertices
66
// std::vector<VertexInterface*> vertices_copy = _active_vertices;
67
// std::sort(vertices_copy.begin(), vertices_copy.end());
68
// auto it = std::adjacent_find(vertices_copy.begin(), vertices_copy.end());
69
// if (it != vertices_copy.end())
70
// {
71
// PRINT_WARNING("MultipleShootingGrid::computeActiveVertices(): returns non");
72
// }
73
74
// #endif
75
76
// TEST_F(TestMultipleShootingGrid, initialize_grid_start_state_only)
77
//{
78
// Eigen::Vector2d x0(0, 5);
79
80
// Eigen::Vector2d u0(0, 0);
81
82
// int num_states = 5;
83
// double dt = 0.1;
84
85
// grid.setHorizon(num_states, dt);
86
// grid.initialize(x0, x0, u0);
87
88
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
89
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
90
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 5);
91
92
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
93
94
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 0.0);
95
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 5.0);
96
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 0.0);
97
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 5.0);
98
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 0.0);
99
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 5.0);
100
// EXPECT_DOUBLE_EQ(s_seq(0, 3), 0.0);
101
// EXPECT_DOUBLE_EQ(s_seq(1, 3), 5.0);
102
// EXPECT_DOUBLE_EQ(s_seq(0, 4), 0.0);
103
// EXPECT_DOUBLE_EQ(s_seq(1, 4), 5.0);
104
105
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
106
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
107
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 5);
108
109
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
110
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
111
112
// // check fixed flags (first shooting node must be fixed, others not)
113
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
114
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
115
// {
116
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
117
// }
118
//}
119
120
// TEST_F(TestMultipleShootingGrid, initialize_grid_start_state_end_state)
121
//{
122
// Eigen::Vector2d x0(0, 5);
123
// Eigen::Vector2d xf(5, 0);
124
125
// Eigen::Vector2d u0(0, 0);
126
127
// int num_states = 5;
128
// double dt = 0.1;
129
130
// grid.setHorizon(num_states, dt);
131
// grid.initialize(x0, xf, u0);
132
133
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
134
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
135
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 5);
136
137
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
138
139
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 0.0);
140
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 5.0);
141
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 1.25);
142
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 3.75);
143
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 2.5);
144
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 2.5);
145
// EXPECT_DOUBLE_EQ(s_seq(0, 3), 3.75);
146
// EXPECT_DOUBLE_EQ(s_seq(1, 3), 1.25);
147
// EXPECT_DOUBLE_EQ(s_seq(0, 4), 5.0);
148
// EXPECT_DOUBLE_EQ(s_seq(1, 4), 0.0);
149
150
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
151
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
152
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 5);
153
154
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
155
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
156
157
// // check fixed flags (first shooting node must be fixed, others not)
158
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
159
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
160
// {
161
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
162
// }
163
//}
164
165
// TEST_F(TestMultipleShootingGrid, grid_prune_trajectory)
166
//{
167
// Eigen::Vector2d x0(0, 5);
168
// Eigen::Vector2d xf(5, 0);
169
170
// Eigen::Vector2d u0(0, 0);
171
172
// int num_states = 5;
173
// double dt = 0.1;
174
175
// grid.setHorizon(num_states, dt);
176
// grid.initialize(x0, xf, u0);
177
178
// grid.pruneTrajectory(Eigen::Vector2d(2.4, 2.4)); // erase the first two intervals
179
180
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
181
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
182
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 3);
183
184
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
185
186
// // first states must be updated to (2.4, 2.4) during pruning
187
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 2.4);
188
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 2.4);
189
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 3.75);
190
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 1.25);
191
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 5.0);
192
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 0.0);
193
194
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
195
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
196
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 3);
197
198
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
199
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
200
201
// // check fixed flags (first shooting node must be fixed, others not)
202
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
203
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
204
// {
205
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
206
// }
207
//}
208
209
// TEST_F(TestMultipleShootingGrid, grid_prune_trajectory_keep_min)
210
//{
211
// Eigen::Vector2d x0(0, 5);
212
// Eigen::Vector2d xf(5, 0);
213
214
// Eigen::Vector2d u0(0, 0);
215
216
// int num_states = 5;
217
// double dt = 0.1;
218
219
// grid.setHorizon(num_states, dt);
220
// grid.initialize(x0, xf, u0);
221
222
// // now specify final state as new initial state
223
// grid.pruneTrajectory(xf);
224
225
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
226
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
227
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 2); // we always keep 2 samples (1 interval) in our OCP
228
229
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
230
231
// // first states must be updated to (2.4, 2.4) during pruning
232
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 5.0);
233
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 0.0);
234
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 5.0);
235
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 0.0);
236
237
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
238
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
239
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 2); // we always keep 2 samples (1 interval) in our OCP
240
241
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
242
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
243
244
// // check fixed flags (first shooting node must be fixed, others not)
245
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
246
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
247
// {
248
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
249
// }
250
//}
251
252
// TEST_F(TestMultipleShootingGrid, grid_extrapolate_trajectory)
253
//{
254
// Eigen::Vector2d x0(0, 5);
255
// Eigen::Vector2d xf(5, 0);
256
257
// Eigen::Vector2d u0(0, 0);
258
259
// int num_states = 5;
260
// double dt = 0.1;
261
262
// grid.setHorizon(num_states, dt);
263
// grid.initialize(x0, xf, u0);
264
265
// grid.extrapolateTrajectory(2);
266
267
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
268
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
269
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 7);
270
271
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
272
273
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 0.0);
274
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 5.0);
275
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 1.25);
276
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 3.75);
277
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 2.5);
278
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 2.5);
279
// EXPECT_DOUBLE_EQ(s_seq(0, 3), 3.75);
280
// EXPECT_DOUBLE_EQ(s_seq(1, 3), 1.25);
281
// EXPECT_DOUBLE_EQ(s_seq(0, 4), 5.0);
282
// EXPECT_DOUBLE_EQ(s_seq(1, 4), 0.0);
283
// EXPECT_DOUBLE_EQ(s_seq(0, 5), 6.25);
284
// EXPECT_DOUBLE_EQ(s_seq(1, 5), -1.25);
285
// EXPECT_DOUBLE_EQ(s_seq(0, 6), 7.5);
286
// EXPECT_DOUBLE_EQ(s_seq(1, 6), -2.5);
287
288
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
289
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
290
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 7);
291
292
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
293
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
294
295
// // check fixed flags (first shooting node must be fixed, others not)
296
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
297
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
298
// {
299
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
300
// }
301
//}
TestSingleShootingGrid::SetUp
void SetUp() override
Definition:
test_single_shooting_grid.cpp:56
macros.h
corbo::StaticReference
Static reference trajectory.
Definition:
reference_trajectory.h:134
console.h
TestSingleShootingGrid::~TestSingleShootingGrid
virtual ~TestSingleShootingGrid()
Definition:
test_single_shooting_grid.cpp:50
value_comparison.h
TestSingleShootingGrid
Definition:
test_single_shooting_grid.cpp:44
TestSingleShootingGrid::grid
SingleShootingGrid grid
Definition:
test_single_shooting_grid.cpp:61
corbo::ZeroReference
Zero reference trajectory.
Definition:
reference_trajectory.h:184
TestSingleShootingGrid::TestSingleShootingGrid
TestSingleShootingGrid()
Definition:
test_single_shooting_grid.cpp:48
reference_trajectory.h
corbo::VectorVertex
Vertex implementation that stores an Eigen::VectorXd (dynamic dimension)
Definition:
vector_vertex.h:73
control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:07:06