feat(轨迹控制): 添加多种轨迹模式支持并重构轨迹生成逻辑
新增轨迹模式枚举和参数结构体,支持正弦波、圆形、正方形、菱形和8字形五种轨迹模式 重构轨迹生成逻辑为独立的生成函数,增加参数验证和配置灵活性
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
#include "mqtt.hpp"
|
||||
#include "navigation.hpp"
|
||||
#include "recharge.hpp"
|
||||
#include "monitor.hpp"
|
||||
// #include "low_controller.hpp"
|
||||
#include "monitor.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
@@ -19,6 +19,35 @@
|
||||
|
||||
namespace custom {
|
||||
|
||||
/**
|
||||
* @brief 轨迹路径样式枚举
|
||||
*/
|
||||
enum class TrajectoryPattern : int {
|
||||
SINE_WAVE = 0, // 正弦波(原有的波浪形)
|
||||
CIRCLE = 1, // 圆形
|
||||
SQUARE = 2, // 正方形
|
||||
DIAMOND = 3, // 菱形
|
||||
FIGURE_EIGHT = 4 // 8字形
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 轨迹参数结构
|
||||
*/
|
||||
struct TrajectoryParams {
|
||||
TrajectoryPattern pattern = TrajectoryPattern::SINE_WAVE; // 路径样式
|
||||
float scale = 1.0f; // 缩放因子
|
||||
float speed = 0.3f; // 移动速度 (m/s)
|
||||
float frequency = 1.0f; // 频率参数(用于周期性路径)
|
||||
float amplitude = 0.6f; // 振幅参数
|
||||
int points_count = 30; // 路径点数量
|
||||
float time_step = 0.06f; // 时间步长
|
||||
|
||||
// 构造函数
|
||||
TrajectoryParams() = default;
|
||||
TrajectoryParams(TrajectoryPattern p, float s = 1.0f, float sp = 0.3f)
|
||||
: pattern(p), scale(s), speed(sp) {}
|
||||
};
|
||||
|
||||
class CustomRobot {
|
||||
public:
|
||||
explicit CustomRobot();
|
||||
@@ -48,11 +77,17 @@ public:
|
||||
bool processRechargeCmd(const std::string& cmd, const nlohmann::json& message);
|
||||
void printServiceList(const std::vector<unitree::robot::go2::ServiceState>& serviceList, int filterStatus = -1);
|
||||
|
||||
bool startTraj();
|
||||
bool startTraj(const TrajectoryParams& params = TrajectoryParams());
|
||||
void stopTraj();
|
||||
|
||||
private:
|
||||
void trajControl();
|
||||
std::vector<unitree::robot::go2::PathPoint> generateTrajectoryPath(const TrajectoryParams& params);
|
||||
std::vector<unitree::robot::go2::PathPoint> generateSineWavePath(const TrajectoryParams& params);
|
||||
std::vector<unitree::robot::go2::PathPoint> generateCirclePath(const TrajectoryParams& params);
|
||||
std::vector<unitree::robot::go2::PathPoint> generateSquarePath(const TrajectoryParams& params);
|
||||
std::vector<unitree::robot::go2::PathPoint> generateDiamondPath(const TrajectoryParams& params);
|
||||
std::vector<unitree::robot::go2::PathPoint> generateFigureEightPath(const TrajectoryParams& params);
|
||||
std::string generateRandomClientId() const;
|
||||
std::unique_ptr<Controller> controller_;
|
||||
// std::unique_ptr<LowController> low_controller_;
|
||||
@@ -69,6 +104,7 @@ private:
|
||||
std::atomic<bool> traj_running_;
|
||||
float traj_dt_;
|
||||
float traj_count_;
|
||||
TrajectoryParams current_traj_params_; // 当前轨迹参数
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
|
||||
Reference in New Issue
Block a user