Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
quadruped-reactive-walking
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gepetto
quadruped-reactive-walking
Commits
658b50d6
Commit
658b50d6
authored
4 years ago
by
Pierre-Alexandre Leziart
Browse files
Options
Downloads
Patches
Plain Diff
Debug MPC functions
parent
5611f5ae
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/example-adder/MPC.hpp
+23
-14
23 additions, 14 deletions
include/example-adder/MPC.hpp
src/MPC.cpp
+344
-49
344 additions, 49 deletions
src/MPC.cpp
src/main.cpp
+28
-4
28 additions, 4 deletions
src/main.cpp
with
395 additions
and
67 deletions
include/example-adder/MPC.hpp
+
23
−
14
View file @
658b50d6
...
...
@@ -9,7 +9,10 @@
#include
<Eigen/Dense>
#include
"osqp_folder/include/osqp.h"
#include
"osqp_folder/include/cs.h"
#include
"osqp_folder/include/auxil.h"
#include
"osqp_folder/include/util.h"
#include
"osqp_folder/include/osqp_configure.h"
#include
"other/st_to_cc.hpp"
class
MPC
{
private:
...
...
@@ -20,23 +23,26 @@ private:
Eigen
::
Matrix
<
double
,
6
,
1
>
q
;
Eigen
::
Matrix
<
double
,
6
,
1
>
v
=
Eigen
::
Matrix
<
double
,
6
,
1
>::
Zero
();
Eigen
::
Matrix
<
double
,
3
,
4
>
footholds
=
Eigen
::
Matrix
<
double
,
3
,
4
>::
Zero
();
Eigen
::
Matrix
<
double
,
1
,
12
>
footholds_tmp
=
Eigen
::
Matrix
<
double
,
12
,
1
>::
Zero
();
Eigen
::
Matrix
<
double
,
3
,
4
>
lever_arms
=
Eigen
::
Matrix
<
double
,
3
,
4
>::
Zero
();
Eigen
::
Matrix
<
int
,
20
,
5
>
gait
=
Eigen
::
Matrix
<
int
,
20
,
5
>::
Zero
();
Eigen
::
Matrix
<
double
,
12
,
1
>
g
=
Eigen
::
Matrix
<
double
,
12
,
1
>::
Zero
();
Eigen
::
Matrix
<
double
,
12
,
12
>
A
=
Eigen
::
Matrix
<
double
,
12
,
12
>::
Zero
();
Eigen
::
Matrix
<
double
,
12
,
12
>
A
=
Eigen
::
Matrix
<
double
,
12
,
12
>::
Identity
();
Eigen
::
Matrix
<
double
,
12
,
12
>
B
=
Eigen
::
Matrix
<
double
,
12
,
12
>::
Zero
();
Eigen
::
Matrix
<
double
,
12
,
1
>
x0
=
Eigen
::
Matrix
<
double
,
12
,
1
>::
Zero
();
double
x_next
[
12
]
=
{};
double
f_applied
[
12
]
=
{};
// Matrix ML
const
static
int
size_nz_ML
=
5000
;
c_int
r_ML
[
size_nz_ML
]
=
{};
// row indexes of non-zero values in matrix ML
c_int
c_ML
[
size_nz_ML
]
=
{};
// col indexes of non-zero values in matrix ML
c_float
v_ML
[
size_nz_ML
]
=
{};
// non-zero values in matrix ML
//int r_ML [size_nz_ML] = {}; // row indexes of non-zero values in matrix ML
//int c_ML [size_nz_ML] = {}; // col indexes of non-zero values in matrix ML
//double v_ML [size_nz_ML] = {}; // non-zero values in matrix ML
//csc* ML_triplet; // Compressed Sparse Column matrix (triplet format)
csc
*
ML
;
// Compressed Sparse Column matrix
inline
void
add_to_ML
(
int
i
,
int
j
,
double
v
);
// function to fill the triplet r/c/v
inline
void
add_to_P
(
int
i
,
int
j
,
double
v
);
// function to fill the triplet r/c/v
inline
void
add_to_ML
(
int
i
,
int
j
,
double
v
,
int
*
r_ML
,
int
*
c_ML
,
double
*
v_ML
);
// function to fill the triplet r/c/v
inline
void
add_to_P
(
int
i
,
int
j
,
double
v
,
int
*
r_P
,
int
*
c_P
,
double
*
v_P
);
// function to fill the triplet r/c/v
// Indices that are used to udpate ML
int
i_x_B
[
12
*
4
]
=
{};
...
...
@@ -48,12 +54,13 @@ private:
const
static
int
size_nz_NK
=
5000
;
double
v_NK_up
[
size_nz_NK
]
=
{};
// maxtrix NK (upper bound)
double
v_NK_low
[
size_nz_NK
]
=
{};
// maxtrix NK (lower bound)
double
v_warmxf
[
size_nz_NK
]
=
{};
// maxtrix NK (lower bound)
// Matrix P
const
static
int
size_nz_P
=
5000
;
c_int
r_P
[
size_nz_P
]
=
{};
// row indexes of non-zero values in matrix ML
c_int
c_P
[
size_nz_P
]
=
{};
// col indexes of non-zero values in matrix ML
c_float
v_P
[
size_nz_P
]
=
{};
// non-zero values in matrix ML
//
c_int r_P [size_nz_P] = {}; // row indexes of non-zero values in matrix ML
//
c_int c_P [size_nz_P] = {}; // col indexes of non-zero values in matrix ML
//
c_float v_P [size_nz_P] = {}; // non-zero values in matrix ML
csc
*
P
;
// Compressed Sparse Column matrix
// Matrix Q
...
...
@@ -62,12 +69,12 @@ private:
// OSQP solver variables
OSQPWorkspace
*
workspce
=
new
OSQPWorkspace
();
OSQPData
*
data
=
new
OSQPData
()
;
OSQPSettings
*
settings
=
new
OSQPSettings
(
);
OSQPData
*
data
;
OSQPSettings
*
settings
=
(
OSQPSettings
*
)
c_malloc
(
sizeof
(
OSQPSettings
)
);
// Matrices whose size depends on the arguments sent to the constructor function
Eigen
::
Matrix
<
double
,
12
,
Eigen
::
Dynamic
>
xref
;
Eigen
::
Matrix
<
double
,
12
,
Eigen
::
Dynamic
>
x
;
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
1
>
x
;
Eigen
::
Matrix
<
int
,
Eigen
::
Dynamic
,
1
>
S_gait
;
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
1
>
warmxf
;
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
1
>
NK_up
;
...
...
@@ -89,7 +96,8 @@ public:
int
call_solver
(
int
);
int
retrieve_result
();
double
*
get_latest_result
();
int
run
(
Eigen
::
Matrix
<
double
,
12
,
Eigen
::
Dynamic
>
xref_in
,
Eigen
::
Matrix
<
double
,
20
,
13
>
fsteps_in
);
double
*
get_x_next
();
int
run
(
int
num_iter
,
Eigen
::
Matrix
<
double
,
12
,
Eigen
::
Dynamic
>
xref_in
,
Eigen
::
Matrix
<
double
,
20
,
13
>
fsteps_in
);
Eigen
::
Matrix
<
double
,
3
,
3
>
getSkew
(
Eigen
::
Matrix
<
double
,
3
,
1
>
v
);
int
construct_S
();
...
...
@@ -97,6 +105,7 @@ public:
// Accessor
double
gethref
()
{
return
h_ref
;
}
void
my_print_csc_matrix
(
csc
*
M
,
const
char
*
name
);
//Eigen::Matrix<double, 12, 12> getA() { return A; }
//Eigen::MatrixXf getML() { return ML; }
...
...
This diff is collapsed.
Click to expand it.
src/MPC.cpp
+
344
−
49
View file @
658b50d6
This diff is collapsed.
Click to expand it.
src/main.cpp
+
28
−
4
View file @
658b50d6
...
...
@@ -4,6 +4,7 @@
#include
<Eigen/Core>
#include
"example-adder/gepadd.hpp"
#include
"example-adder/MPC.hpp"
#include
"other/st_to_cc.hpp"
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
==
3
)
{
...
...
@@ -11,8 +12,29 @@ int main(int argc, char** argv) {
std
::
cout
<<
"The sum of "
<<
a
<<
" and "
<<
b
<<
" is: "
;
std
::
cout
<<
gepetto
::
example
::
add
(
a
,
b
)
<<
std
::
endl
;
MPC
test
(
0.001
f
,
2
,
0.32
f
);
test
.
create_matrices
();
Eigen
::
Matrix
<
double
,
20
,
13
>
test_fsteps
=
Eigen
::
Matrix
<
double
,
20
,
13
>::
Zero
();
test_fsteps
.
row
(
0
)
<<
15
,
0.19
,
0.15
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
-
0.19
,
-
0.15
,
0.0
;
test_fsteps
.
row
(
1
)
<<
1
,
0.19
,
0.15
,
0.0
,
0.19
,
-
0.15
,
0.0
,
-
0.19
,
0.15
,
0.0
,
-
0.19
,
-
0.15
,
0.0
;
test_fsteps
.
row
(
2
)
<<
15
,
0.0
,
0.0
,
0.0
,
0.19
,
-
0.15
,
0.0
,
-
0.19
,
0.15
,
0.0
,
0.0
,
0.0
,
0.0
;
test_fsteps
.
row
(
3
)
<<
1
,
0.19
,
0.15
,
0.0
,
0.19
,
-
0.15
,
0.0
,
-
0.19
,
0.15
,
0.0
,
-
0.19
,
-
0.15
,
0.0
;
Eigen
::
Matrix
<
double
,
12
,
Eigen
::
Dynamic
>
test_xref
=
Eigen
::
Matrix
<
double
,
12
,
Eigen
::
Dynamic
>::
Zero
(
12
,
33
);
test_xref
.
row
(
2
)
=
0.17
*
Eigen
::
Matrix
<
double
,
1
,
Eigen
::
Dynamic
>::
Ones
(
1
,
33
);
MPC
test
(
0.02
f
,
32
,
0.64
f
);
test
.
run
(
0
,
test_xref
,
test_fsteps
);
double
*
result
;
result
=
test
.
get_latest_result
();
/*for (int i = 0; i < 12; i++)
{
std::cout << *(result+i) << ", ";
}*/
test_fsteps
(
0
,
0
)
=
14
;
test_fsteps
.
row
(
4
)
=
test_fsteps
.
row
(
0
);
test_fsteps
(
4
,
0
)
=
1
;
test
.
run
(
1
,
test_xref
,
test_fsteps
);
std
::
cout
<<
test
.
gethref
()
<<
std
::
endl
;
/*std::cout << test.getA() << std::endl;
std::cout << test.getML() << std::endl;
...
...
@@ -20,7 +42,7 @@ int main(int argc, char** argv) {
std::cout << test.getMonth() << std::endl;
std::cout << test.getYear() << std::endl;*/
Eigen
::
MatrixXd
m
(
2
,
2
);
/*
Eigen::MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
...
...
@@ -33,7 +55,9 @@ int main(int argc, char** argv) {
13, 14, 15, 16, 17, 18;
Eigen::Map<Eigen::MatrixXf> M2(M1.data(), M1.size(), 1);
std
::
cout
<<
"M2:"
<<
std
::
endl
<<
M2
<<
std
::
endl
;
std::cout << "M2:" << std::endl << M2 << std::endl;*/
return
EXIT_SUCCESS
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment