|
|
@@ -1,5 +1,7 @@
|
|
|
#define __MOTOR1_DEF
|
|
|
#include "ABIS_User.h"
|
|
|
+#include <math.h>
|
|
|
+
|
|
|
|
|
|
#define MAX_SETP_OF_X 500000
|
|
|
#define MAX_SETP_OF_X_LEAVEOPT 100000
|
|
|
@@ -42,29 +44,52 @@ void InitMotorXPWM(void){
|
|
|
IFS0bits.T2IF = 0;
|
|
|
IPC1bits.T2IP = 7;
|
|
|
}
|
|
|
+// S型曲线数学变换
|
|
|
+float sigmoid(float x) {
|
|
|
+ return 1.0f / (1.0f + expf(-x));
|
|
|
+}
|
|
|
+
|
|
|
/*******************************************************************************
|
|
|
* 函数名称:SetMotor
|
|
|
*******************************************************************************/
|
|
|
void SetMotorX(unsigned long int Pulses,unsigned int spd,unsigned long int *AccPLS,unsigned long int *constVPLS)
|
|
|
{
|
|
|
+ float deno ;
|
|
|
+ float melo ;
|
|
|
+ float fre;
|
|
|
+ float flexible=MOTORX_XFLEXIBLE;
|
|
|
+ float x_scale;
|
|
|
unsigned int i;
|
|
|
- unsigned int Prd;
|
|
|
- Prd = 625000 / spd;
|
|
|
- for (i = 0; i < MOTORX_ACC; i++) {
|
|
|
- if ((Prd < g_uiMotorXPeriod[i])&&(Prd >= g_uiMotorXPeriod[i + 1])) {
|
|
|
- *AccPLS = i + 1;
|
|
|
- break;
|
|
|
- } else if (Prd == g_uiMotorXPeriod[i]) {
|
|
|
- *AccPLS = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (Pulses >= *AccPLS + *AccPLS) {
|
|
|
- *constVPLS = Pulses - *AccPLS;
|
|
|
- } else if (Pulses < *AccPLS + *AccPLS) {
|
|
|
- *AccPLS = Pulses / 2;
|
|
|
+ unsigned int Prd;
|
|
|
+ unsigned long int accPlus;
|
|
|
+ static unsigned int lastspd=0;
|
|
|
+ if(spd < g_tEE.uiXSpeedMin)spd = g_tEE.uiXSpeedMin;
|
|
|
+ if(spd > g_tEE.uiXSpeedMax)spd = g_tEE.uiXSpeedMax;
|
|
|
+ accPlus = (spd- g_tEE.uiXSpeedMin)/flexible;
|
|
|
+ if(accPlus > MOTORX_ACC){
|
|
|
+ accPlus = MOTORX_ACC;
|
|
|
+ flexible = (spd- g_tEE.uiXSpeedMin)/accPlus;
|
|
|
+ }
|
|
|
+ if((Pulses/2)>accPlus){
|
|
|
+ *AccPLS = accPlus;
|
|
|
+ *constVPLS = Pulses - *AccPLS;
|
|
|
+ }else{
|
|
|
+ *AccPLS = Pulses / 2;
|
|
|
*constVPLS = *AccPLS;
|
|
|
- }
|
|
|
+ }
|
|
|
+ if(lastspd != spd){
|
|
|
+ /*只在速度变化时候,跟新曲线参数*/
|
|
|
+ float Fdelt = spd- g_tEE.uiXSpeedMin;
|
|
|
+ x_scale = accPlus;
|
|
|
+// g_uiMotorXPeriod[0] = (unsigned short)(625000.0/g_tEE.uiXSpeedMin);
|
|
|
+ g_uiMotorXPeriod[accPlus] = (unsigned short)(625000.0/spd);
|
|
|
+ for(i=0; i<(accPlus); i++){
|
|
|
+ float melo =flexible * (i - x_scale) / x_scale;
|
|
|
+ deno = sigmoid(melo);
|
|
|
+ fre = Fdelt * deno + g_tEE.uiXSpeedMin;
|
|
|
+ g_uiMotorXPeriod[i] = (unsigned short)(625000.0/fre);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
/*******************************************************************************
|
|
|
* 函数名称:MotorHome
|
|
|
@@ -82,7 +107,7 @@ unsigned int MotorXHome(unsigned int pulseoffset,unsigned int MOVEspd,unsigned i
|
|
|
PulseNum=0;
|
|
|
if(HOMEX == 0){
|
|
|
MOTORX_DIR = FORWARD;
|
|
|
- Freq=5000000/LEAVspd;
|
|
|
+ Freq=2500000/LEAVspd;
|
|
|
TMR8=0;
|
|
|
PR8=Freq;
|
|
|
IFS3bits.T8IF = 0;
|
|
|
@@ -97,7 +122,7 @@ unsigned int MotorXHome(unsigned int pulseoffset,unsigned int MOVEspd,unsigned i
|
|
|
MOTORX_PWM=0;
|
|
|
}else{
|
|
|
MOTORX_DIR = REVERSAL;
|
|
|
- Freq=5000000/MOVEspd;
|
|
|
+ Freq=2500000/MOVEspd;
|
|
|
TMR8=0;
|
|
|
PR8=Freq;
|
|
|
IFS3bits.T8IF = 0;
|