Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ff40ab1
外部リポジトリ更新
claude-a Jul 22, 2025
deb937b
ビルド修正
claude-a Jul 22, 2025
e4deb30
修正
claude-a Jul 22, 2025
b463022
修正
claude-a Jul 22, 2025
a947f53
修正
claude-a Jul 23, 2025
ff3a714
修正
claude-a Jul 23, 2025
09061f9
作成中
claude-a Jul 23, 2025
7fff649
テスト
claude-a Jul 23, 2025
81b0ba0
テスト完了
claude-a Jul 23, 2025
e08d149
外部リポジトリ更新
claude-a Jul 24, 2025
c5e19e8
外部リポジトリ更新
claude-a Jul 24, 2025
3d01329
修正
claude-a Jul 24, 2025
f54f309
作成中
claude-a Jul 24, 2025
22da7f2
作成中
claude-a Jul 25, 2025
ce8c2bf
作成中
claude-a Jul 26, 2025
782e6e2
作成中
claude-a Jul 26, 2025
c8d8467
作成中
claude-a Jul 26, 2025
d9bf9eb
作成中
claude-a Jul 26, 2025
d265d23
外部リポジトリ更新
claude-a Jul 26, 2025
e8ea680
QR実装を取りやめ
claude-a Jul 26, 2025
d803538
修正
claude-a Jul 26, 2025
5423f5f
コメント追加
claude-a Jul 26, 2025
1108be4
不要ファイル削除
claude-a Jul 27, 2025
c2d1404
外部リポジトリ更新
claude-a Aug 2, 2025
3882274
テスト
claude-a Aug 2, 2025
7c081c8
テスト完了
claude-a Aug 2, 2025
17375ba
Implement convert_SparseAvailable_for_deploy function and integrate i…
claude-a Aug 2, 2025
9d2bd75
テスト
claude-a Aug 2, 2025
0057842
テスト完了
claude-a Aug 2, 2025
8a58e81
Add conversion of SparseAvailable matrices for F, Phi, and solver_fac…
claude-a Aug 2, 2025
4cc69e7
テスト
claude-a Aug 2, 2025
594d2d0
テスト
claude-a Aug 2, 2025
64d62ad
テスト完了
claude-a Aug 2, 2025
678a99f
Refactor indentation handling in MatrixUpdaterToCppVisitor for improv…
claude-a Aug 2, 2025
529da82
Refactor sympy_function parameters and update method signatures for c…
claude-a Aug 2, 2025
45b131d
Refactor parameter order in A_Updater, B_Updater, and C_Updater metho…
claude-a Aug 2, 2025
597aa09
Increase simulation time from 5.0 to 20.0 seconds for extended testing
claude-a Aug 2, 2025
b83991b
Refactor update_parameters function to accept a Parameter struct for …
claude-a Aug 2, 2025
2e1ec6f
Refactor update_parameters to accept a Parameter struct for improved …
claude-a Aug 2, 2025
56e0d4a
Add new SIL implementations for LTI MPC with servo motor and state-sp…
claude-a Aug 2, 2025
9d78c68
Remove obsolete SIL implementations for linear MPC and servo motor co…
claude-a Aug 2, 2025
3defd7b
Update LTI MPC initialization and update calls in servo_motor_SIL.py
claude-a Aug 2, 2025
1576b63
Update SIL implementations to use LTI MPC for servo motor and state-s…
claude-a Aug 2, 2025
b45778b
Enhance parameter handling by exposing Parameter struct in Python bin…
claude-a Aug 2, 2025
c6f42de
テスト
claude-a Aug 2, 2025
e002d46
テスト
claude-a Aug 2, 2025
5ccac24
テスト完了
claude-a Aug 2, 2025
7a95a89
Disable check for Adaptive MPC with float type due to numerical insta…
claude-a Aug 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/run_SIL_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ jobs:

