规范模块目录和第三方依赖结构
This commit is contained in:
@@ -24,7 +24,13 @@ set(SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
# 头文件目录
|
# 头文件目录
|
||||||
include_directories(src)
|
include_directories(
|
||||||
|
include
|
||||||
|
third_party
|
||||||
|
third_party/kdl_parser/include
|
||||||
|
third_party/orocos_kdl/install_wasm/include
|
||||||
|
third_party/eigen3
|
||||||
|
)
|
||||||
|
|
||||||
# 创建可执行文件
|
# 创建可执行文件
|
||||||
add_executable(smart_wasm ${SOURCES})
|
add_executable(smart_wasm ${SOURCES})
|
||||||
@@ -47,4 +53,4 @@ set_target_properties(smart_wasm PROPERTIES
|
|||||||
SUFFIX ".js"
|
SUFFIX ".js"
|
||||||
OUTPUT_NAME "smart_math"
|
OUTPUT_NAME "smart_math"
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/public/wasm"
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/public/wasm"
|
||||||
)
|
)
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -17,7 +17,7 @@
|
|||||||
```text
|
```text
|
||||||
.
|
.
|
||||||
|-- src/ C++ 业务实现
|
|-- src/ C++ 业务实现
|
||||||
|-- inc/ 公共头文件
|
|-- include/ 公共头文件和业务接口定义
|
||||||
|-- scripts/ 构建、调试、回归测试脚本
|
|-- scripts/ 构建、调试、回归测试脚本
|
||||||
|-- tests/
|
|-- tests/
|
||||||
| |-- testdata/ 正式回归测试数据
|
| |-- testdata/ 正式回归测试数据
|
||||||
@@ -25,9 +25,12 @@
|
|||||||
|-- docs/
|
|-- docs/
|
||||||
| |-- notes/ 功能说明和算法笔记
|
| |-- notes/ 功能说明和算法笔记
|
||||||
| `-- build-logs/ 历史编译记录和调试日志
|
| `-- build-logs/ 历史编译记录和调试日志
|
||||||
|
|-- third_party/
|
||||||
|
| |-- eigen3/ 第三方 Eigen 依赖
|
||||||
|
| |-- kdl_parser/ vendored URDF/KDL parser 源码
|
||||||
|
| |-- nlohmann/ JSON 头文件库
|
||||||
|
| `-- orocos_kdl/ 第三方 KDL 依赖及安装产物
|
||||||
|-- public/wasm/ WASM 构建输出
|
|-- public/wasm/ WASM 构建输出
|
||||||
|-- Eigen3/ 第三方 Eigen 依赖
|
|
||||||
|-- KDL/ 第三方 KDL 依赖及安装产物
|
|
||||||
|-- package.json npm 入口
|
|-- package.json npm 入口
|
||||||
|-- CMakeLists.txt CMake 入口
|
|-- CMakeLists.txt CMake 入口
|
||||||
`-- Makefile Make 入口
|
`-- Makefile Make 入口
|
||||||
@@ -44,6 +47,8 @@ npm run build-serve
|
|||||||
## 📁 目录约定
|
## 📁 目录约定
|
||||||
|
|
||||||
- 根目录只保留项目入口文件和核心目录,避免测试样例、日志、草稿散落在顶层。
|
- 根目录只保留项目入口文件和核心目录,避免测试样例、日志、草稿散落在顶层。
|
||||||
|
- `include/` 只放本项目对外和模块间共享的头文件。
|
||||||
|
- `third_party/` 统一收纳所有外部依赖和 vendored 源码,避免和业务代码混放。
|
||||||
- `tests/testdata/` 放可重复执行的标准化测试数据。
|
- `tests/testdata/` 放可重复执行的标准化测试数据。
|
||||||
- `tests/fixtures/legacy/` 放历史调试输入输出,便于追溯,但默认不作为正式回归入口。
|
- `tests/fixtures/legacy/` 放历史调试输入输出,便于追溯,但默认不作为正式回归入口。
|
||||||
- `docs/notes/` 放业务说明和算法记录。
|
- `docs/notes/` 放业务说明和算法记录。
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
#ifndef CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
||||||
#define CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
#define CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
||||||
|
|
||||||
#include "CrankSliderMechanism.h"
|
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -90,4 +90,4 @@ private:
|
|||||||
std::string formatDouble(double value, int precision = 3) const;
|
std::string formatDouble(double value, int precision = 3) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
#endif // CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
#ifndef CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
||||||
#define CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
#define CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
||||||
|
|
||||||
#include "CrankSliderMechanism.h"
|
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -51,4 +51,4 @@ private:
|
|||||||
std::pair<double, double> getACRange() const;
|
std::pair<double, double> getACRange() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
#endif // CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "SharedGeometry.h" // 包含共享的几何类
|
#include "SharedGeometry/SharedGeometry.h" // 包含共享的几何类
|
||||||
// 定义常数
|
// 定义常数
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
@@ -198,4 +198,4 @@ void deleteCrankSliderMechanism(CrankSliderMechanism *mechanism);
|
|||||||
using CrankSliderMechanismPtr = std::shared_ptr<CrankSliderMechanism>;
|
using CrankSliderMechanismPtr = std::shared_ptr<CrankSliderMechanism>;
|
||||||
CrankSliderMechanismPtr createCrankSliderMechanismSmart();
|
CrankSliderMechanismPtr createCrankSliderMechanismSmart();
|
||||||
|
|
||||||
#endif // MECHANISM_SIMULATION_H
|
#endif // MECHANISM_SIMULATION_H
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
// FourBarMechanism.h
|
// FourBarMechanism.h
|
||||||
#ifndef FOUR_BAR_MECHANISM_H
|
#ifndef FOUR_BAR_MECHANISM_H
|
||||||
#define FOUR_BAR_MECHANISM_H
|
#define FOUR_BAR_MECHANISM_H
|
||||||
#include "CrankSliderMechanism.h"
|
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "SharedGeometry.h"
|
#include "SharedGeometry/SharedGeometry.h"
|
||||||
|
|
||||||
// 前向声明
|
// 前向声明
|
||||||
struct MechanismParameters;
|
struct MechanismParameters;
|
||||||
@@ -91,4 +91,4 @@ void deleteFourBarMechanism(FourBarMechanism *mechanism);
|
|||||||
using FourBarMechanismPtr = std::shared_ptr<FourBarMechanism>;
|
using FourBarMechanismPtr = std::shared_ptr<FourBarMechanism>;
|
||||||
FourBarMechanismPtr createFourBarMechanismSmart();
|
FourBarMechanismPtr createFourBarMechanismSmart();
|
||||||
|
|
||||||
#endif // FOUR_BAR_MECHANISM_H
|
#endif // FOUR_BAR_MECHANISM_H
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
// SliderCrankMechanism.h
|
// SliderCrankMechanism.h
|
||||||
#ifndef SLIDER_CRANK_MECHANISM_H
|
#ifndef SLIDER_CRANK_MECHANISM_H
|
||||||
#define SLIDER_CRANK_MECHANISM_H
|
#define SLIDER_CRANK_MECHANISM_H
|
||||||
#include "CrankSliderMechanism.h"
|
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "SharedGeometry.h"
|
#include "SharedGeometry/SharedGeometry.h"
|
||||||
// 解模式枚举
|
// 解模式枚举
|
||||||
enum class SolutionMode
|
enum class SolutionMode
|
||||||
{
|
{
|
||||||
@@ -98,4 +98,4 @@ void deleteSliderCrankMechanism(SliderCrankMechanism *mechanism);
|
|||||||
using SliderCrankMechanismPtr = std::shared_ptr<SliderCrankMechanism>;
|
using SliderCrankMechanismPtr = std::shared_ptr<SliderCrankMechanism>;
|
||||||
SliderCrankMechanismPtr createSliderCrankMechanismSmart();
|
SliderCrankMechanismPtr createSliderCrankMechanismSmart();
|
||||||
|
|
||||||
#endif // SLIDER_CRANK_MECHANISM_H
|
#endif // SLIDER_CRANK_MECHANISM_H
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include "../inc/nlohmann/json.hpp"
|
#include <nlohmann/json.hpp>
|
||||||
#include "OPERATION.h"
|
#include "QuadrupedRobotSimulation/OPERATION.h"
|
||||||
#include "SharedGeometry.h" // 包含共享的几何类
|
#include "SharedGeometry/SharedGeometry.h"
|
||||||
#include "RobotConfig.hpp"
|
#include "QuadrupedRobotSimulation/RobotConfig.hpp"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -703,4 +703,4 @@ private:
|
|||||||
// 实用函数
|
// 实用函数
|
||||||
Point2D ArrayToPoint(const std::vector<double> &array);
|
Point2D ArrayToPoint(const std::vector<double> &array);
|
||||||
|
|
||||||
#endif // BASE_CLASS_H
|
#endif // BASE_CLASS_H
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
#ifndef COMPLETE_JSON_EXPORTER_H
|
#ifndef COMPLETE_JSON_EXPORTER_H
|
||||||
#define COMPLETE_JSON_EXPORTER_H
|
#define COMPLETE_JSON_EXPORTER_H
|
||||||
|
|
||||||
#include "BaseClass.h"
|
#include "QuadrupedRobotSimulation/BaseClass.h"
|
||||||
#include "KinematicsSimulation.h"
|
#include "QuadrupedRobotSimulation/KinematicsSimulation.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -48,4 +48,4 @@ private:
|
|||||||
static std::string DoubleToString(double value, int precision = 6);
|
static std::string DoubleToString(double value, int precision = 6);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMPLETE_JSON_EXPORTER_H
|
#endif // COMPLETE_JSON_EXPORTER_H
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
#ifndef KINEMATICS_HELPER_H
|
#ifndef KINEMATICS_HELPER_H
|
||||||
#define KINEMATICS_HELPER_H
|
#define KINEMATICS_HELPER_H
|
||||||
|
|
||||||
#include "BaseClass.h"
|
#include "QuadrupedRobotSimulation/BaseClass.h"
|
||||||
#include "KinematicsSimulation.h"
|
#include "QuadrupedRobotSimulation/KinematicsSimulation.h"
|
||||||
#include "KinematicsReverse.h"
|
#include "QuadrupedRobotSimulation/KinematicsReverse.h"
|
||||||
#include "CompleteJsonExporter.h"
|
#include "QuadrupedRobotSimulation/CompleteJsonExporter.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -141,4 +141,4 @@ private:
|
|||||||
static RobotGaitRequest LoadAndValidateJson(const std::string &jsonInput);
|
static RobotGaitRequest LoadAndValidateJson(const std::string &jsonInput);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KINEMATICS_HELPER_H
|
#endif // KINEMATICS_HELPER_H
|
||||||
@@ -12,9 +12,9 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "BaseClass.h"
|
#include "QuadrupedRobotSimulation/BaseClass.h"
|
||||||
#include "OPERATION.h"
|
#include "QuadrupedRobotSimulation/OPERATION.h"
|
||||||
#include "SharedGeometry.h"
|
#include "SharedGeometry/SharedGeometry.h"
|
||||||
|
|
||||||
class ReverseKinematicsCalculator
|
class ReverseKinematicsCalculator
|
||||||
{
|
{
|
||||||
@@ -216,4 +216,4 @@ private:
|
|||||||
std::vector<double> RotateVector(double angle, const std::vector<double> &vector);
|
std::vector<double> RotateVector(double angle, const std::vector<double> &vector);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KINEMATICS_REVERSE_H
|
#endif // KINEMATICS_REVERSE_H
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#ifndef KINEMATICS_SIMULATION_H
|
#ifndef KINEMATICS_SIMULATION_H
|
||||||
#define KINEMATICS_SIMULATION_H
|
#define KINEMATICS_SIMULATION_H
|
||||||
|
|
||||||
#include "BaseClass.h"
|
#include "QuadrupedRobotSimulation/BaseClass.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -198,4 +198,4 @@ private:
|
|||||||
std::vector<double> ShiftArray(const std::vector<double> &array, int shiftFrames);
|
std::vector<double> ShiftArray(const std::vector<double> &array, int shiftFrames);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KINEMATICS_SIMULATION_H
|
#endif // KINEMATICS_SIMULATION_H
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "../inc/nlohmann/json.hpp"
|
#include <nlohmann/json.hpp>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
// 毫米转米函数
|
// 毫米转米函数
|
||||||
@@ -344,4 +344,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OPERATION_H
|
#endif // OPERATION_H
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include "OPERATION.h"
|
#include "QuadrupedRobotSimulation/OPERATION.h"
|
||||||
// 2D向量类
|
// 2D向量类
|
||||||
class Vector2D
|
class Vector2D
|
||||||
{
|
{
|
||||||
@@ -94,4 +94,4 @@ public:
|
|||||||
double x2, double y2);
|
double x2, double y2);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHARED_GEOMETRY_H
|
#endif // SHARED_GEOMETRY_H
|
||||||
@@ -94,27 +94,24 @@ $compileResult = emcc `
|
|||||||
src/utils.cpp `
|
src/utils.cpp `
|
||||||
src/math_utils.cpp `
|
src/math_utils.cpp `
|
||||||
src/smart_json_wrapper.cpp `
|
src/smart_json_wrapper.cpp `
|
||||||
src/kdl_parser/src/kdl_parser.cpp `
|
third_party/kdl_parser/src/kdl_parser.cpp `
|
||||||
src/kdl_parser/src/joint.cpp `
|
third_party/kdl_parser/src/joint.cpp `
|
||||||
src/kdl_parser/src/link.cpp `
|
third_party/kdl_parser/src/link.cpp `
|
||||||
src/kdl_parser/src/model.cpp `
|
third_party/kdl_parser/src/model.cpp `
|
||||||
src/kdl_parser/src/pose.cpp `
|
third_party/kdl_parser/src/pose.cpp `
|
||||||
src/kdl_parser/src/tinystr.cpp `
|
third_party/kdl_parser/src/tinystr.cpp `
|
||||||
src/kdl_parser/src/tinyxml.cpp `
|
third_party/kdl_parser/src/tinyxml.cpp `
|
||||||
src/kdl_parser/src/tinyxml2.cpp `
|
third_party/kdl_parser/src/tinyxml2.cpp `
|
||||||
src/kdl_parser/src/tinyxmlerror.cpp `
|
third_party/kdl_parser/src/tinyxmlerror.cpp `
|
||||||
src/kdl_parser/src/tinyxmlparser.cpp `
|
third_party/kdl_parser/src/tinyxmlparser.cpp `
|
||||||
src/kdl_parser/src/twist.cpp `
|
third_party/kdl_parser/src/twist.cpp `
|
||||||
src/kdl_parser/src/world.cpp `
|
third_party/kdl_parser/src/world.cpp `
|
||||||
-I./inc `
|
-I./include `
|
||||||
-I./inc/QuadrupedRobotSimulation `
|
-I./third_party `
|
||||||
-I./inc/FourBarMechanism `
|
-I./third_party/kdl_parser/include `
|
||||||
-I./inc/SharedGeometry `
|
-I./third_party/orocos_kdl/install_wasm/include `
|
||||||
-I./src/kdl_parser/include `
|
-I./third_party/eigen3 `
|
||||||
-I./KDL/install_wasm/include `
|
-L./third_party/orocos_kdl/install_wasm/lib `
|
||||||
-I./Eigen3 `
|
|
||||||
-I./Eigen3/eigen3 `
|
|
||||||
-L./KDL/install_wasm/lib `
|
|
||||||
-lorocos-kdl `
|
-lorocos-kdl `
|
||||||
-std=c++17 `
|
-std=c++17 `
|
||||||
-s WASM=1 `
|
-s WASM=1 `
|
||||||
|
|||||||
@@ -3,8 +3,42 @@
|
|||||||
Write-Host "=== 重新构建 WASM 模块 ===" -ForegroundColor Cyan
|
Write-Host "=== 重新构建 WASM 模块 ===" -ForegroundColor Cyan
|
||||||
|
|
||||||
# 设置环境
|
# 设置环境
|
||||||
$EmsdkPath = "E:\emsdk"
|
$emsdkCandidates = @()
|
||||||
if (-not (Test-Path $EmsdkPath)) {
|
|
||||||
|
if ($env:EMSDK) {
|
||||||
|
$emsdkCandidates += $env:EMSDK
|
||||||
|
}
|
||||||
|
|
||||||
|
$emsdkCandidates += "E:\emsdk"
|
||||||
|
$emsdkCandidates += (Join-Path (Split-Path $PSScriptRoot -Parent) "..\emsdk")
|
||||||
|
$emsdkCandidates += (Join-Path (Split-Path $PSScriptRoot -Parent) "emsdk")
|
||||||
|
|
||||||
|
$emccCommand = Get-Command emcc -ErrorAction SilentlyContinue
|
||||||
|
if ($emccCommand -and $emccCommand.Source) {
|
||||||
|
$emccSourceDir = Split-Path $emccCommand.Source -Parent
|
||||||
|
if (Test-Path (Join-Path $emccSourceDir "emcc.ps1")) {
|
||||||
|
$emsdkCandidates += (Split-Path (Split-Path $emccSourceDir -Parent) -Parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$EmsdkPath = $null
|
||||||
|
foreach ($candidate in $emsdkCandidates | Select-Object -Unique) {
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($candidate)) {
|
||||||
|
try {
|
||||||
|
if (Test-Path $candidate) {
|
||||||
|
$resolvedCandidate = [System.IO.Path]::GetFullPath($candidate)
|
||||||
|
if (Test-Path (Join-Path $resolvedCandidate "upstream\emscripten\emcc.ps1")) {
|
||||||
|
$EmsdkPath = $resolvedCandidate
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $EmsdkPath) {
|
||||||
Write-Host "[错误] 未找到 Emscripten" -ForegroundColor Red
|
Write-Host "[错误] 未找到 Emscripten" -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -18,7 +52,7 @@ Write-Host "[ ] 编译 WASM 模块(包含完整的运行时方法)..." -Fore
|
|||||||
|
|
||||||
# 完整的编译命令
|
# 完整的编译命令
|
||||||
$compileCmd = @'
|
$compileCmd = @'
|
||||||
emcc src/math_utils.cpp src/smart_json_wrapper.cpp src/main.cpp -I./src -std=c++17 -s WASM=1 -s EXPORTED_FUNCTIONS='["_smart_process_json","_smart_get_function_list","_smart_get_function_info","_smart_test_match","_smart_get_version","_smart_free_string","_main"]' -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap","UTF8ToString","stringToUTF8","lengthBytesUTF8","allocateUTF8","allocate","ALLOC_NORMAL","getValue","setValue"]' -s MODULARIZE=1 -s EXPORT_NAME="createSmartMathModule" -s ALLOW_MEMORY_GROWTH=1 -s ASSERTIONS=1 -O3 -o public/wasm/smart_math.js
|
emcc src/math_utils.cpp src/smart_json_wrapper.cpp src/main.cpp -I./include -I./third_party -I./third_party/kdl_parser/include -I./third_party/orocos_kdl/install_wasm/include -I./third_party/eigen3 -std=c++17 -s WASM=1 -s EXPORTED_FUNCTIONS='["_smart_process_json","_smart_get_function_list","_smart_get_function_info","_smart_test_match","_smart_get_version","_smart_free_string","_main"]' -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap","UTF8ToString","stringToUTF8","lengthBytesUTF8","allocateUTF8","allocate","ALLOC_NORMAL","getValue","setValue"]' -s MODULARIZE=1 -s EXPORT_NAME="createSmartMathModule" -s ALLOW_MEMORY_GROWTH=1 -s ASSERTIONS=1 -O3 -o public/wasm/smart_math.js
|
||||||
'@
|
'@
|
||||||
|
|
||||||
Write-Host "执行命令: $compileCmd" -ForegroundColor Gray
|
Write-Host "执行命令: $compileCmd" -ForegroundColor Gray
|
||||||
|
|||||||
@@ -3,17 +3,60 @@
|
|||||||
Write-Host "=== 测试编译 ===" -ForegroundColor Cyan
|
Write-Host "=== 测试编译 ===" -ForegroundColor Cyan
|
||||||
|
|
||||||
# 设置环境
|
# 设置环境
|
||||||
$EmsdkPath = "E:\emsdk"
|
$emsdkCandidates = @()
|
||||||
if (-not (Test-Path $EmsdkPath)) {
|
|
||||||
|
if ($env:EMSDK) {
|
||||||
|
$emsdkCandidates += $env:EMSDK
|
||||||
|
}
|
||||||
|
|
||||||
|
$emsdkCandidates += "E:\emsdk"
|
||||||
|
$emsdkCandidates += (Join-Path (Split-Path $PSScriptRoot -Parent) "..\emsdk")
|
||||||
|
$emsdkCandidates += (Join-Path (Split-Path $PSScriptRoot -Parent) "emsdk")
|
||||||
|
|
||||||
|
$emccCommand = Get-Command emcc -ErrorAction SilentlyContinue
|
||||||
|
if ($emccCommand -and $emccCommand.Source) {
|
||||||
|
$emccSourceDir = Split-Path $emccCommand.Source -Parent
|
||||||
|
if (Test-Path (Join-Path $emccSourceDir "emcc.ps1")) {
|
||||||
|
$emsdkCandidates += (Split-Path (Split-Path $emccSourceDir -Parent) -Parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$EmsdkPath = $null
|
||||||
|
foreach ($candidate in $emsdkCandidates | Select-Object -Unique) {
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($candidate)) {
|
||||||
|
try {
|
||||||
|
if (Test-Path $candidate) {
|
||||||
|
$resolvedCandidate = [System.IO.Path]::GetFullPath($candidate)
|
||||||
|
if (Test-Path (Join-Path $resolvedCandidate "upstream\emscripten\emcc.ps1")) {
|
||||||
|
$EmsdkPath = $resolvedCandidate
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $EmsdkPath) {
|
||||||
Write-Host "[错误] 未找到 Emscripten" -ForegroundColor Red
|
Write-Host "[错误] 未找到 Emscripten" -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$env:PATH = "$EmsdkPath\upstream\emscripten;$env:PATH"
|
$env:PATH = "$EmsdkPath\upstream\emscripten;$env:PATH"
|
||||||
|
|
||||||
|
# 公共包含目录
|
||||||
|
$includeArgs = @(
|
||||||
|
'-I./include',
|
||||||
|
'-I./third_party',
|
||||||
|
'-I./third_party/kdl_parser/include',
|
||||||
|
'-I./third_party/orocos_kdl/install_wasm/include',
|
||||||
|
'-I./third_party/eigen3'
|
||||||
|
)
|
||||||
|
|
||||||
# 测试 1: 编译 math_utils.cpp
|
# 测试 1: 编译 math_utils.cpp
|
||||||
Write-Host "[ ] 测试编译 math_utils.cpp..." -ForegroundColor Cyan
|
Write-Host "[ ] 测试编译 math_utils.cpp..." -ForegroundColor Cyan
|
||||||
emcc src/math_utils.cpp -I./src -s WASM=1 -c -o test_math.o 2>&1
|
emcc src/math_utils.cpp @includeArgs -s WASM=1 -c -o test_math.o 2>&1
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-Host "[✓] math_utils.cpp 编译成功" -ForegroundColor Green
|
Write-Host "[✓] math_utils.cpp 编译成功" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
@@ -22,7 +65,7 @@ if ($LASTEXITCODE -eq 0) {
|
|||||||
|
|
||||||
# 测试 2: 编译 smart_json_wrapper.cpp
|
# 测试 2: 编译 smart_json_wrapper.cpp
|
||||||
Write-Host "[ ] 测试编译 smart_json_wrapper.cpp..." -ForegroundColor Cyan
|
Write-Host "[ ] 测试编译 smart_json_wrapper.cpp..." -ForegroundColor Cyan
|
||||||
emcc src/smart_json_wrapper.cpp -I./src -s WASM=1 -c -o test_wrapper.o 2>&1
|
emcc src/smart_json_wrapper.cpp @includeArgs -s WASM=1 -c -o test_wrapper.o 2>&1
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-Host "[✓] smart_json_wrapper.cpp 编译成功" -ForegroundColor Green
|
Write-Host "[✓] smart_json_wrapper.cpp 编译成功" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
@@ -31,7 +74,7 @@ if ($LASTEXITCODE -eq 0) {
|
|||||||
|
|
||||||
# 测试 3: 编译 main.cpp
|
# 测试 3: 编译 main.cpp
|
||||||
Write-Host "[ ] 测试编译 main.cpp..." -ForegroundColor Cyan
|
Write-Host "[ ] 测试编译 main.cpp..." -ForegroundColor Cyan
|
||||||
emcc src/main.cpp -I./src -s WASM=1 -c -o test_main.o 2>&1
|
emcc src/main.cpp @includeArgs -s WASM=1 -c -o test_main.o 2>&1
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-Host "[✓] main.cpp 编译成功" -ForegroundColor Green
|
Write-Host "[✓] main.cpp 编译成功" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "CrankRockingBlockMechanism_Forward.h"
|
#include "FourBarMechanism/CrankRockingBlockMechanism_Forward.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -477,4 +477,4 @@ string CrankRockingBlockMechanism_Forward::formatDouble(double value, int precis
|
|||||||
char buffer[32];
|
char buffer[32];
|
||||||
snprintf(buffer, sizeof(buffer), "%.*f", precision, value);
|
snprintf(buffer, sizeof(buffer), "%.*f", precision, value);
|
||||||
return string(buffer);
|
return string(buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "CrankRockingBlockMechanism_Inverse.h"
|
#include "FourBarMechanism/CrankRockingBlockMechanism_Inverse.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -258,4 +258,4 @@ string CrankRockingBlockMechanism_Inverse::getStatusText()
|
|||||||
trajectoryPoints.size());
|
trajectoryPoints.size());
|
||||||
|
|
||||||
return string(buffer);
|
return string(buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// mechanism_simulation.cpp
|
// mechanism_simulation.cpp
|
||||||
#include "CrankSliderMechanism.h"
|
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -471,4 +471,4 @@ void deleteCrankSliderMechanism(CrankSliderMechanism *mechanism)
|
|||||||
CrankSliderMechanismPtr createCrankSliderMechanismSmart()
|
CrankSliderMechanismPtr createCrankSliderMechanismSmart()
|
||||||
{
|
{
|
||||||
return std::make_shared<CrankSliderMechanism>();
|
return std::make_shared<CrankSliderMechanism>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// FourBarMechanism.cpp
|
// FourBarMechanism.cpp
|
||||||
#include "FourBarMechanism.h"
|
#include "FourBarMechanism/FourBarMechanism.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -326,4 +326,4 @@ void deleteFourBarMechanism(FourBarMechanism *mechanism)
|
|||||||
FourBarMechanismPtr createFourBarMechanismSmart()
|
FourBarMechanismPtr createFourBarMechanismSmart()
|
||||||
{
|
{
|
||||||
return std::make_shared<FourBarMechanism>();
|
return std::make_shared<FourBarMechanism>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SliderCrankMechanism.cpp
|
// SliderCrankMechanism.cpp
|
||||||
#include "SliderCrankMechanism.h"
|
#include "FourBarMechanism/SliderCrankMechanism.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -371,4 +371,4 @@ void deleteSliderCrankMechanism(SliderCrankMechanism *mechanism)
|
|||||||
SliderCrankMechanismPtr createSliderCrankMechanismSmart()
|
SliderCrankMechanismPtr createSliderCrankMechanismSmart()
|
||||||
{
|
{
|
||||||
return std::make_shared<SliderCrankMechanism>();
|
return std::make_shared<SliderCrankMechanism>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
#include "KinematicsHelper.h"
|
#include "QuadrupedRobotSimulation/KinematicsHelper.h"
|
||||||
#include "KinematicsWebAPI.h"
|
#include "KinematicsWebAPI.h"
|
||||||
#include "CrankSliderMechanism.h"
|
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||||
#include "URDFStrings.h"
|
#include "URDFStrings.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// BaseClass.cpp - 修复type_error::create错误
|
// BaseClass.cpp - 修复type_error::create错误
|
||||||
#include "BaseClass.h"
|
#include "QuadrupedRobotSimulation/BaseClass.h"
|
||||||
|
|
||||||
// 为nlohmann/json添加std::optional支持
|
// 为nlohmann/json添加std::optional支持
|
||||||
namespace nlohmann
|
namespace nlohmann
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// CompleteJsonExporter.cpp
|
// CompleteJsonExporter.cpp
|
||||||
#include "CompleteJsonExporter.h"
|
#include "QuadrupedRobotSimulation/CompleteJsonExporter.h"
|
||||||
#include "BaseClass.h"
|
#include "QuadrupedRobotSimulation/BaseClass.h"
|
||||||
#include "KinematicsSimulation.h"
|
#include "QuadrupedRobotSimulation/KinematicsSimulation.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -711,4 +711,4 @@ std::string CompleteJsonExporter::DoubleToString(double value, int precision)
|
|||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << std::fixed << std::setprecision(precision) << value;
|
oss << std::fixed << std::setprecision(precision) << value;
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// KinematicsHelper.cpp
|
// KinematicsHelper.cpp
|
||||||
#include "KinematicsHelper.h"
|
#include "QuadrupedRobotSimulation/KinematicsHelper.h"
|
||||||
#include "RobotConfig.hpp"
|
#include "QuadrupedRobotSimulation/RobotConfig.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -317,4 +317,4 @@ RobotGaitRequest KinematicsHelper::LoadAndValidateJson(const std::string &jsonIn
|
|||||||
std::cerr << "Error parsing JSON: " << e.what() << std::endl;
|
std::cerr << "Error parsing JSON: " << e.what() << std::endl;
|
||||||
return CreateDefaultRequest();
|
return CreateDefaultRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// KinematicsReverse.cpp
|
// KinematicsReverse.cpp
|
||||||
#include "KinematicsReverse.h"
|
#include "QuadrupedRobotSimulation/KinematicsReverse.h"
|
||||||
#include "graph_utils.hpp"
|
#include "QuadrupedRobotSimulation/graph_utils.hpp"
|
||||||
#include "RobotConfig.hpp"
|
#include "QuadrupedRobotSimulation/RobotConfig.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -1285,4 +1285,4 @@ void ReverseKinematicsCalculator::debugPrintFinalJson(const std::vector<C_ObjSta
|
|||||||
std::cout << " 四元数: [" << obj.qx << ", " << obj.qy << ", "
|
std::cout << " 四元数: [" << obj.qx << ", " << obj.qy << ", "
|
||||||
<< obj.qz << ", " << obj.qw << "]\n";
|
<< obj.qz << ", " << obj.qw << "]\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// KinematicsSimulation.cpp
|
// KinematicsSimulation.cpp
|
||||||
#include "CompleteJsonExporter.h"
|
#include "QuadrupedRobotSimulation/CompleteJsonExporter.h"
|
||||||
#include "KinematicsSimulation.h"
|
#include "QuadrupedRobotSimulation/KinematicsSimulation.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -1356,4 +1356,4 @@ std::vector<double> QuadrupedRobotSimulation::ShiftArray(const std::vector<doubl
|
|||||||
result[(i + shiftFrames) % array.size()] = array[i];
|
result[(i + shiftFrames) % array.size()] = array[i];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "RobotConfig.hpp"
|
#include "QuadrupedRobotSimulation/RobotConfig.hpp"
|
||||||
// 统一的更新函数:手动从JSON更新现有对象
|
// 统一的更新函数:手动从JSON更新现有对象
|
||||||
RequestParameters &RequestParameters::updateFromJson(const nlohmann::json &j, RequestParameters &req_param)
|
RequestParameters &RequestParameters::updateFromJson(const nlohmann::json &j, RequestParameters &req_param)
|
||||||
{
|
{
|
||||||
@@ -843,4 +843,4 @@ bool RequestParameters::saveToFile(const std::string &filename) const
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SharedGeometry.cpp
|
// SharedGeometry.cpp
|
||||||
#include "SharedGeometry.h"
|
#include "SharedGeometry/SharedGeometry.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -208,4 +208,4 @@ C_ObjStates PoseCalculator::CalculatePoseAndQuaternion_C_ObjStates(const std::st
|
|||||||
c_ObjStates.qw = ToString(qw);
|
c_ObjStates.qw = ToString(qw);
|
||||||
|
|
||||||
return c_ObjStates;
|
return c_ObjStates;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../src/smart_json_wrapper.h"
|
#include "../include/smart_json_wrapper.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -185,4 +185,4 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user