修复构建脚本和WASM测试问题
This commit is contained in:
@@ -426,105 +426,109 @@ std::string KinematicsWebAPI::func(std::string sanitized_body)
|
||||
{"error", "Invalid parameters"},
|
||||
{"validation_errors", validation.Errors},
|
||||
{"validation_warnings", validation.Warnings}};
|
||||
return res_data;
|
||||
}
|
||||
|
||||
// 执行计算
|
||||
MechanismState state = mechanism->calculate(angleDeg);
|
||||
|
||||
// 检查是否有错误
|
||||
if (state.hasError())
|
||||
else
|
||||
{
|
||||
res_data = {
|
||||
{"success", false},
|
||||
{"error", state.ErrorMessage}};
|
||||
return res_data;
|
||||
// 执行计算
|
||||
MechanismState state = mechanism->calculate(angleDeg);
|
||||
|
||||
// 检查是否有错误
|
||||
if (state.hasError())
|
||||
{
|
||||
res_data = {
|
||||
{"success", false},
|
||||
{"error", state.ErrorMessage}};
|
||||
}
|
||||
else
|
||||
{
|
||||
// 构建响应数据
|
||||
json result;
|
||||
result["success"] = true;
|
||||
|
||||
// 添加点坐标
|
||||
json points_json;
|
||||
for (const auto &point_pair : state.Points)
|
||||
{
|
||||
json point;
|
||||
point["x"] = point_pair.second.X;
|
||||
point["y"] = point_pair.second.Y;
|
||||
points_json[point_pair.first] = point;
|
||||
}
|
||||
result["points"] = points_json;
|
||||
|
||||
// 添加姿态信息
|
||||
json poses_json;
|
||||
for (const auto &pose_pair : state.Poses)
|
||||
{
|
||||
json pose;
|
||||
pose["tx"] = pose_pair.second.tx;
|
||||
pose["ty"] = pose_pair.second.ty;
|
||||
pose["tz"] = pose_pair.second.tz;
|
||||
pose["qx"] = pose_pair.second.qx;
|
||||
pose["qy"] = pose_pair.second.qy;
|
||||
pose["qz"] = pose_pair.second.qz;
|
||||
pose["qw"] = pose_pair.second.qw;
|
||||
poses_json[pose_pair.first] = pose;
|
||||
}
|
||||
result["poses"] = poses_json;
|
||||
|
||||
// 添加角度信息
|
||||
json angles_json;
|
||||
for (const auto &angle_pair : state.Angles)
|
||||
{
|
||||
angles_json[angle_pair.first] = angle_pair.second;
|
||||
}
|
||||
result["angles"] = angles_json;
|
||||
|
||||
// 添加输入值
|
||||
result["input_value"] = state.InputValue;
|
||||
|
||||
// 添加警告信息(如果有)
|
||||
if (state.hasWarning())
|
||||
{
|
||||
result["warning"] = state.WarningMessage;
|
||||
}
|
||||
|
||||
// 添加轨迹信息
|
||||
std::vector<Vector2D> trajectory = mechanism->getTrajectoryPoints();
|
||||
std::vector<Vector2D> slider_trajectory = mechanism->getSliderTrajectory();
|
||||
|
||||
json trajectory_json;
|
||||
for (size_t i = 0; i < trajectory.size(); i++)
|
||||
{
|
||||
json point;
|
||||
point["x"] = trajectory[i].X;
|
||||
point["y"] = trajectory[i].Y;
|
||||
trajectory_json.push_back(point);
|
||||
}
|
||||
result["trajectory"] = trajectory_json;
|
||||
|
||||
json slider_trajectory_json;
|
||||
for (size_t i = 0; i < slider_trajectory.size(); i++)
|
||||
{
|
||||
json point;
|
||||
point["x"] = slider_trajectory[i].X;
|
||||
point["y"] = slider_trajectory[i].Y;
|
||||
slider_trajectory_json.push_back(point);
|
||||
}
|
||||
result["slider_trajectory"] = slider_trajectory_json;
|
||||
|
||||
// 添加参数信息
|
||||
result["parameters"] = {
|
||||
{"L_AB", L_AB},
|
||||
{"L_BS", L_BS},
|
||||
{"S_OFS", S_OFS},
|
||||
{"angleDeg", angleDeg}};
|
||||
|
||||
res_data = result;
|
||||
}
|
||||
}
|
||||
|
||||
// 构建响应数据
|
||||
json result;
|
||||
result["success"] = true;
|
||||
|
||||
// 添加点坐标
|
||||
json points_json;
|
||||
for (const auto &point_pair : state.Points)
|
||||
{
|
||||
json point;
|
||||
point["x"] = point_pair.second.X;
|
||||
point["y"] = point_pair.second.Y;
|
||||
points_json[point_pair.first] = point;
|
||||
}
|
||||
result["points"] = points_json;
|
||||
|
||||
// 添加姿态信息
|
||||
json poses_json;
|
||||
for (const auto &pose_pair : state.Poses)
|
||||
{
|
||||
json pose;
|
||||
pose["tx"] = pose_pair.second.tx;
|
||||
pose["ty"] = pose_pair.second.ty;
|
||||
pose["tz"] = pose_pair.second.tz;
|
||||
pose["qx"] = pose_pair.second.qx;
|
||||
pose["qy"] = pose_pair.second.qy;
|
||||
pose["qz"] = pose_pair.second.qz;
|
||||
pose["qw"] = pose_pair.second.qw;
|
||||
poses_json[pose_pair.first] = pose;
|
||||
}
|
||||
result["poses"] = poses_json;
|
||||
|
||||
// 添加角度信息
|
||||
json angles_json;
|
||||
for (const auto &angle_pair : state.Angles)
|
||||
{
|
||||
angles_json[angle_pair.first] = angle_pair.second;
|
||||
}
|
||||
result["angles"] = angles_json;
|
||||
|
||||
// 添加输入值
|
||||
result["input_value"] = state.InputValue;
|
||||
|
||||
// 添加警告信息(如果有)
|
||||
if (state.hasWarning())
|
||||
{
|
||||
result["warning"] = state.WarningMessage;
|
||||
}
|
||||
|
||||
// 添加轨迹信息
|
||||
std::vector<Vector2D> trajectory = mechanism->getTrajectoryPoints();
|
||||
std::vector<Vector2D> slider_trajectory = mechanism->getSliderTrajectory();
|
||||
|
||||
json trajectory_json;
|
||||
for (size_t i = 0; i < trajectory.size(); i++)
|
||||
{
|
||||
json point;
|
||||
point["x"] = trajectory[i].X;
|
||||
point["y"] = trajectory[i].Y;
|
||||
trajectory_json.push_back(point);
|
||||
}
|
||||
result["trajectory"] = trajectory_json;
|
||||
|
||||
json slider_trajectory_json;
|
||||
for (size_t i = 0; i < slider_trajectory.size(); i++)
|
||||
{
|
||||
json point;
|
||||
point["x"] = slider_trajectory[i].X;
|
||||
point["y"] = slider_trajectory[i].Y;
|
||||
slider_trajectory_json.push_back(point);
|
||||
}
|
||||
result["slider_trajectory"] = slider_trajectory_json;
|
||||
|
||||
// 添加参数信息
|
||||
result["parameters"] = {
|
||||
{"L_AB", L_AB},
|
||||
{"L_BS", L_BS},
|
||||
{"S_OFS", S_OFS},
|
||||
{"angleDeg", angleDeg}};
|
||||
|
||||
res_data = result;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
res_data = {{"success", false, "error", "Failed to Cmd_FourBar_CrankSlider: " + std::string(e.what())}};
|
||||
res_data = {
|
||||
{"success", false},
|
||||
{"error", "Failed to Cmd_FourBar_CrankSlider: " + std::string(e.what())}};
|
||||
}
|
||||
}
|
||||
else if (req_cmd == "Cmd_QuadrupedRobot_CalculateAllPointsFromMotorAngles")
|
||||
@@ -602,4 +606,4 @@ std::string KinematicsWebAPI::getCurrentTimestamp()
|
||||
bool KinematicsWebAPI::is_running() const
|
||||
{
|
||||
return running_;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/Robot.cpp
BIN
src/Robot.cpp
Binary file not shown.
Reference in New Issue
Block a user