Skip to content

Commit

Permalink
[core] Compute PGS error in residual space instead of optimization sp…
Browse files Browse the repository at this point in the history
…ace.
  • Loading branch information
Alexis Duburcq committed Dec 1, 2021
1 parent 01101a4 commit a94541a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions core/include/jiminy/core/solver/LCPSolvers.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace jiminy
std::vector<uint32_t> indices_;
uint32_t lastShuffle_;
vectorN_t b_;
vectorN_t y_;
vectorN_t yPrev_;
};


Expand Down
20 changes: 13 additions & 7 deletions core/src/solver/LCPSolvers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace jiminy
tolRel_(tolRel),
indices_(),
lastShuffle_(0U),
b_()
b_(),
y_(),
yPrev_()
{
// Empty on purpose.
}
Expand All @@ -34,8 +36,6 @@ namespace jiminy
std::vector<std::vector<int32_t> > const & fIndices,
vectorN_t & x)
{
bool_t isSuccess = true;

// Shuffle coefficient update order to break any repeating cycles
if (randomPermutationPeriod_ > 0 && lastShuffle_ > randomPermutationPeriod_)
{
Expand All @@ -44,12 +44,14 @@ namespace jiminy
}
++lastShuffle_;

// Backup previous solution
yPrev_.noalias() = A * x;

// Update every coefficients sequentially
for (uint32_t const & i : indices_)
{
// Extract single coefficient
float64_t & e = x[i];
float64_t const ePrev = e;

// Update a single coefficient
e += (b[i] - A.col(i).dot(x)) / A(i, i);
Expand Down Expand Up @@ -95,11 +97,15 @@ namespace jiminy
e = 0.0;
}
}

// Check if still possible to terminate after complete update
isSuccess = isSuccess && (std::abs(e - ePrev) < tolAbs_ || std::abs((e - ePrev) / e) < tolRel_);
}

// Check if terminate conditions are satisfied
y_.noalias() = A * x;
bool_t isSuccess = (
(y_ - yPrev_).array().abs() < tolAbs_ ||
((y_ - yPrev_).array() / y_.array()).abs() < tolRel_
).all();

return isSuccess;
}

Expand Down
2 changes: 1 addition & 1 deletion python/gym_jiminy/unit_py/test_pipeline_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _test_pid_standing(self):
action_init['Q'], action_init['V'] = encoder_data[
:, self.env.controller.motor_to_encoder]

# Run the simulation during 12s
# Run the simulation
while self.env.stepper_state.t < 12.0:
self.env.step(action_init)

Expand Down

0 comments on commit a94541a

Please sign in to comment.