
#ifndef _VID29_H_
#define _VID29_H_

#include "stdint.h"
#include "Motor_Controller.h"

/******************************************************************************
步进电机特性参数
******************************************************************************/
#define   STEPPER_MOTOR_TOTAL_PHASE         24        //每一微步对应转子旋转15度,转子旋转一周共24微步
#define   STEPPER_MOTOR_STEP_PER_10DEG      120       //电机输出转轴每10度对应120微步
#define   STEPPER_MOTOR_SPEED_MAX           6000      //电机最大转速,单位:微步/秒
#define   STEPPER_MOTOR_SPEED_MIN           10        //电机最小转速,单位:微步/秒
#define   STEPPER_MOTOR_ACC_MAX             50        //最大加速度,用于限制加速度范围

/******************************************************************************
步进电机应用参数
******************************************************************************/
/*=============================================================================
警告：应用参数必须设置在对应的特性参数范围内
=============================================================================*/
#define   STEPPER_MOTOR_DIR_SWITCH_SPEED    120       //电机最大换向转速,低于此转速电机才可以切换旋转方向,单位:微步/秒
#define   STEPPER_MOTOR_CAL_SPEED_MIN       360       //电机最小校准速度,校正模式时电机以不低于此速度旋转,单位:微步/秒
#define   STEPPER_MOTOR_FULL_RST_SPEED      5000      //电机大角度归零速度,单位:微步/秒
#define   STEPPER_MOTOR_FINE_RST_SPEED      720       //电机小角度归零速度,单位:微步/秒
#define   STEPPER_MOTOR_SHDN_RST_SPEED      4320      //电机断电归零速度,单位:微步/秒

#define   STEPPER_MOTOR_BRAKE_ACC           50        //电机制动加速度
#define   STEPPER_MOTOR_FULL_RST_ACC        30        //电机大角度归零加速度
#define   STEPPER_MOTOR_FINE_RST_ACC        10        //电机小角度归零加速度
#define   STEPPER_MOTOR_SHDN_RST_ACC        5         //电机断电归零加速度

#define   STEPPER_MOTOR_DAMPING_FACTOR      2         //电机阻尼系数,阻尼系数越大,电机减速越慢

/******************************************************************************
步进电机力矩调节
******************************************************************************/
/*=============================================================================
警告：错误的力矩设置将有可能导致步进电机丢步甚至卡滞
      调节力矩时需要考虑同步调整步进电机应用参数
=============================================================================*/
#define   STEPPER_MOTOR_MOMENT_FACTOR       75       //调节范围为0 - 100(对应0% - 100%)

/******************************************************************************
步进电机相位表
******************************************************************************/
static const uint16_t StepperMotorCosDutyCycleTable[STEPPER_MOTOR_TOTAL_PHASE]  =
{
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000) | 0x8000,
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000,  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000,  
};

static const uint16_t StepperMotorSinDutyCycleTable[STEPPER_MOTOR_TOTAL_PHASE]  =
{
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000,  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000,
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000) | 0x8000,
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,
};

#endif
