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
dded2d1e
Commit
dded2d1e
authored
2 years ago
by
Pierre-Alexandre Leziart
Browse files
Options
Downloads
Patches
Plain Diff
Rebase changes to MPC from flying branch
parent
3eb077e5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/qrw/MPC.hpp
+4
-4
4 additions, 4 deletions
include/qrw/MPC.hpp
src/MPC.cpp
+27
-9
27 additions, 9 deletions
src/MPC.cpp
with
31 additions
and
13 deletions
include/qrw/MPC.hpp
+
4
−
4
View file @
dded2d1e
...
@@ -240,7 +240,7 @@ class MPC {
...
@@ -240,7 +240,7 @@ class MPC {
MatrixN
x_f_applied
;
// Next predicted state of the robot + Desired contact forces to reach it
MatrixN
x_f_applied
;
// Next predicted state of the robot + Desired contact forces to reach it
// Matrix ML
// Matrix ML
const
static
int
size_nz_ML
=
5000
;
const
static
int
size_nz_ML
=
1
5000
;
csc
*
ML
;
// Compressed Sparse Column matrix
csc
*
ML
;
// Compressed Sparse Column matrix
// Indices that are used to udpate ML
// Indices that are used to udpate ML
...
@@ -250,17 +250,17 @@ class MPC {
...
@@ -250,17 +250,17 @@ class MPC {
// TODO FOR S ????
// TODO FOR S ????
// Matrix NK
// Matrix NK
const
static
int
size_nz_NK
=
1
5000
;
const
static
int
size_nz_NK
=
4
5000
;
double
v_NK_up
[
size_nz_NK
]
=
{};
// maxtrix NK (upper bound)
double
v_NK_up
[
size_nz_NK
]
=
{};
// maxtrix NK (upper bound)
double
v_NK_low
[
size_nz_NK
]
=
{};
// maxtrix NK (lower bound)
double
v_NK_low
[
size_nz_NK
]
=
{};
// maxtrix NK (lower bound)
double
v_warmxf
[
size_nz_NK
]
=
{};
// maxtrix NK (lower bound)
double
v_warmxf
[
size_nz_NK
]
=
{};
// maxtrix NK (lower bound)
// Matrix P
// Matrix P
const
static
int
size_nz_P
=
1
5000
;
const
static
int
size_nz_P
=
4
5000
;
csc
*
P
;
// Compressed Sparse Column matrix
csc
*
P
;
// Compressed Sparse Column matrix
// Matrix Q
// Matrix Q
const
static
int
size_nz_Q
=
1
5000
;
const
static
int
size_nz_Q
=
4
5000
;
double
Q
[
size_nz_Q
]
=
{};
// Q is full of zeros
double
Q
[
size_nz_Q
]
=
{};
// Q is full of zeros
// OSQP solver variables
// OSQP solver variables
...
...
This diff is collapsed.
Click to expand it.
src/MPC.cpp
+
27
−
9
View file @
dded2d1e
...
@@ -18,12 +18,12 @@ MPC::MPC(Params ¶ms) {
...
@@ -18,12 +18,12 @@ MPC::MPC(Params ¶ms) {
// Predefined variables
// Predefined variables
mass
=
params_
->
mass
;
mass
=
params_
->
mass
;
mu
=
0.
9
f
;
mu
=
0.
5
f
;
cpt_ML
=
0
;
cpt_ML
=
0
;
cpt_P
=
0
;
cpt_P
=
0
;
offset_CoM
(
0
,
0
)
=
params_
->
CoM_offset
[
0
];
offset_CoM
(
0
,
0
)
=
params_
->
CoM_offset
[
0
];
offset_CoM
(
1
,
0
)
=
params_
->
CoM_offset
[
1
]
;
offset_CoM
(
1
,
0
)
=
params_
->
CoM_offset
[
1
]
*
0.0
;
// No lateral offset due to symmetry
offset_CoM
(
2
,
0
)
=
params_
->
CoM_offset
[
2
];
// Vertical offset between center of base and CoM
offset_CoM
(
2
,
0
)
=
params_
->
CoM_offset
[
2
];
// Vertical offset between center of base and CoM
// Predefined matrices
// Predefined matrices
footholds
<<
0.19
,
0.19
,
-
0.19
,
-
0.19
,
0.15005
,
-
0.15005
,
0.15005
,
-
0.15005
,
0.0
,
0.0
,
0.0
,
0.0
;
footholds
<<
0.19
,
0.19
,
-
0.19
,
-
0.19
,
0.15005
,
-
0.15005
,
0.15005
,
-
0.15005
,
0.0
,
0.0
,
0.0
,
0.0
;
...
@@ -217,7 +217,11 @@ int MPC::create_ML() {
...
@@ -217,7 +217,11 @@ int MPC::create_ML() {
// Get skew-symetric matrix for each foothold
// Get skew-symetric matrix for each foothold
Matrix34
l_arms
=
footholds
-
(
xref
.
block
(
0
,
k
,
3
,
1
)).
replicate
<
1
,
4
>
();
Matrix34
l_arms
=
footholds
-
(
xref
.
block
(
0
,
k
,
3
,
1
)).
replicate
<
1
,
4
>
();
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
B
.
block
(
9
,
3
*
i
,
3
,
3
)
=
dt
*
(
I_inv
*
getSkew
(
l_arms
.
col
(
i
)));
if
(
footholds_bis
.
col
(
i
).
isZero
())
{
// Foot in swing
B
.
block
(
9
,
3
*
i
,
3
,
3
).
setZero
();
}
else
{
B
.
block
(
9
,
3
*
i
,
3
,
3
)
=
dt
*
(
I_inv
*
getSkew
(
lever_arms
.
col
(
i
)));
}
}
}
int
i_iter
=
24
*
4
*
k
;
int
i_iter
=
24
*
4
*
k
;
...
@@ -487,10 +491,24 @@ float MPC::retrieve_cost() {
...
@@ -487,10 +491,24 @@ float MPC::retrieve_cost() {
int
MPC
::
call_solver
(
int
k
)
{
int
MPC
::
call_solver
(
int
k
)
{
// Initial guess for forces (mass evenly supported by all legs in contact)
// Initial guess for forces (mass evenly supported by all legs in contact)
warmxf
.
block
(
0
,
0
,
12
*
(
n_steps
-
1
),
1
)
=
x
.
block
(
12
,
0
,
12
*
(
n_steps
-
1
),
1
);
if
(
k
==
0
)
{
warmxf
.
block
(
12
*
n_steps
,
0
,
12
*
(
n_steps
-
1
),
1
)
=
x
.
block
(
12
*
(
n_steps
+
1
),
0
,
12
*
(
n_steps
-
1
),
1
);
warmxf
.
block
(
0
,
0
,
12
*
(
n_steps
-
1
),
1
)
=
x
.
block
(
12
,
0
,
12
*
(
n_steps
-
1
),
1
);
warmxf
.
block
(
12
*
(
2
*
n_steps
-
1
),
0
,
12
,
1
)
=
x
.
block
(
12
*
n_steps
,
0
,
12
,
1
);
warmxf
.
block
(
12
*
n_steps
,
0
,
12
*
(
n_steps
-
1
),
1
)
=
x
.
block
(
12
*
(
n_steps
+
1
),
0
,
12
*
(
n_steps
-
1
),
1
);
VectorN
::
Map
(
&
v_warmxf
[
0
],
warmxf
.
size
())
=
warmxf
;
warmxf
.
block
(
12
*
(
2
*
n_steps
-
1
),
0
,
12
,
1
)
=
x
.
block
(
12
*
n_steps
,
0
,
12
,
1
);
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
1
>::
Map
(
&
v_warmxf
[
0
],
warmxf
.
size
())
=
warmxf
;
}
else
{
for
(
int
i
=
0
;
i
<
12
*
(
n_steps
-
1
);
i
++
)
{
v_warmxf
[
i
]
=
(
workspce
->
solution
->
x
)[
i
+
12
];
// Shift predicted state by one time step
v_warmxf
[
i
+
12
*
n_steps
]
=
(
workspce
->
solution
->
x
)[
i
+
12
+
12
*
n_steps
];
// Shift desired forces by one time step
}
for
(
int
i
=
0
;
i
<
12
;
i
++
)
{
v_warmxf
[
i
+
12
*
(
n_steps
-
1
)]
=
(
workspce
->
solution
->
x
)[
i
+
12
*
(
n_steps
-
1
)];
// Last state is not shifted (no roll)
v_warmxf
[
i
+
12
*
(
n_steps
-
1
)
+
12
*
n_steps
]
=
0.0
;
// Last ctc force is 0.0, could be workspce->solution->x)[i + 12 * (n_steps-1) + 12 * n_steps];
}
}
// Setup the solver (first iteration) then just update it
// Setup the solver (first iteration) then just update it
if
(
k
==
0
)
// Setup the solver with the matrices
if
(
k
==
0
)
// Setup the solver with the matrices
...
@@ -534,7 +552,7 @@ int MPC::call_solver(int k) {
...
@@ -534,7 +552,7 @@ int MPC::call_solver(int k) {
{
{
osqp_update_A
(
workspce
,
&
ML
->
x
[
0
],
OSQP_NULL
,
0
);
osqp_update_A
(
workspce
,
&
ML
->
x
[
0
],
OSQP_NULL
,
0
);
osqp_update_bounds
(
workspce
,
&
v_NK_low
[
0
],
&
v_NK_up
[
0
]);
osqp_update_bounds
(
workspce
,
&
v_NK_low
[
0
],
&
v_NK_up
[
0
]);
//
osqp_warm_start_x(workspce, &v_warmxf[0]);
osqp_warm_start_x
(
workspce
,
&
v_warmxf
[
0
]);
}
}
// char t_char[1] = {'M'};
// char t_char[1] = {'M'};
...
...
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