Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Gesel <[email protected]>
  • Loading branch information
pac48 committed Nov 10, 2024
1 parent 347d391 commit 0a4daf7
Show file tree
Hide file tree
Showing 8 changed files with 567 additions and 443 deletions.
68 changes: 68 additions & 0 deletions .clang-format
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 include/fast_inverse_kinematics/fast_inverse_kinematics.hpp
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
Loading

0 comments on commit 0a4daf7

Please sign in to comment.