T_SpeedShape.h 1.7 KB
#ifndef __T_SPEEDSHAPE_H_
#define __T_SPEEDSHAPE_H_


typedef enum
{
    TRAP_CURVE_STA_1_T,
    TRAP_CURVE_STA_2_TRIANGLE,
    TRAP_CURVE_STA_3_BACK,
    TRAP_CURVE_STA_4_STOP,
} TRAP_CURVE_STA;

typedef enum
{
    TRAP_CURVE_CYCMODE_OFF = 0,
    TRAP_CURVE_CYCMODE_M1,
} TRAP_CURVE_CYCMODE;

typedef enum
{
    TRAP_CURVE_CYCSIGN_NONE = 0,
    TRAP_CURVE_CYCSIGN_NEED_CYC,
} TRAP_CURVE_CYCSIGN;

typedef struct
{
    /* Globe Setting Group */
    float vel_Max_Limit;
    float acc_global;

    /* Target Group */
    float target_Position;

    /* Running Status*/
    TRAP_CURVE_STA status;
    float vel_Max;   // the MAX Velocity calculated by target ; The Maximum is vel_Max_Limit
    float vel_Cur;   // the Current velocity ; transitions for state transitions
    float vel_Orig;  // the originate velocity ;
    float pos_Start; // the position where start to move ; Will be flashed when state transitions
    float pos_Cur;   // the current position ;

    float time_Start; // the start time;
    float time_Now;   // the current time;

    float acc_live;

    // /* Vaule PreCalculation */
    // float vel_Orig_2;   //vel_Orig ^ 2

    /* Inter calculate Value */
    float t1; // Tf = t1 + t2 + t3
    float t2;
    float t3;
    float S1_Int;
    float S2_Int;
    float S3_Int;
    float S_Min;
    float Vm; // the Maximum achievable velocity

    int cycMode;
    float cycRange;
    float cycRange_2;
    float target_Position_CYC;
    int cycSign;

} TRAP_CURVE_s;

void trap_Curve_Init(TRAP_CURVE_s *s, float vel_Max_Limit, float acc_global, float time_Now,int cycMode,float cycRange);
void trap_Curve_SetTarget(TRAP_CURVE_s *s, float target_Position);
float trap_Curve_Update(TRAP_CURVE_s *s, float time_Now);

#endif