- name: Run SIL tests
run: |
/opt/venv_py_MCAP/bin/python3 ./test_sil/linear_mpc/state_space_SISO_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/linear_mpc/state_space_SISO_trajectory_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/linear_mpc/servo_motor_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/linear_mpc/servo_motor_constraints_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/lti_mpc/state_space_SISO_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/lti_mpc/state_space_SISO_trajectory_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/lti_mpc/servo_motor_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/lti_mpc/servo_motor_constraints_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/servo_motor_ltv_mpc/servo_motor_LTV_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/servo_motor_ltv_mpc_constraints/servo_motor_LTV_constraints_SIL.py
/opt/venv_py_MCAP/bin/python3 ./test_sil/adaptive_mpc_two_wheel_vehicle/two_wheel_vehicle_model_SIL.py
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug Active File",
"name": "Debug Active C++ File",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
Expand All @@ -21,7 +21,7 @@
"ignoreFailures": true
}
],
"preLaunchTask": "Build Active File"
"preLaunchTask": "Build Active C++ File"
}
]
}
5 changes: 3 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"version": "2.0.0",
"tasks": [
{
"label": "Build Active File",
"label": "Build Active C++ File",
"type": "shell",
"command": "/usr/bin/g++",
"args": [
"-g",
"-O0",
"-std=c++11",
"-I${workspaceFolder}",
"-I${workspaceFolder}/mpc_utility",
Expand All @@ -29,7 +30,7 @@
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Build the active C++ file"
"detail": "Build Active C++ File"
}
]
}
14 changes: 9 additions & 5 deletions mpc_utility/mpc_matrices_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,16 @@ def visit_FunctionDef(self, node):
unused_args = [
arg for arg in update_args if arg not in sympy_func_args]

self.indent += " "
for arg in unused_args:
self.cpp_code += f"{self.indent}static_cast<void>({arg});\n"
self.indent = self.indent[:-4]
self.cpp_code += "\n"

if node.name == "sympy_function":
self.cpp_code += f"{self.indent} {ret_type} result;\n\n"
self.indent += " "
self.cpp_code += f"{self.indent}{ret_type} result;\n\n"
self.indent = self.indent[:-4]

# function body
self.indent += " "
Expand Down Expand Up @@ -247,11 +251,11 @@ def visit_Return(self, node):
return_code = np_array_extractor.convert_to_cpp()
self.SparseAvailable = np_array_extractor.SparseAvailable
return_code = return_code.replace(
"\n", "\n" + self.indent + " ")
self.cpp_code += self.indent + " " + return_code + "\n"
self.cpp_code += self.indent + " return result;\n"
"\n", "\n" + self.indent)
self.cpp_code += self.indent + return_code + "\n"
self.cpp_code += self.indent + "return result;\n"
else:
self.cpp_code += self.indent + " return " + return_code + ";\n"
self.cpp_code += self.indent + "return " + return_code + ";\n"

