Skip to content

Commit 7e00661

Browse files
committed
Change nu initialization and restore throw exception
1 parent 75f0d7f commit 7e00661

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/friction-compensation.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
#include "simple-mpc/friction-compensation.hpp"
2-
2+
#include <iostream>
33
namespace simple_mpc
44
{
55

66
FrictionCompensation::FrictionCompensation(const Model & model, const bool with_free_flyer)
77
{
88
if (with_free_flyer)
99
{
10-
// Ignore universe and root joints
11-
nu_ = model.njoints - 2;
10+
// Ignore free flyer joint
11+
nu_ = model.nv - 6;
1212
}
1313
else
1414
{
15-
// Ignore universe joint
16-
nu_ = model.njoints - 1;
15+
// If no free flyer
16+
nu_ = model.nv;
1717
}
1818
dry_friction_ = model.friction.tail(nu_);
1919
viscuous_friction_ = model.damping.tail(nu_);
2020
}
2121

2222
void FrictionCompensation::computeFriction(Eigen::Ref<const VectorXd> velocity, Eigen::Ref<VectorXd> torque)
2323
{
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_));
24+
if (velocity.size() != nu_)
25+
throw std::runtime_error("Velocity has wrong size");
26+
if (torque.size() != nu_)
27+
throw std::runtime_error("Torque has wrong size");
28+
2629
torque += viscuous_friction_.cwiseProduct(velocity)
2730
+ dry_friction_.cwiseProduct(velocity.unaryExpr(std::function(signFunction)));
2831
}

0 commit comments

Comments
 (0)