无刷云台代码分析
if((fabs(pitchRCSpeed)>0.0)&&(pitchAngleACC // pitchSetpoint=constrain(pitchSetpoint,config.minRCPitch,config.maxRCPitch); //630-1130 return constrain(out, -maxDegPerSecond ,maxDegPerSecond);//返回限幅后的数据out pitchDevider = constrain(maxDegPerSecondPitch / (pitchPID + 0.000001), -15000,15000)*2;//调整信号 rollDirection = sgn(rollDevider) * config.dirMotorRoll;//计算电机输出数据1、0、-1 //Serial.println( (micros()-timer)/CC_FACTOR); }
{
gyroPitch = gyroPitch + config.accelWeight * pitchRCSpeed * RC_GAIN;
pitchSetpoint = pitchAngleACC;
}
else
gyroPitch = gyroPitch + config.accelWeight * (pitchAngleACC - pitchSetpoint) /sampleTimeACC;//加入加速度计算出的调节系数吗?
// rollSetpoint=constrain(rollSetpoint,config.minRCRoll,config.maxRCRoll);
//计算电机数据
pitchPID = ComputePID(sampleTimePID,gyroPitch,0.0, &pitchErrorSum, &pitchErrorOld,config.gyroPitchKp,config.gyroPitchKi,config.gyroPitchKd,maxDegPerSecondPitch);
rollPID = ComputePID(sampleTimePID,gyroRoll,0.0, &rollErrorSum, &rollErrorOld,config.gyroRollKp,config.gyroRollKi,config.gyroRollKd,maxDegPerSecondRoll);
//
/*
float ComputePID(float SampleTimeInSecs, float in, float setPoint, float *errorSum, float *errorOld, float Kp, float Ki, float Kd, float maxDegPerSecond)
{
//PID算法说明,PID 分为P比例调节,I积分 预设置和反馈值之间的差值在时间上的累积,累积值大到一定时才处理,有滞后控制的作用。D微分项调节即根据趋势作提前量调整,有提前控制的作用
float error = setPoint - in;//计算差值,0.0-gyroRoll
//算法分析&rollErrorSum+=(0.0-gyroRoll)然后限幅
// Integrate Errors
*errorSum += error;//积分
*errorSum = constrain(*errorSum, -maxDegPerSecond ,maxDegPerSecond);//限幅
/*Compute PID Output*/
//PID算法代码
float out = (Kp * error + SampleTimeInSecs * Ki * *errorSum + Kd * (error - *errorOld) / (SampleTimeInSecs + 0.000001))/1000.0;
//1、比例调节算法P:当前error*Kp(error为差值,Kp为P值即比例调节量,可进行人工设置、基础的调整速度只根据差值大小确定调整快慢)+2、积分调节算法I:总error*Ki*SampleTimeInSecs(差值积分总值*errorSum(是角度值吗?)*调节因子Ki*时间变量+3、微分D 调节,即根据在一定时间内的变化量来确定调整效果的快慢来作一个提前量调整。调整因子Kd*变化量(error - *errorOld)/时间
//D的作用就是在一定时间内判断差值的变化趋势。越大就调的调的越快。越少调的越慢。
//I的算法好像有点问题,不像网上说的那样吗?
*errorOld = error;// &rollErrorOld=error 存本次的差值,以便和下一次角速度即差值比较
}
*/
//1250-1700
pitchDirection = sgn(pitchDevider) * config.dirMotorPitch;//计算电机输出数据1、0、-1只转动一点点 0不转
rollDevider = constrain(maxDegPerSecondRoll / (rollPID + 0.000001), -15000,15000)*2;//2、调整信号 constrain的作用是限幅,功能为如果maxDegPerSecondRoll / (rollPID + 0.000001)小于-15000则返回-15000,大于15000则返回15000。否则返回原来的值 2、+ 0.000001的作用是为了防止rollPID为0吗?3、(rollPID + 0.000001)为角度值?不像但和角度相关
//maxDegPerSecondRoll = MOTORUPDATE_FREQ * 1000.0 / N_SIN / (config.nPolesMotorRoll/2) * 360.0;//转动的最大值吗?
// Initialize Motor Movement (初始化电机运动) 最大值?
// maxDegPerSecondPitch = MOTORUPDATE_FREQ * 1000.0 / N_SIN / (config.nPolesMotorPitch/2) * 360.0;
//maxDegPerSecondRoll = MOTORUPDATE_FREQ * 1000.0 / N_SIN / (config.nPolesMotorRoll/2) * 360.0;
//1400-1850
sCmd.readSerial();
无刷云台代码分 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)