50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
/* USER INCLUDE BEGIN */
|
|
|
|
/* USER INCLUDE END */
|
|
|
|
/* USER DEFINE BEGIN */
|
|
|
|
/* USER DEFINE END */
|
|
/* --- 梯形速度规划器相关定义与函数 --- */
|
|
typedef struct {
|
|
float target_pos; // 最终目标位置
|
|
float start_pos; // 起始位置
|
|
float current_pos; // 瞬时位置 (给PID位置环)
|
|
float current_vel; // 瞬时速度 (给PID速度环前馈)
|
|
|
|
float max_vel; // 最大速度
|
|
float accel; // 加速度
|
|
|
|
float t_acc; // 加速段时间
|
|
float t_total; // 总时间
|
|
float d_acc; // 加速段距离
|
|
float d_cruise; // 匀速段距离
|
|
|
|
float elapsed_time; // 已运行时间
|
|
int direction; // 运行方向 (1 或 -1)
|
|
} TrapezoidalProfile;
|
|
|
|
|
|
/* -------------------------------------------------------- */
|
|
void Profile_Init(TrapezoidalProfile *p, float start, float target, float v_max, float acc);
|
|
|
|
void Profile_Update(TrapezoidalProfile *p, float dt);
|
|
|
|
/* USER FUNCTION BEGIN */
|
|
|
|
/* USER FUNCTION END */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|