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_multiple_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/multiple_shooting_grid.h
>
30
31
#include <
corbo-core/reference_trajectory.h
>
32
#include <
corbo-systems/benchmark/linear_benchmark_systems.h
>
33
34
#include <
corbo-core/console.h
>
35
#include <
corbo-core/macros.h
>
36
#include <
corbo-core/value_comparison.h
>
37
38
#include "gtest/gtest.h"
39
40
using
corbo::MultipleShootingGrid
;
41
using
corbo::StaticReference
;
42
using
corbo::ZeroReference
;
43
using
corbo::VectorVertex
;
44
45
class
TestMultipleShootingGrid
:
public
testing::Test
46
{
47
protected
:
48
// You can do set-up work for each test here.
49
TestMultipleShootingGrid
() {}
50
// You can do clean-up work that doesn't throw exceptions here.
51
virtual
~TestMultipleShootingGrid
() {}
52
// If the constructor and destructor are not enough for setting up
53
// and cleaning up each test, you can define the following methods:
54
55
// Code here will be called immediately after the constructor (right
56
// before each test).
57
void
SetUp
()
override
{}
58
// Code here will be called immediately after each test (right
59
// before the destructor).
60
// virtual void TearDown();
61
62
MultipleShootingGrid
grid
;
63
};
64
65
// #ifndef NDEBUG
66
// // check if we have only unique vertices
67
// std::vector<VertexInterface*> vertices_copy = _active_vertices;
68
// std::sort(vertices_copy.begin(), vertices_copy.end());
69
// auto it = std::adjacent_find(vertices_copy.begin(), vertices_copy.end());
70
// if (it != vertices_copy.end())
71
// {
72
// PRINT_WARNING("MultipleShootingGrid::computeActiveVertices(): returns non");
73
// }
74
75
// #endif
76
77
// TEST_F(TestMultipleShootingGrid, initialize_grid_start_state_only)
78
//{
79
// Eigen::Vector2d x0(0, 5);
80
81
// Eigen::Vector2d u0(0, 0);
82
83
// int num_states = 5;
84
// double dt = 0.1;
85
86
// grid.setHorizon(num_states, dt);
87
// grid.initialize(x0, x0, u0);
88
89
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
90
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
91
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 5);
92
93
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
94
95
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 0.0);
96
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 5.0);
97
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 0.0);
98
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 5.0);
99
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 0.0);
100
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 5.0);
101
// EXPECT_DOUBLE_EQ(s_seq(0, 3), 0.0);
102
// EXPECT_DOUBLE_EQ(s_seq(1, 3), 5.0);
103
// EXPECT_DOUBLE_EQ(s_seq(0, 4), 0.0);
104
// EXPECT_DOUBLE_EQ(s_seq(1, 4), 5.0);
105
106
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
107
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
108
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 5);
109
110
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
111
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
112
113
// // check fixed flags (first shooting node must be fixed, others not)
114
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
115
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
116
// {
117
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
118
// }
119
//}
120
121
// TEST_F(TestMultipleShootingGrid, initialize_grid_start_state_end_state)
122
//{
123
// Eigen::Vector2d x0(0, 5);
124
// Eigen::Vector2d xf(5, 0);
125
126
// Eigen::Vector2d u0(0, 0);
127
128
// int num_states = 5;
129
// double dt = 0.1;
130
131
// grid.setHorizon(num_states, dt);
132
// grid.initialize(x0, xf, u0);
133
134
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
135
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
136
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 5);
137
138
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
139
140
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 0.0);
141
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 5.0);
142
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 1.25);
143
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 3.75);
144
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 2.5);
145
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 2.5);
146
// EXPECT_DOUBLE_EQ(s_seq(0, 3), 3.75);
147
// EXPECT_DOUBLE_EQ(s_seq(1, 3), 1.25);
148
// EXPECT_DOUBLE_EQ(s_seq(0, 4), 5.0);
149
// EXPECT_DOUBLE_EQ(s_seq(1, 4), 0.0);
150
151
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
152
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
153
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 5);
154
155
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
156
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
157
158
// // check fixed flags (first shooting node must be fixed, others not)
159
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
160
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
161
// {
162
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
163
// }
164
//}
165
166
// TEST_F(TestMultipleShootingGrid, grid_prune_trajectory)
167
//{
168
// Eigen::Vector2d x0(0, 5);
169
// Eigen::Vector2d xf(5, 0);
170
171
// Eigen::Vector2d u0(0, 0);
172
173
// int num_states = 5;
174
// double dt = 0.1;
175
176
// grid.setHorizon(num_states, dt);
177
// grid.initialize(x0, xf, u0);
178
179
// grid.pruneTrajectory(Eigen::Vector2d(2.4, 2.4)); // erase the first two intervals
180
181
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
182
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
183
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 3);
184
185
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
186
187
// // first states must be updated to (2.4, 2.4) during pruning
188
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 2.4);
189
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 2.4);
190
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 3.75);
191
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 1.25);
192
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 5.0);
193
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 0.0);
194
195
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
196
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
197
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 3);
198
199
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
200
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
201
202
// // check fixed flags (first shooting node must be fixed, others not)
203
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
204
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
205
// {
206
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
207
// }
208
//}
209
210
// TEST_F(TestMultipleShootingGrid, grid_prune_trajectory_keep_min)
211
//{
212
// Eigen::Vector2d x0(0, 5);
213
// Eigen::Vector2d xf(5, 0);
214
215
// Eigen::Vector2d u0(0, 0);
216
217
// int num_states = 5;
218
// double dt = 0.1;
219
220
// grid.setHorizon(num_states, dt);
221
// grid.initialize(x0, xf, u0);
222
223
// // now specify final state as new initial state
224
// grid.pruneTrajectory(xf);
225
226
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
227
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
228
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 2); // we always keep 2 samples (1 interval) in our OCP
229
230
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
231
232
// // first states must be updated to (2.4, 2.4) during pruning
233
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 5.0);
234
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 0.0);
235
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 5.0);
236
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 0.0);
237
238
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
239
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
240
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 2); // we always keep 2 samples (1 interval) in our OCP
241
242
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
243
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
244
245
// // check fixed flags (first shooting node must be fixed, others not)
246
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
247
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
248
// {
249
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
250
// }
251
//}
252
253
// TEST_F(TestMultipleShootingGrid, grid_extrapolate_trajectory)
254
//{
255
// Eigen::Vector2d x0(0, 5);
256
// Eigen::Vector2d xf(5, 0);
257
258
// Eigen::Vector2d u0(0, 0);
259
260
// int num_states = 5;
261
// double dt = 0.1;
262
263
// grid.setHorizon(num_states, dt);
264
// grid.initialize(x0, xf, u0);
265
266
// grid.extrapolateTrajectory(2);
267
268
// corbo::TimeSeries::Ptr sn = grid.getShootingNodeTimeSeries();
269
// EXPECT_DOUBLE_EQ(sn->getValueDimension(), 2);
270
// EXPECT_DOUBLE_EQ(sn->getTimeDimension(), 7);
271
272
// Eigen::MatrixXd s_seq = sn->getValuesMatrixView();
273
274
// EXPECT_DOUBLE_EQ(s_seq(0, 0), 0.0);
275
// EXPECT_DOUBLE_EQ(s_seq(1, 0), 5.0);
276
// EXPECT_DOUBLE_EQ(s_seq(0, 1), 1.25);
277
// EXPECT_DOUBLE_EQ(s_seq(1, 1), 3.75);
278
// EXPECT_DOUBLE_EQ(s_seq(0, 2), 2.5);
279
// EXPECT_DOUBLE_EQ(s_seq(1, 2), 2.5);
280
// EXPECT_DOUBLE_EQ(s_seq(0, 3), 3.75);
281
// EXPECT_DOUBLE_EQ(s_seq(1, 3), 1.25);
282
// EXPECT_DOUBLE_EQ(s_seq(0, 4), 5.0);
283
// EXPECT_DOUBLE_EQ(s_seq(1, 4), 0.0);
284
// EXPECT_DOUBLE_EQ(s_seq(0, 5), 6.25);
285
// EXPECT_DOUBLE_EQ(s_seq(1, 5), -1.25);
286
// EXPECT_DOUBLE_EQ(s_seq(0, 6), 7.5);
287
// EXPECT_DOUBLE_EQ(s_seq(1, 6), -2.5);
288
289
// corbo::TimeSeries::Ptr un = grid.getControlInputTimeSeries();
290
// EXPECT_DOUBLE_EQ(un->getValueDimension(), 2);
291
// EXPECT_DOUBLE_EQ(un->getTimeDimension(), 7);
292
293
// Eigen::MatrixXd u_seq = un->getValuesMatrixView();
294
// EXPECT_TRUE(u_seq.isZero()) << u_seq;
295
296
// // check fixed flags (first shooting node must be fixed, others not)
297
// EXPECT_TRUE(grid.getShootingIntervals()[0].shooting_node->isFixed());
298
// for (int i = 1; i < (int)grid.getShootingIntervals().size(); ++i)
299
// {
300
// EXPECT_FALSE(grid.getShootingIntervals()[i].shooting_node->isFixed());
301
// }
302
//}
corbo::MultipleShootingGrid
Definition:
multiple_shooting_grid.h:56
linear_benchmark_systems.h
TestMultipleShootingGrid::grid
MultipleShootingGrid grid
Definition:
test_multiple_shooting_grid.cpp:62
macros.h
corbo::StaticReference
Static reference trajectory.
Definition:
reference_trajectory.h:134
console.h
value_comparison.h
TestMultipleShootingGrid::~TestMultipleShootingGrid
virtual ~TestMultipleShootingGrid()
Definition:
test_multiple_shooting_grid.cpp:51
TestMultipleShootingGrid
Definition:
test_multiple_shooting_grid.cpp:45
multiple_shooting_grid.h
corbo::ZeroReference
Zero reference trajectory.
Definition:
reference_trajectory.h:184
TestMultipleShootingGrid::SetUp
void SetUp() override
Definition:
test_multiple_shooting_grid.cpp:57
TestMultipleShootingGrid::TestMultipleShootingGrid
TestMultipleShootingGrid()
Definition:
test_multiple_shooting_grid.cpp:49
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