def visit_Assign(self, node):
"""
Expand Down
30 changes: 24 additions & 6 deletions python_mpc/adaptive_mpc_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from external_libraries.python_numpy_to_cpp.python_numpy.numpy_deploy import NumpyDeploy
from external_libraries.MCAP_python_control.python_control.control_deploy import ControlDeploy
from external_libraries.python_control_to_cpp.python_control.kalman_filter_deploy import KalmanFilterDeploy

from mpc_utility.adaptive_matrices_deploy import AdaptiveMatricesDeploy
from python_mpc.common_mpc_deploy import convert_SparseAvailable_for_deploy

from external_libraries.MCAP_python_mpc.python_mpc.adaptive_mpc import AdaptiveMPC_NoConstraints

Expand Down Expand Up @@ -114,8 +116,8 @@ def generate_Adaptive_MPC_NC_cpp_code(
exec(
f"{B_matrix_name} = B_symbolic_SparseAvailable_list[0]")
B_file_name = eval(
f"NumpyDeploy.generate_matrix_cpp_code({B_matrix_name}," +
" caller_file_name_without_ext)")
f"NumpyDeploy.generate_matrix_cpp_code(matrix_in={B_matrix_name}, " +
"file_name=caller_file_name_without_ext)")

deployed_file_names.append(B_file_name)
B_file_name_no_extension = B_file_name.split(".")[0]
Expand Down Expand Up @@ -193,32 +195,48 @@ def generate_Adaptive_MPC_NC_cpp_code(
raise ValueError(
"No parameter file found in EKF deployment files.")

# create F
F_SparseAvailable = convert_SparseAvailable_for_deploy(
ada_mpc_nc.prediction_matrices.F_SparseAvailable)
exec(f"{variable_name}_F = ada_mpc_nc.prediction_matrices.F_ndarray")
F_file_name = eval(
f"NumpyDeploy.generate_matrix_cpp_code({variable_name}_F, caller_file_name_without_ext)")
f"NumpyDeploy.generate_matrix_cpp_code(matrix_in={variable_name}_F, " +
"SparseAvailable=F_SparseAvailable, " +
"file_name=caller_file_name_without_ext)")

deployed_file_names.append(F_file_name)
F_file_name_no_extension = F_file_name.split(".")[0]

# create Phi
Phi_SparseAvailable = convert_SparseAvailable_for_deploy(
ada_mpc_nc.prediction_matrices.Phi_SparseAvailable)
exec(
f"{variable_name}_Phi = ada_mpc_nc.prediction_matrices.Phi_ndarray")
Phi_file_name = eval(
f"NumpyDeploy.generate_matrix_cpp_code({variable_name}_Phi, caller_file_name_without_ext)")
f"NumpyDeploy.generate_matrix_cpp_code(matrix_in={variable_name}_Phi, " +
"SparseAvailable=Phi_SparseAvailable, " +
"file_name=caller_file_name_without_ext)")

deployed_file_names.append(Phi_file_name)
Phi_file_name_no_extension = Phi_file_name.split(".")[0]

# create solver_factor
solver_factor_SparseAvailable = convert_SparseAvailable_for_deploy(
ada_mpc_nc.solver_factor_SparseAvailable)
exec(f"{variable_name}_solver_factor = ada_mpc_nc.solver_factor")
solver_factor_file_name = eval(
f"NumpyDeploy.generate_matrix_cpp_code({variable_name}_solver_factor, caller_file_name_without_ext)")
f"NumpyDeploy.generate_matrix_cpp_code(matrix_in={variable_name}_solver_factor, " +
"SparseAvailable=solver_factor_SparseAvailable, " +
"file_name=caller_file_name_without_ext)")

deployed_file_names.append(solver_factor_file_name)
solver_factor_file_name_no_extension = solver_factor_file_name.split(".")[
0]

exec(f"{variable_name}_Weight_U_Nc = ada_mpc_nc.Weight_U_Nc")
Weight_U_Nc_file_name = eval(
f"NumpyDeploy.generate_matrix_cpp_code({variable_name}_Weight_U_Nc, caller_file_name_without_ext)")
f"NumpyDeploy.generate_matrix_cpp_code(matrix_in={variable_name}_Weight_U_Nc, " +
"file_name=caller_file_name_without_ext)")

deployed_file_names.append(Weight_U_Nc_file_name)
Weight_U_Nc_file_name_no_extension = Weight_U_Nc_file_name.split(".")[
Expand Down
21 changes: 21 additions & 0 deletions python_mpc/common_mpc_deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import sys
sys.path.append(os.getcwd())

import numpy as np
import sympy as sp


def convert_SparseAvailable_for_deploy(SparseAvailable: sp.Matrix) -> np.ndarray:

if not isinstance(SparseAvailable, sp.MatrixBase):
raise TypeError("SparseAvailable must be a sympy Matrix")

SparseAvailable_ndarray = np.zeros(SparseAvailable.shape, dtype=bool)

for i in range(SparseAvailable.shape[0]):
for j in range(SparseAvailable.shape[1]):
if int(SparseAvailable[i, j]) != 0:
SparseAvailable_ndarray[i, j] = True

return SparseAvailable_ndarray
Loading