规范模块目录和第三方依赖结构
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
#ifndef CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
||||
#define CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
||||
|
||||
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
// 曲柄摇块机构(正解)
|
||||
class CrankRockingBlockMechanism_Forward
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
MechanismType type;
|
||||
MechanismParameters parameters;
|
||||
|
||||
// 轨迹数据
|
||||
std::vector<Vector2D> trajectoryB; // 滑块B的轨迹
|
||||
std::vector<Vector2D> crankCirclePoints; // 曲柄端点A的轨迹
|
||||
std::vector<Vector2D> rockerTrajectory; // 摇块轨迹
|
||||
|
||||
// 性能统计
|
||||
int frameCount;
|
||||
SimpleTimer timer;
|
||||
|
||||
// 配置参数
|
||||
double thetaADelta;
|
||||
double thetaAValueFactor;
|
||||
int thetaAFlip;
|
||||
|
||||
public:
|
||||
CrankRockingBlockMechanism_Forward();
|
||||
|
||||
// 基本属性
|
||||
std::string getName() const;
|
||||
MechanismType getType() const;
|
||||
MechanismParameters getParameters() const;
|
||||
void setParameters(const MechanismParameters ¶ms);
|
||||
|
||||
// 设置连杆长度
|
||||
void setLink(double OA, double AB, double OC);
|
||||
void setOA(double length);
|
||||
void setAB(double length);
|
||||
void setOC(double distance);
|
||||
|
||||
// 配置方法
|
||||
void setThetaADelta(double delta);
|
||||
void setThetaAValueFactor(double factor);
|
||||
void setThetaAFlip(int flip);
|
||||
|
||||
// 主要计算函数
|
||||
MechanismState calculate(double crankAngleDeg);
|
||||
|
||||
// 获取输入范围
|
||||
std::pair<double, double> getInputRange();
|
||||
|
||||
// 轨迹相关
|
||||
std::vector<Vector2D> getTrajectoryPoints() const;
|
||||
std::vector<Vector2D> getCrankCirclePoints() const;
|
||||
std::vector<Vector2D> getRockerTrajectory() const;
|
||||
void clearTrajectory();
|
||||
|
||||
// 参数验证
|
||||
ValidationResult validateParameters();
|
||||
|
||||
// 状态信息
|
||||
std::string getStatusText();
|
||||
|
||||
// 获取配置参数
|
||||
double getThetaADelta() const;
|
||||
double getThetaAValueFactor() const;
|
||||
int getThetaAFlip() const;
|
||||
double getOA() const;
|
||||
double getAB() const;
|
||||
double getOC() const;
|
||||
|
||||
private:
|
||||
Vector2D calculatePointB(const Vector2D &A, const Vector2D &C, double AB);
|
||||
void checkLimitPositions(MechanismState &state, const Vector2D &A,
|
||||
const Vector2D &B, const Vector2D &C,
|
||||
double OA, double AB, double OC);
|
||||
double normalizeAngle(double angle);
|
||||
std::pair<double, double> getValidCrankRange() const;
|
||||
bool checkFullRotationCondition(double OA, double AB, double OC) const;
|
||||
|
||||
// 辅助方法
|
||||
double degreesToRadians(double degrees) const;
|
||||
double radiansToDegrees(double radians) const;
|
||||
std::string formatDouble(double value, int precision = 3) const;
|
||||
};
|
||||
|
||||
#endif // CRANK_ROCKING_BLOCK_MECHANISM_FORWARD_H
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
||||
#define CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
||||
|
||||
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
// 曲柄摇块机构(逆解)
|
||||
class CrankRockingBlockMechanism_Inverse
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
MechanismType type;
|
||||
MechanismParameters parameters;
|
||||
std::vector<Vector2D> trajectoryPoints;
|
||||
|
||||
public:
|
||||
CrankRockingBlockMechanism_Inverse();
|
||||
|
||||
// 基本属性
|
||||
std::string getName() const;
|
||||
MechanismType getType() const;
|
||||
MechanismParameters getParameters() const;
|
||||
void setParameters(const MechanismParameters ¶ms);
|
||||
|
||||
// 设置连杆长度
|
||||
void setLink(double OA, double AB, double OC);
|
||||
void setOA(double length);
|
||||
void setAB(double length);
|
||||
void setOC(double distance);
|
||||
|
||||
// 主要计算函数
|
||||
MechanismState calculate(double acDistance);
|
||||
|
||||
// 获取输入范围
|
||||
std::pair<double, double> getInputRange();
|
||||
|
||||
// 轨迹相关
|
||||
std::vector<Vector2D> getTrajectoryPoints() const;
|
||||
void clearTrajectory();
|
||||
|
||||
// 参数验证
|
||||
ValidationResult validateParameters();
|
||||
|
||||
// 状态信息
|
||||
std::string getStatusText();
|
||||
|
||||
private:
|
||||
std::pair<double, double> getACRange() const;
|
||||
};
|
||||
|
||||
#endif // CRANK_ROCKING_BLOCK_MECHANISM_INVERSE_H
|
||||
201
include/FourBarMechanism/CrankSliderMechanism.h
Normal file
201
include/FourBarMechanism/CrankSliderMechanism.h
Normal file
@@ -0,0 +1,201 @@
|
||||
// mechanism_simulation.h
|
||||
#ifndef MECHANISM_SIMULATION_H
|
||||
#define MECHANISM_SIMULATION_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include "SharedGeometry/SharedGeometry.h" // 包含共享的几何类
|
||||
// 定义常数
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
// // 前向声明
|
||||
// class Vector2D;
|
||||
// class Pose7;
|
||||
// class PoseCalculator;
|
||||
struct MechanismParameters;
|
||||
struct MechanismState;
|
||||
struct ValidationResult;
|
||||
class SimpleTimer;
|
||||
class CrankSliderMechanism;
|
||||
|
||||
// 机构类型枚举
|
||||
enum class MechanismType
|
||||
{
|
||||
Unknown = 0,
|
||||
CrankSlider = 1, // 曲柄滑块机构
|
||||
FourBar = 2, // 四杆机构
|
||||
CrankRockingBlock = 3, // 曲柄摇块机构(逆解)
|
||||
CrankRockingBlock_Forward = 4, // 曲柄摇块机构(正解)
|
||||
};
|
||||
|
||||
// 机制参数结构体
|
||||
struct MechanismParameters
|
||||
{
|
||||
double CrankLength2;
|
||||
double ConnectingRodLength2;
|
||||
double SliderOffset2;
|
||||
double InputValue;
|
||||
double AngularVelocity;
|
||||
|
||||
// 四杆机构参数
|
||||
double L1; // 曲柄
|
||||
double L2; // 连杆
|
||||
double L3; // 摇杆
|
||||
double L4; // 机架
|
||||
|
||||
MechanismParameters();
|
||||
};
|
||||
|
||||
// 机制状态结构体
|
||||
struct MechanismState
|
||||
{
|
||||
std::map<std::string, Vector2D> Points;
|
||||
std::map<std::string, Pose7> Poses;
|
||||
std::map<std::string, double> Angles;
|
||||
double InputValue;
|
||||
std::string ErrorMessage;
|
||||
std::string WarningMessage;
|
||||
|
||||
MechanismState();
|
||||
bool hasError() const;
|
||||
bool hasWarning() const;
|
||||
};
|
||||
|
||||
// 验证结果结构体
|
||||
struct ValidationResult
|
||||
{
|
||||
std::vector<std::string> Errors;
|
||||
std::vector<std::string> Warnings;
|
||||
|
||||
bool isValid() const;
|
||||
std::string getCombinedMessage() const;
|
||||
};
|
||||
|
||||
// 姿态计算器
|
||||
// class PoseCalculator
|
||||
// {
|
||||
// public:
|
||||
// static Pose7 CalculatePoseAndQuaternion(const Vector2D &start, const Vector2D &end);
|
||||
// };
|
||||
|
||||
// 简单的时间封装
|
||||
class SimpleTimer
|
||||
{
|
||||
private:
|
||||
std::chrono::steady_clock::time_point start;
|
||||
|
||||
public:
|
||||
SimpleTimer();
|
||||
void reset();
|
||||
double elapsedSeconds() const;
|
||||
};
|
||||
|
||||
// 曲柄滑块机构类
|
||||
class CrankSliderMechanism
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
MechanismParameters parameters;
|
||||
MechanismType type;
|
||||
|
||||
// 轨迹数据
|
||||
std::vector<Vector2D> trajectoryB;
|
||||
std::vector<Vector2D> sliderTrajectory;
|
||||
std::vector<Vector2D> crankCirclePoints;
|
||||
|
||||
// 性能统计
|
||||
int frameCount;
|
||||
SimpleTimer timer;
|
||||
|
||||
// 配置参数
|
||||
std::string codeBody;
|
||||
std::string l1ABModelName;
|
||||
std::string l2BSModelName;
|
||||
std::string l3SModelName;
|
||||
double thetaADelta;
|
||||
double thetaAValueFactor;
|
||||
int thetaAFlip;
|
||||
|
||||
// 辅助方法
|
||||
double degreesToRadians(double degrees) const;
|
||||
double radiansToDegrees(double radians) const;
|
||||
std::string formatDouble(double value, int precision = 3) const;
|
||||
|
||||
public:
|
||||
CrankSliderMechanism();
|
||||
// json calculate(const json ¶m)
|
||||
// 基本属性访问
|
||||
std::string getName() const;
|
||||
MechanismType getType() const;
|
||||
MechanismParameters getParameters() const;
|
||||
|
||||
void setName(const std::string &newName);
|
||||
void setParameters(const MechanismParameters ¶ms);
|
||||
|
||||
// 设置连杆长度
|
||||
void setLink(double crankLength, double rodLength, double sliderOffset);
|
||||
|
||||
// 配置方法
|
||||
void setThetaADelta(double delta);
|
||||
void setThetaAValueFactor(double factor);
|
||||
void setThetaAFlip(int flip);
|
||||
void setL_AB(double length);
|
||||
void setL_BS(double length);
|
||||
void setS_OFS(double offset);
|
||||
void setCodeBody(const std::string &code);
|
||||
void setL1ABModelName(const std::string &modelName);
|
||||
void setL2BSModelName(const std::string &modelName);
|
||||
void setL3SModelName(const std::string &modelName);
|
||||
|
||||
// 主要计算函数
|
||||
MechanismState calculate(double _angleDeg);
|
||||
|
||||
// 参数验证
|
||||
ValidationResult validateParameters();
|
||||
|
||||
// 获取输入范围
|
||||
std::pair<double, double> getInputRange();
|
||||
|
||||
// 获取轨迹点
|
||||
std::vector<Vector2D> getTrajectoryPoints();
|
||||
|
||||
// 获取滑块轨迹
|
||||
std::vector<Vector2D> getSliderTrajectory() const;
|
||||
|
||||
// 获取曲柄圆轨迹点
|
||||
std::vector<Vector2D> getCrankCirclePoints() const;
|
||||
|
||||
// 清除轨迹
|
||||
void clearTrajectory();
|
||||
|
||||
// 获取状态文本
|
||||
std::string getStatusText();
|
||||
|
||||
// 获取配置参数
|
||||
double getThetaADelta() const;
|
||||
double getThetaAValueFactor() const;
|
||||
int getThetaAFlip() const;
|
||||
double getL_AB() const;
|
||||
double getL_BS() const;
|
||||
double getS_OFS() const;
|
||||
std::string getCodeBody() const;
|
||||
std::string getL1ABModelName() const;
|
||||
std::string getL2BSModelName() const;
|
||||
std::string getL3SModelName() const;
|
||||
};
|
||||
|
||||
// 工厂函数
|
||||
CrankSliderMechanism *createCrankSliderMechanism();
|
||||
void deleteCrankSliderMechanism(CrankSliderMechanism *mechanism);
|
||||
|
||||
// 智能指针版本(可选)
|
||||
using CrankSliderMechanismPtr = std::shared_ptr<CrankSliderMechanism>;
|
||||
CrankSliderMechanismPtr createCrankSliderMechanismSmart();
|
||||
|
||||
#endif // MECHANISM_SIMULATION_H
|
||||
94
include/FourBarMechanism/FourBarMechanism.h
Normal file
94
include/FourBarMechanism/FourBarMechanism.h
Normal file
@@ -0,0 +1,94 @@
|
||||
// FourBarMechanism.h
|
||||
#ifndef FOUR_BAR_MECHANISM_H
|
||||
#define FOUR_BAR_MECHANISM_H
|
||||
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include "SharedGeometry/SharedGeometry.h"
|
||||
|
||||
// 前向声明
|
||||
struct MechanismParameters;
|
||||
struct MechanismState;
|
||||
struct ValidationResult;
|
||||
|
||||
// 四杆机构类
|
||||
class FourBarMechanism
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
MechanismParameters parameters;
|
||||
|
||||
// 轨迹数据
|
||||
std::vector<Vector2D> trajectoryB;
|
||||
std::vector<Vector2D> trajectoryC;
|
||||
std::vector<Vector2D> crankCirclePoints;
|
||||
|
||||
// 性能统计
|
||||
int frameCount;
|
||||
std::chrono::steady_clock::time_point startTime;
|
||||
|
||||
// 辅助方法
|
||||
double degreesToRadians(double degrees) const;
|
||||
double radiansToDegrees(double radians) const;
|
||||
std::string formatDouble(double value, int precision = 2) const;
|
||||
|
||||
// 内部计算方法
|
||||
bool calculatePointC(const Vector2D &A, const Vector2D &D, const Vector2D &B,
|
||||
double l2, double l3, Vector2D &C) const;
|
||||
bool checkGrashofCondition() const;
|
||||
bool isShortestLinkCrank() const;
|
||||
|
||||
public:
|
||||
FourBarMechanism();
|
||||
|
||||
// 基本属性访问
|
||||
std::string getName() const;
|
||||
MechanismType getType() const;
|
||||
MechanismParameters getParameters() const;
|
||||
|
||||
void setName(const std::string &newName);
|
||||
void setParameters(const MechanismParameters ¶ms);
|
||||
|
||||
// 设置杆件长度
|
||||
void setLink(double l1, double l2, double l3, double l4);
|
||||
|
||||
// 主要计算函数
|
||||
MechanismState calculate(double angleDeg);
|
||||
|
||||
// 参数验证
|
||||
ValidationResult validateParameters();
|
||||
|
||||
// 获取输入范围
|
||||
std::pair<double, double> getInputRange();
|
||||
|
||||
// 获取轨迹点
|
||||
std::vector<Vector2D> getTrajectoryPoints() const;
|
||||
std::vector<Vector2D> getTrajectoryC() const;
|
||||
std::vector<Vector2D> getCrankCirclePoints() const;
|
||||
|
||||
// 清除轨迹
|
||||
void clearTrajectory();
|
||||
|
||||
// 获取状态文本
|
||||
std::string getStatusText();
|
||||
|
||||
// 获取参数
|
||||
double getL1() const;
|
||||
double getL2() const;
|
||||
double getL3() const;
|
||||
double getL4() const;
|
||||
};
|
||||
|
||||
// 工厂函数
|
||||
FourBarMechanism *createFourBarMechanism();
|
||||
void deleteFourBarMechanism(FourBarMechanism *mechanism);
|
||||
|
||||
// 智能指针版本
|
||||
using FourBarMechanismPtr = std::shared_ptr<FourBarMechanism>;
|
||||
FourBarMechanismPtr createFourBarMechanismSmart();
|
||||
|
||||
#endif // FOUR_BAR_MECHANISM_H
|
||||
101
include/FourBarMechanism/SliderCrankMechanism.h
Normal file
101
include/FourBarMechanism/SliderCrankMechanism.h
Normal file
@@ -0,0 +1,101 @@
|
||||
// SliderCrankMechanism.h
|
||||
#ifndef SLIDER_CRANK_MECHANISM_H
|
||||
#define SLIDER_CRANK_MECHANISM_H
|
||||
#include "FourBarMechanism/CrankSliderMechanism.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
#include "SharedGeometry/SharedGeometry.h"
|
||||
// 解模式枚举
|
||||
enum class SolutionMode
|
||||
{
|
||||
Auto = 0,
|
||||
Solution1 = 1,
|
||||
Solution2 = 2
|
||||
};
|
||||
|
||||
// 机制参数结构体(扩展版本)
|
||||
struct MechanismParametersExt
|
||||
{
|
||||
double CrankLength;
|
||||
double ConnectingRodLength;
|
||||
double SliderOffset;
|
||||
double InputValue;
|
||||
double AngularVelocity;
|
||||
SolutionMode SolutionMode;
|
||||
std::pair<double, double> CrankAngleRange1;
|
||||
std::pair<double, double> CrankAngleRange2;
|
||||
|
||||
MechanismParametersExt();
|
||||
};
|
||||
// 解模式枚举
|
||||
|
||||
// 曲柄滑块机构逆解类
|
||||
class SliderCrankMechanism
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
MechanismParametersExt parameters;
|
||||
|
||||
// 轨迹数据
|
||||
std::vector<Vector2D> trajectoryB;
|
||||
std::vector<Vector2D> sliderTrajectory;
|
||||
std::vector<Vector2D> trajectoryBAlt;
|
||||
|
||||
// 辅助方法
|
||||
double degreesToRadians(double degrees) const;
|
||||
double radiansToDegrees(double radians) const;
|
||||
std::string formatDouble(double value, int precision = 3) const;
|
||||
double clamp(double value, double min, double max) const;
|
||||
|
||||
// 计算滑块范围
|
||||
std::pair<double, double> calculateSliderRange();
|
||||
|
||||
public:
|
||||
SliderCrankMechanism();
|
||||
|
||||
// 基本属性访问
|
||||
std::string getName() const;
|
||||
MechanismType getType() const;
|
||||
MechanismParametersExt getParameters() const;
|
||||
|
||||
void setName(const std::string &newName);
|
||||
void setParameters(const MechanismParametersExt ¶ms);
|
||||
|
||||
// 设置连杆长度
|
||||
void setLink(double crankLength, double rodLength, double sliderOffset);
|
||||
|
||||
// 设置解模式
|
||||
void setSolutionMode(SolutionMode mode);
|
||||
|
||||
// 主要计算函数(逆解)
|
||||
MechanismState calculate(double sliderX);
|
||||
|
||||
// 参数验证
|
||||
ValidationResult validateParameters();
|
||||
|
||||
// 获取输入范围
|
||||
std::pair<double, double> getInputRange();
|
||||
|
||||
// 获取轨迹点
|
||||
std::vector<Vector2D> getTrajectoryPoints();
|
||||
std::vector<Vector2D> getSliderTrajectory() const;
|
||||
std::vector<Vector2D> getAlternativeTrajectory() const;
|
||||
|
||||
// 清除轨迹
|
||||
void clearTrajectory();
|
||||
|
||||
// 获取状态文本
|
||||
std::string getStatusText();
|
||||
};
|
||||
|
||||
// 工厂函数
|
||||
SliderCrankMechanism *createSliderCrankMechanism();
|
||||
void deleteSliderCrankMechanism(SliderCrankMechanism *mechanism);
|
||||
|
||||
// 智能指针版本
|
||||
using SliderCrankMechanismPtr = std::shared_ptr<SliderCrankMechanism>;
|
||||
SliderCrankMechanismPtr createSliderCrankMechanismSmart();
|
||||
|
||||
#endif // SLIDER_CRANK_MECHANISM_H
|
||||
Reference in New Issue
Block a user