Skip to content

Commit

Permalink
Rearrange code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuYanzhen1 committed Feb 9, 2022
1 parent 1b9145c commit fd7e315
Show file tree
Hide file tree
Showing 14 changed files with 1,207 additions and 1,234 deletions.
37 changes: 0 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,38 +1 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Executables
*.out
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

.idea
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#include "riccati_solver.h"

#ifndef RUN_CUNIT_TEST
#include "printf.h"
#else
#include "stdio.h"
#include "math.h"
#endif

// P = 96.7181 16.2375 -2.0601
// 16.2375 31.0814 8.2303
// -2.0601 8.2303 11.3719

#define ITERATION_ACCURACY 0.01f

float uabs(float value) {
if (value < 0)
return -1 * value;
else
return value;
}

void solveRiccatiIteration(float A[3][3], float B[3][2], float Q[3][3], float R[2][2]) {
float matrix_p_next[3][3] = {0}, matrix_p[3][3] = {{Q[0][0], Q[0][1], Q[0][2]},
{Q[1][0], Q[1][1], Q[1][2]},
Expand Down Expand Up @@ -113,19 +124,19 @@ void solveRiccatiIteration(float A[3][3], float B[3][2], float Q[3][3], float R[
matrix_p_next[2][1] = matrix_at_pn_a[2][1] - another_matrix[2][1];
matrix_p_next[2][2] = matrix_at_pn_a[2][2] - another_matrix[2][2] + Q[0][0];

float p_next_max_coefficient = fabsf(matrix_p_next[0][0]);
float p_next_max_coefficient = uabs(matrix_p_next[0][0]);
for (unsigned char counter1 = 0; counter1 < 3; ++counter1)
for (unsigned char counter2 = 0; counter2 < 3; ++counter2)
if (p_next_max_coefficient < fabsf(matrix_p_next[counter1][counter2]))
p_next_max_coefficient = fabsf(matrix_p_next[counter1][counter2]);
if (p_next_max_coefficient < uabs(matrix_p_next[counter1][counter2]))
p_next_max_coefficient = uabs(matrix_p_next[counter1][counter2]);

float p_max_coefficient = fabsf(matrix_p[0][0]);
float p_max_coefficient = uabs(matrix_p[0][0]);
for (unsigned char counter1 = 0; counter1 < 3; ++counter1)
for (unsigned char counter2 = 0; counter2 < 3; ++counter2)
if (p_max_coefficient < fabsf(matrix_p[counter1][counter2]))
p_max_coefficient = fabsf(matrix_p[counter1][counter2]);
if (p_max_coefficient < uabs(matrix_p[counter1][counter2]))
p_max_coefficient = uabs(matrix_p[counter1][counter2]);

if (fabsf(p_max_coefficient - p_next_max_coefficient) < ITERATION_ACCURACY) {
if (uabs(p_max_coefficient - p_next_max_coefficient) < ITERATION_ACCURACY) {
printf("\r\niteration counter:%d\r\n", counter);
break;
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion testbench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ endif ()

file(GLOB_RECURSE SOURCES "main.c" "unit_test.c" "script/*.c" "../program/protocol/mdtp_pack.c"
"../program/protocol/gps_parser.c" "../program/protocol/mdtp_unpack.c" "../program/math/sort.c"
"riccati_solver/*.c")
"../program/math/riccati_solver.c")

add_executable(testbench ${SOURCES})
target_link_libraries(testbench cunit m)
1 change: 0 additions & 1 deletion testbench/script/solver_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ void test_riccati_solver(void) {
float Matrix_R[2][2] = {{1, 0},
{0, 1}};
solveRiccatiIteration(Matrix_A, Matrix_B, Matrix_Q, Matrix_R);
CU_PASS("Riccati Solver")
}
148 changes: 74 additions & 74 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------

*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash

# qtcreator generated files
*.pro.user*

# xemacs temporary files
*.flc

# Vim temporary files
.*.swp

# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*

# MinGW generated files
*.Debug
*.Release

# Python byte code
*.pyc

# Binaries
# --------
*.dll
*.exe

build
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------

*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash

# qtcreator generated files
*.pro.user*

# xemacs temporary files
*.flc

# Vim temporary files
.*.swp

# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*

# MinGW generated files
*.Debug
*.Release

# Python byte code
*.pyc

# Binaries
# --------
*.dll
*.exe

build
48 changes: 24 additions & 24 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
cmake_minimum_required(VERSION 3.5)

project(monitor LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(app_WINRC app_win32.rc)

set_property(SOURCE app_win32.rc APPEND PROPERTY
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/icon.ico
)

find_package(Qt5 COMPONENTS Widgets SerialPort PrintSupport REQUIRED)

add_executable(monitor WIN32 ${app_WINRC} main.cpp mainwindow.cpp mainwindow.h
decrypt.cpp encrypt.cpp serial.cpp mainwindow.ui qcustomplot.cpp customplot.cpp)

target_link_libraries(monitor PRIVATE Qt5::Widgets Qt5::SerialPort Qt5::PrintSupport)
cmake_minimum_required(VERSION 3.5)

project(monitor LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(app_WINRC app_win32.rc)

set_property(SOURCE app_win32.rc APPEND PROPERTY
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/icon.ico
)

find_package(Qt5 COMPONENTS Widgets SerialPort PrintSupport REQUIRED)

add_executable(monitor WIN32 ${app_WINRC} main.cpp mainwindow.cpp mainwindow.h
decrypt.cpp encrypt.cpp serial.cpp mainwindow.ui qcustomplot.cpp customplot.cpp)

target_link_libraries(monitor PRIVATE Qt5::Widgets Qt5::SerialPort Qt5::PrintSupport)
Loading

0 comments on commit fd7e315

Please sign in to comment.