|
3 | 3 | namespace simple_mpc |
4 | 4 | { |
5 | 5 |
|
6 | | - FrictionCompensation::FrictionCompensation(const Model & model, const long actuation_size) |
| 6 | + FrictionCompensation::FrictionCompensation(const Model & model, const bool with_free_flyer) |
7 | 7 | { |
8 | | - corrected_torque_.resize(actuation_size); |
9 | | - dry_friction_ = model.friction; |
10 | | - viscuous_friction_ = model.damping; |
11 | | - } |
12 | | - |
13 | | - void FrictionCompensation::computeFriction(const Eigen::VectorXd & velocity, const Eigen::VectorXd & torque) |
14 | | - { |
15 | | - if (velocity.size() != corrected_torque_.size()) |
| 8 | + if (with_free_flyer) |
16 | 9 | { |
17 | | - throw std::runtime_error("Velocity has wrong size"); |
| 10 | + // Ignore universe and root joints |
| 11 | + nu_ = model.njoints - 2; |
18 | 12 | } |
19 | | - if (torque.size() != corrected_torque_.size()) |
| 13 | + else |
20 | 14 | { |
21 | | - throw std::runtime_error("Torque has wrong size"); |
| 15 | + // Ignore root joint |
| 16 | + nu_ = model.njoints - 1; |
22 | 17 | } |
23 | | - corrected_torque_ = torque + viscuous_friction_.cwiseProduct(velocity) |
24 | | - + dry_friction_.cwiseProduct(velocity.unaryExpr(std::function(signFunction))); |
| 18 | + dry_friction_ = model.friction.head(nu_); |
| 19 | + viscuous_friction_ = model.damping.head(nu_); |
| 20 | + } |
| 21 | + |
| 22 | + void FrictionCompensation::computeFriction(Eigen::Ref<const VectorXd> velocity, Eigen::Ref<VectorXd> torque) |
| 23 | + { |
| 24 | + assert(("Velocity size must be equal to actuation size", velocity.size() == nu_)); |
| 25 | + assert(("Torque size must be equal to actuation size", torque.size() == nu_)); |
| 26 | + torque += viscuous_friction_.cwiseProduct(velocity) |
| 27 | + + dry_friction_.cwiseProduct(velocity.unaryExpr(std::function(signFunction))); |
25 | 28 | } |
26 | 29 |
|
27 | 30 | double FrictionCompensation::signFunction(double x) |
|
0 commit comments