Skip to content

Commit

Permalink
major update of the library
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele committed Jan 30, 2024
1 parent 815c5d6 commit a334b7b
Show file tree
Hide file tree
Showing 16 changed files with 693 additions and 465 deletions.
105 changes: 105 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakComment: 10
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 5
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI_UKF](https://github.com/gabrielenava/Eigen_UKF/actions/workflows/ci_ukf.yml/badge.svg)](https://github.com/gabrielenava/Eigen_UKF/actions/workflows/ci_ukf.yml)

A C++ implementation of the Unscented Kalman Filter (UKF) using Eigen. The UKF uses a deterministic sampling technique known as the unscented transformation to calculate statistics around the mean. This technique does not require differentiability of the models.
A C++ implementation of the Unscented Kalman Filter (UKF) using Eigen. The UKF uses a deterministic sampling technique known as the Unscented Transformation to calculate statistics around the mean. This technique does not require differentiability of the models.

See also https://groups.seas.harvard.edu/courses/cs281/papers/unscented.pdf for more details.

Expand All @@ -28,8 +28,9 @@ make install

The UKF library will be available in the `install/lib` folder. The library is composed of two classes:

- [SystemModel](lib/src/SystemModel.cpp): template class used to construct the state and observation models. Create a child class from this parent class, then edit it to add your models.
- [UnscentedKF](lib/src/UnscentedKF.cpp): the class implementing the UKF algorithm.
- [UnscentedKF](lib/src/UnscentedKF.cpp): implementation of the Unscented Kalman Filter in c++. Provides methods to set up a routine for estimation/filtering of user-defined quantities via UKF. Works alongside with the UKFModel class which provides the prediction and observation models.

- [UKFModel](lib/src/UKFModel.cpp): defines the prediction and observation models for the UnscentedKF class. This is an abstract class: the user must create his own child class derived from UKFModel, and implement with it the prediction and observation models for his specific problem.

### Example

Expand Down
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Date: Ott. 2023

# Configure the executable
set(SRCS src/ThrustEstimationUKF.cpp src/JetSystemModel.cpp)
set(SRCS src/ThrustEstimationUKF.cpp src/JetUKFModel.cpp)
add_executable(${PROJECT_NAME}_example ${SRCS})

target_include_directories(${PROJECT_NAME}_example PUBLIC include)
Expand Down
29 changes: 0 additions & 29 deletions example/include/JetSystemModel.h

This file was deleted.

57 changes: 57 additions & 0 deletions example/include/JetUKFModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @file JetUKFModel.h
* @author Gabriele Nava
* @date 2024
*/
#ifndef JET_UKF_MODEL_H
#define JET_UKF_MODEL_H

#include "UKFModel.h"

/**
* @class JetUKFModel
* @brief Inherit and overwrite methods of the UKFModel class to implement
* the prediction and observation models for jet thrust estimation.
*/
class JetUKFModel : public UKFModel
{
public:
/**
* @brief Construct a JetUKFModel object with inputs.
* @param dt discretization time step.
*/
JetUKFModel(const double& dt);

/**
* @brief Update the process model.
* @return None.
*/
void updateProcessModel(const Eigen::Ref<Eigen::VectorXd> u);

/**
* @brief Get the system state at next time instant using the prediction model.
* @param x State at the current time instant;
* @return State at the next time instant.
*/
Eigen::VectorXd computePredictionFromModel(const Eigen::Ref<Eigen::VectorXd> x) override;

/**
* @brief Get the observed variables from the current state. The observed variables are
* the ones to be compared with the available measurements.
* @param x State at current time instant;
* @return Observed variables.
*/
Eigen::VectorXd computeObservationFromModel(const Eigen::Ref<Eigen::VectorXd> x) override;

double m_dt;

// state model parameters
Eigen::Matrix2d m_A;
Eigen::Vector2d m_B;
Eigen::VectorXd m_u;

// measurement model parameters
Eigen::Vector2d m_h;
};

#endif /* end of include guard JET_UKF_MODEL_H */
35 changes: 0 additions & 35 deletions example/src/JetSystemModel.cpp

This file was deleted.

32 changes: 32 additions & 0 deletions example/src/JetUKFModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file JetUKFModel.cpp
* @author Gabriele Nava
* @date 2024
*/
#include <JetUKFModel.h>

JetUKFModel::JetUKFModel(const double& dt)
: m_dt(dt)
{
// for jet engines, implemented a simple kinematic model
m_A << 1.0, m_dt, 0.0, 1.0;
m_B << std::pow(m_dt, 2) / 2, m_dt;

// measurements are the observed thrusts
m_h << 1.0, 0.0;
}

void JetUKFModel::updateProcessModel(const Eigen::Ref<Eigen::VectorXd> u)
{
m_u = u;
}

Eigen::VectorXd JetUKFModel::computePredictionFromModel(const Eigen::Ref<Eigen::VectorXd> x)
{
return (m_A * x + m_B * m_u);
}

Eigen::VectorXd JetUKFModel::computeObservationFromModel(const Eigen::Ref<Eigen::VectorXd> x)
{
return m_h.transpose() * x;
}
Loading

0 comments on commit a334b7b

Please sign in to comment.