-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Al-khwarizmi-780/feature/refactoring
refactoring and fix linux build
- Loading branch information
Showing
276 changed files
with
111,889 additions
and
720 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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
@echo off | ||
|
||
echo Creating Build Folder | ||
md .\cpp\build | ||
if not exist ".\cpp\build" ( | ||
echo Creating ./cpp/build Folder | ||
md ./cpp/build | ||
) else ( | ||
echo ./cpp/build folder already exists | ||
) | ||
|
||
echo generating meta files | ||
cmake -S .\cpp -B .\cpp\build | ||
cmake -S ./cpp -B ./cpp/build | ||
|
||
echo building ... | ||
cmake --build .\cpp\build | ||
cmake --build ./cpp/build | ||
|
||
echo installing ... | ||
cmake --install .\cpp\build --config Debug | ||
cmake --install ./cpp/build --config Debug | ||
::runas /user:Administrator "cmake --install .\cpp\build --config Debug" | ||
|
||
pause |
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
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,8 +1,8 @@ | ||
set(EXAMPLE_EXECUTABLE_PREFIX "example_") | ||
|
||
add_subdirectory(kf_state_estimation) | ||
add_subdirectory(ekf_range_sensor) | ||
add_subdirectory(unscented_transform) | ||
add_subdirectory(ukf_range_sensor) | ||
add_subdirectory(test_least_squares) | ||
add_subdirectory(sr_ukf_linear_function) | ||
set(EXAMPLE_EXECUTABLE_PREFIX "example_") | ||
|
||
add_subdirectory(kf_state_estimation) | ||
add_subdirectory(ekf_range_sensor) | ||
add_subdirectory(unscented_transform) | ||
add_subdirectory(ukf_range_sensor) | ||
add_subdirectory(test_least_squares) | ||
add_subdirectory(sr_ukf_linear_function) |
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
149 changes: 74 additions & 75 deletions
149
cpp/Examples/ekf_range_sensor/main.cpp → cpp/examples/ekf_range_sensor/main.cpp
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,75 +1,74 @@ | ||
/// | ||
/// Copyright 2022 Mohanad Youssef (Al-khwarizmi) | ||
/// | ||
/// Use of this source code is governed by an GPL-3.0 - style | ||
/// license that can be found in the LICENSE file or at | ||
/// https://opensource.org/licenses/GPL-3.0 | ||
/// | ||
/// @author Mohanad Youssef <mohanad.magdy.hammad@gmail.com> | ||
/// @file main.cpp | ||
/// | ||
|
||
#include <iostream> | ||
#include <stdint.h> | ||
|
||
#include "kalman_filter/types.h" | ||
#include "kalman_filter/kalman_filter.h" | ||
|
||
#include "kalman_filter/unscented_transform.h" | ||
|
||
static constexpr size_t DIM_X{ 2 }; | ||
static constexpr size_t DIM_Z{ 2 }; | ||
|
||
static kf::KalmanFilter<DIM_X, DIM_Z> kalmanfilter; | ||
|
||
kf::Vector<DIM_Z> covertCartesian2Polar(const kf::Vector<DIM_X> & cartesian); | ||
kf::Matrix<DIM_Z, DIM_Z> calculateJacobianMatrix(const kf::Vector<DIM_X> & vecX); | ||
void executeCorrectionStep(); | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
executeCorrectionStep(); | ||
|
||
return 0; | ||
} | ||
|
||
kf::Vector<DIM_Z> covertCartesian2Polar(const kf::Vector<DIM_X> & cartesian) | ||
{ | ||
const kf::Vector<DIM_Z> polar{ | ||
std::sqrt(cartesian[0] * cartesian[0] + cartesian[1] * cartesian[1]), | ||
std::atan2(cartesian[1], cartesian[0]) | ||
}; | ||
return polar; | ||
} | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> calculateJacobianMatrix(const kf::Vector<DIM_X> & vecX) | ||
{ | ||
const kf::float32_t valX2PlusY2{ (vecX[0] * vecX[0]) + (vecX[1] * vecX[1]) }; | ||
const kf::float32_t valSqrtX2PlusY2{ std::sqrt(valX2PlusY2) }; | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> matHj; | ||
matHj << | ||
(vecX[0] / valSqrtX2PlusY2), (vecX[1] / valSqrtX2PlusY2), | ||
(-vecX[1] / valX2PlusY2), (vecX[0] / valX2PlusY2); | ||
|
||
return matHj; | ||
} | ||
|
||
void executeCorrectionStep() | ||
{ | ||
kalmanfilter.vecX() << 10.0F, 5.0F; | ||
kalmanfilter.matP() << 0.3F, 0.0F, 0.0F, 0.3F; | ||
|
||
const kf::Vector<DIM_X> measPosCart{ 10.4F, 5.2F }; | ||
const kf::Vector<DIM_Z> vecZ{ covertCartesian2Polar(measPosCart) }; | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> matR; | ||
matR << 0.1F, 0.0F, 0.0F, 0.0008F; | ||
|
||
kf::Matrix<DIM_Z, DIM_X> matHj{ calculateJacobianMatrix(kalmanfilter.vecX()) }; // jacobian matrix Hj | ||
|
||
kalmanfilter.correctEkf(covertCartesian2Polar, vecZ, matR, matHj); | ||
|
||
std::cout << "\ncorrected state vector = \n" << kalmanfilter.vecX() << "\n"; | ||
std::cout << "\ncorrected state covariance = \n" << kalmanfilter.matP() << "\n"; | ||
} | ||
/// | ||
/// Copyright 2022 Mohanad Youssef (Al-khwarizmi) | ||
/// | ||
/// Use of this source code is governed by an GPL-3.0 - style | ||
/// license that can be found in the LICENSE file or at | ||
/// https://opensource.org/licenses/GPL-3.0 | ||
/// | ||
/// @author Mohanad Youssef <mohanad.magdy.hammad@gmail.com> | ||
/// @file main.cpp | ||
/// | ||
|
||
#include <iostream> | ||
#include <stdint.h> | ||
|
||
#include "types.h" | ||
#include "kalman_filter/kalman_filter.h" | ||
#include "kalman_filter/unscented_transform.h" | ||
|
||
static constexpr size_t DIM_X{ 2 }; | ||
static constexpr size_t DIM_Z{ 2 }; | ||
|
||
static kf::KalmanFilter<DIM_X, DIM_Z> kalmanfilter; | ||
|
||
kf::Vector<DIM_Z> covertCartesian2Polar(const kf::Vector<DIM_X> & cartesian); | ||
kf::Matrix<DIM_Z, DIM_Z> calculateJacobianMatrix(const kf::Vector<DIM_X> & vecX); | ||
void executeCorrectionStep(); | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
executeCorrectionStep(); | ||
|
||
return 0; | ||
} | ||
|
||
kf::Vector<DIM_Z> covertCartesian2Polar(const kf::Vector<DIM_X> & cartesian) | ||
{ | ||
const kf::Vector<DIM_Z> polar{ | ||
std::sqrt(cartesian[0] * cartesian[0] + cartesian[1] * cartesian[1]), | ||
std::atan2(cartesian[1], cartesian[0]) | ||
}; | ||
return polar; | ||
} | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> calculateJacobianMatrix(const kf::Vector<DIM_X> & vecX) | ||
{ | ||
const kf::float32_t valX2PlusY2{ (vecX[0] * vecX[0]) + (vecX[1] * vecX[1]) }; | ||
const kf::float32_t valSqrtX2PlusY2{ std::sqrt(valX2PlusY2) }; | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> matHj; | ||
matHj << | ||
(vecX[0] / valSqrtX2PlusY2), (vecX[1] / valSqrtX2PlusY2), | ||
(-vecX[1] / valX2PlusY2), (vecX[0] / valX2PlusY2); | ||
|
||
return matHj; | ||
} | ||
|
||
void executeCorrectionStep() | ||
{ | ||
kalmanfilter.vecX() << 10.0F, 5.0F; | ||
kalmanfilter.matP() << 0.3F, 0.0F, 0.0F, 0.3F; | ||
|
||
const kf::Vector<DIM_X> measPosCart{ 10.4F, 5.2F }; | ||
const kf::Vector<DIM_Z> vecZ{ covertCartesian2Polar(measPosCart) }; | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> matR; | ||
matR << 0.1F, 0.0F, 0.0F, 0.0008F; | ||
|
||
kf::Matrix<DIM_Z, DIM_X> matHj{ calculateJacobianMatrix(kalmanfilter.vecX()) }; // jacobian matrix Hj | ||
|
||
kalmanfilter.correctEkf(covertCartesian2Polar, vecZ, matR, matHj); | ||
|
||
std::cout << "\ncorrected state vector = \n" << kalmanfilter.vecX() << "\n"; | ||
std::cout << "\ncorrected state covariance = \n" << kalmanfilter.matP() << "\n"; | ||
} |
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
140 changes: 70 additions & 70 deletions
140
cpp/Examples/kf_state_estimation/main.cpp → cpp/examples/kf_state_estimation/main.cpp
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,70 +1,70 @@ | ||
/// | ||
/// Copyright 2022 Mohanad Youssef (Al-khwarizmi) | ||
/// | ||
/// Use of this source code is governed by an GPL-3.0 - style | ||
/// license that can be found in the LICENSE file or at | ||
/// https://opensource.org/licenses/GPL-3.0 | ||
/// | ||
/// @author Mohanad Youssef <mohanad.magdy.hammad@gmail.com> | ||
/// @file main.cpp | ||
/// | ||
|
||
#include <iostream> | ||
#include <stdint.h> | ||
|
||
#include "kalman_filter/types.h" | ||
#include "kalman_filter/kalman_filter.h" | ||
|
||
static constexpr size_t DIM_X{ 2 }; | ||
static constexpr size_t DIM_Z{ 1 }; | ||
static constexpr kf::float32_t T{ 1.0F }; | ||
static constexpr kf::float32_t Q11{ 0.1F }, Q22{ 0.1F }; | ||
|
||
static kf::KalmanFilter<DIM_X, DIM_Z> kalmanfilter; | ||
|
||
void executePredictionStep(); | ||
void executeCorrectionStep(); | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
executePredictionStep(); | ||
executeCorrectionStep(); | ||
|
||
return 0; | ||
} | ||
|
||
void executePredictionStep() | ||
{ | ||
kalmanfilter.vecX() << 0.0F, 2.0F; | ||
kalmanfilter.matP() << 0.1F, 0.0F, 0.0F, 0.1F; | ||
|
||
kf::Matrix<DIM_X, DIM_X> F; // state transition matrix | ||
F << 1.0F, T, 0.0F, 1.0F; | ||
|
||
kf::Matrix<DIM_X, DIM_X> Q; // process noise covariance | ||
Q(0, 0) = (Q11 * T) + (Q22 * (std::pow(T, 3) / 3.0F)); | ||
Q(0, 1) = Q(1, 0) = Q22 * (std::pow(T, 2) / 2.0F); | ||
Q(1, 1) = Q22 * T; | ||
|
||
kalmanfilter.predictLKF(F, Q); // execute prediction step | ||
|
||
std::cout << "\npredicted state vector = \n" << kalmanfilter.vecX() << "\n"; | ||
std::cout << "\npredicted state covariance = \n" << kalmanfilter.matP() << "\n"; | ||
} | ||
|
||
void executeCorrectionStep() | ||
{ | ||
kf::Vector<DIM_Z> vecZ; | ||
vecZ << 2.25F; | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> matR; | ||
matR << 0.01F; | ||
|
||
kf::Matrix<DIM_Z, DIM_X> matH; | ||
matH << 1.0F, 0.0F; | ||
|
||
kalmanfilter.correctLKF(vecZ, matR, matH); | ||
|
||
std::cout << "\ncorrected state vector = \n" << kalmanfilter.vecX() << "\n"; | ||
std::cout << "\ncorrected state covariance = \n" << kalmanfilter.matP() << "\n"; | ||
} | ||
/// | ||
/// Copyright 2022 Mohanad Youssef (Al-khwarizmi) | ||
/// | ||
/// Use of this source code is governed by an GPL-3.0 - style | ||
/// license that can be found in the LICENSE file or at | ||
/// https://opensource.org/licenses/GPL-3.0 | ||
/// | ||
/// @author Mohanad Youssef <mohanad.magdy.hammad@gmail.com> | ||
/// @file main.cpp | ||
/// | ||
|
||
#include <iostream> | ||
#include <stdint.h> | ||
|
||
#include "types.h" | ||
#include "kalman_filter/kalman_filter.h" | ||
|
||
static constexpr size_t DIM_X{ 2 }; | ||
static constexpr size_t DIM_Z{ 1 }; | ||
static constexpr kf::float32_t T{ 1.0F }; | ||
static constexpr kf::float32_t Q11{ 0.1F }, Q22{ 0.1F }; | ||
|
||
static kf::KalmanFilter<DIM_X, DIM_Z> kalmanfilter; | ||
|
||
void executePredictionStep(); | ||
void executeCorrectionStep(); | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
executePredictionStep(); | ||
executeCorrectionStep(); | ||
|
||
return 0; | ||
} | ||
|
||
void executePredictionStep() | ||
{ | ||
kalmanfilter.vecX() << 0.0F, 2.0F; | ||
kalmanfilter.matP() << 0.1F, 0.0F, 0.0F, 0.1F; | ||
|
||
kf::Matrix<DIM_X, DIM_X> F; // state transition matrix | ||
F << 1.0F, T, 0.0F, 1.0F; | ||
|
||
kf::Matrix<DIM_X, DIM_X> Q; // process noise covariance | ||
Q(0, 0) = (Q11 * T) + (Q22 * (std::pow(T, 3.0F) / 3.0F)); | ||
Q(0, 1) = Q(1, 0) = Q22 * (std::pow(T, 2.0F) / 2.0F); | ||
Q(1, 1) = Q22 * T; | ||
|
||
kalmanfilter.predictLKF(F, Q); // execute prediction step | ||
|
||
std::cout << "\npredicted state vector = \n" << kalmanfilter.vecX() << "\n"; | ||
std::cout << "\npredicted state covariance = \n" << kalmanfilter.matP() << "\n"; | ||
} | ||
|
||
void executeCorrectionStep() | ||
{ | ||
kf::Vector<DIM_Z> vecZ; | ||
vecZ << 2.25F; | ||
|
||
kf::Matrix<DIM_Z, DIM_Z> matR; | ||
matR << 0.01F; | ||
|
||
kf::Matrix<DIM_Z, DIM_X> matH; | ||
matH << 1.0F, 0.0F; | ||
|
||
kalmanfilter.correctLKF(vecZ, matR, matH); | ||
|
||
std::cout << "\ncorrected state vector = \n" << kalmanfilter.vecX() << "\n"; | ||
std::cout << "\ncorrected state covariance = \n" << kalmanfilter.matP() << "\n"; | ||
} |
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
Oops, something went wrong.