-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paul Gesel <[email protected]>
- Loading branch information
Showing
8 changed files
with
567 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
BasedOnStyle: Google | ||
AccessModifierOffset: -2 | ||
ConstructorInitializerIndentWidth: 2 | ||
AlignEscapedNewlinesLeft: false | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AlwaysBreakTemplateDeclarations: true | ||
AlwaysBreakBeforeMultilineStrings: false | ||
BreakBeforeBinaryOperators: false | ||
BreakBeforeTernaryOperators: false | ||
BreakConstructorInitializers: BeforeComma | ||
BinPackParameters: true | ||
ColumnLimit: 90 | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
DerivePointerBinding: false | ||
PointerBindsToType: true | ||
ExperimentalAutoDetectBinPacking: false | ||
IndentCaseLabels: true | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCSpaceBeforeProtocolList: true | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 60 | ||
PenaltyBreakString: 1 | ||
PenaltyBreakFirstLessLess: 1000 | ||
PenaltyExcessCharacter: 1000 | ||
PenaltyReturnTypeOnItsOwnLine: 90 | ||
SpacesBeforeTrailingComments: 2 | ||
Cpp11BracedListStyle: false | ||
Standard: Auto | ||
IndentWidth: 2 | ||
TabWidth: 2 | ||
UseTab: Never | ||
IndentFunctionDeclarationAfterType: false | ||
SpacesInParentheses: false | ||
SpacesInAngles: false | ||
SpaceInEmptyParentheses: false | ||
SpacesInCStyleCastParentheses: false | ||
SpaceAfterControlStatementKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: Never | ||
ContinuationIndentWidth: 4 | ||
SortIncludes: false | ||
SpaceAfterCStyleCast: false | ||
ReflowComments: false | ||
|
||
# Configure each individual brace in BraceWrapping | ||
BreakBeforeBraces: Custom | ||
|
||
# Control of individual brace wrapping cases | ||
BraceWrapping: { | ||
AfterClass: 'true', | ||
AfterControlStatement: 'true', | ||
AfterEnum : 'true', | ||
AfterFunction : 'true', | ||
AfterNamespace : 'true', | ||
AfterStruct : 'true', | ||
AfterUnion : 'true', | ||
BeforeCatch : 'true', | ||
BeforeElse : 'true', | ||
IndentBraces : 'false', | ||
SplitEmptyFunction: 'false' | ||
} | ||
... |
131 changes: 69 additions & 62 deletions
131
include/fast_inverse_kinematics/fast_inverse_kinematics.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,81 @@ | ||
#pragma once | ||
|
||
#include "memory" | ||
|
||
#include <Eigen/Core> | ||
#include <Eigen/Dense> | ||
|
||
#include "memory" | ||
|
||
#ifdef FAST_FK_USE_IK | ||
|
||
#include "LBFGS.h" | ||
|
||
#include "kinematics_interface.hpp" | ||
|
||
namespace fast_fk::internal { | ||
class InverseKinematics { | ||
public: | ||
Eigen::Matrix<float, 3, 3> target_rot_; | ||
Eigen::Vector<float, 3> target_pose_; | ||
std::array<std::array<float, 16>, FAST_FK_NUMBER_OF_JOINTS> joint_data = {0}; | ||
std::unique_ptr<LBFGSpp::LBFGSSolver<float>> solver; | ||
LBFGSpp::LBFGSParam<float> param; | ||
|
||
InverseKinematics(const Eigen::Matrix<float, 3, 3> &target_rot, | ||
const Eigen::Vector<float, 3> &target_pose) : target_rot_{target_rot}, | ||
target_pose_{target_pose} { | ||
param.epsilon = 1E-3; | ||
param.epsilon_rel = 1E-3; | ||
param.max_iterations = 30; | ||
|
||
solver = std::make_unique<LBFGSpp::LBFGSSolver<float >>(param); | ||
} | ||
|
||
fk_interface::IKSolverStats | ||
inverse_kinematics(Eigen::Matrix<float, 4, 4> &transform, Eigen::VectorX<float> &q_guess) { | ||
target_rot_ = transform.block<3, 3>(0, 0); | ||
target_pose_(0) = transform(0, 3); | ||
target_pose_(1) = transform(1, 3); | ||
target_pose_(2) = transform(2, 3); | ||
|
||
float fx = 1E10; | ||
int niter; | ||
|
||
try { | ||
niter = solver->minimize(*this, q_guess, fx); | ||
} catch (const std::runtime_error &e) { | ||
return {fx, niter, solver->final_grad_norm(), false, e.what()}; | ||
} | ||
|
||
return {fx, niter, solver->final_grad_norm(), true, ""}; | ||
} | ||
|
||
float operator()(const Eigen::VectorX<float> &q, Eigen::VectorX<float> &grad); | ||
|
||
|
||
}; | ||
} | ||
namespace fast_fk::internal | ||
{ | ||
class InverseKinematics | ||
{ | ||
public: | ||
Eigen::Matrix<float, 3, 3> target_rot_; | ||
Eigen::Vector<float, 3> target_pose_; | ||
std::array<std::array<float, 16>, FAST_FK_NUMBER_OF_JOINTS> joint_data = { 0 }; | ||
std::unique_ptr<LBFGSpp::LBFGSSolver<float>> solver; | ||
LBFGSpp::LBFGSParam<float> param; | ||
|
||
InverseKinematics(const Eigen::Matrix<float, 3, 3>& target_rot, | ||
const Eigen::Vector<float, 3>& target_pose) | ||
: target_rot_{ target_rot }, target_pose_{ target_pose } | ||
{ | ||
param.epsilon = 1E-3; | ||
param.epsilon_rel = 1E-3; | ||
param.max_iterations = 30; | ||
|
||
solver = std::make_unique<LBFGSpp::LBFGSSolver<float>>(param); | ||
} | ||
|
||
fk_interface::IKSolverStats inverse_kinematics(Eigen::Matrix<float, 4, 4>& transform, | ||
Eigen::VectorX<float>& q_guess) | ||
{ | ||
target_rot_ = transform.block<3, 3>(0, 0); | ||
target_pose_(0) = transform(0, 3); | ||
target_pose_(1) = transform(1, 3); | ||
target_pose_(2) = transform(2, 3); | ||
|
||
float fx = 1E10; | ||
int niter; | ||
|
||
try | ||
{ | ||
niter = solver->minimize(*this, q_guess, fx); | ||
} | ||
catch(const std::runtime_error& e) | ||
{ | ||
return { fx, niter, solver->final_grad_norm(), false, e.what() }; | ||
} | ||
|
||
return { fx, niter, solver->final_grad_norm(), true, "" }; | ||
} | ||
|
||
float operator()(const Eigen::VectorX<float>& q, Eigen::VectorX<float>& grad); | ||
}; | ||
} // namespace fast_fk::internal | ||
#else | ||
namespace fast_fk::internal { | ||
class InverseKinematics { | ||
public: | ||
InverseKinematics(const Eigen::Matrix<float, 3, 3> &target_rot, | ||
const Eigen::Vector<float, 3> &target_pose){} | ||
|
||
fk_interface::IKSolverStats | ||
inverse_kinematics(Eigen::Matrix<float, 4, 4> &transform, Eigen::VectorX<float> &q_guess) { | ||
throw std::logic_error("Function not implemented."); | ||
return {}; | ||
} | ||
|
||
float operator()(const Eigen::VectorX<float> &q, Eigen::VectorX<float> &grad); | ||
|
||
}; | ||
} | ||
namespace fast_fk::internal | ||
{ | ||
class InverseKinematics | ||
{ | ||
public: | ||
InverseKinematics(const Eigen::Matrix<float, 3, 3>& target_rot, | ||
const Eigen::Vector<float, 3>& target_pose) | ||
{} | ||
|
||
fk_interface::IKSolverStats inverse_kinematics(Eigen::Matrix<float, 4, 4>& transform, | ||
Eigen::VectorX<float>& q_guess) | ||
{ | ||
throw std::logic_error("Function not implemented."); | ||
return {}; | ||
} | ||
|
||
float operator()(const Eigen::VectorX<float>& q, Eigen::VectorX<float>& grad); | ||
}; | ||
} // namespace fast_fk::internal | ||
#endif |
Oops, something went wrong.