亿加合和智能车制作

标题: 重读官方的方案。不知道对不对,特拿过来讨论讨论 [打印本页]

作者: zhu_xuekui    时间: 2012-3-24 05:12
标题: 重读官方的方案。不知道对不对,特拿过来讨论讨论
void TI1_OnInterrupt(void)
{
int i;
  /* Write your code here ... */
   //--------------------------------------------------------------------------
   WAITTIME_INC;                               // Increase WAITTIME function counter;
   if(TIME1MS_INT_FLAG)  return;
   
   //--------------------------------------------------------------------------
   g_n1MSEventCount ++;
if(g_nTimeTestFlag)  TIMETEST_ON;
     
   //--------------------------------------------------------------------------
   g_nSpeedControlPeriod ++;
   SpeedControlOutput();
   
   g_nDirectionControlPeriod ++;
   DirectionControlOutput();

  //--------------------------------------------------------------------------
   if(g_n1MSEventCount >= CONTROL_PERIOD) {    // Motor speed adjust
    g_n1MSEventCount = 0;                   // Clear the event counter;
   
    GetMotorPulse();
   } else if(g_n1MSEventCount == 1) {          // Start ADC convert and Car erect adjust
    if(AD_FLAG) {
   for(i = 0; i < INPUT_VOLTAGE_AVERAGE; i ++)
    SampleInputVoltage();
    }
   } else if(g_n1MSEventCount == 2) {          // Get the voltage and start calculation
  if(AD_FLAG) GetInputVoltageAverage();
  //----------------------------------------------------------------------
  AngleCalculate();
  AngleControl();  
  //----------------------------------------------------------------------
  MotorOutput();                          // Output motor control voltage;   
   } else if(g_n1MSEventCount == 3) {          // Car speed adjust
    g_nSpeedControlCount ++;
    if(g_nSpeedControlCount >= SPEED_CONTROL_COUNT) {
     SpeedControl();
     g_nSpeedControlCount = 0;
     g_nSpeedControlPeriod = 0;     
    }
   } else if(g_n1MSEventCount == 4) {          // Car direction control
  g_nDirectionControlCount ++;
  DirectionVoltageSigma();
  if(g_nDirectionControlCount >= DIRECTION_CONTROL_COUNT) {
     DirectionControl();
     g_nDirectionControlCount = 0;
     g_nDirectionControlPeriod = 0;
    }
   }
   
  //--------------------------------------------------------------------------
  if(g_nTimeTestFlag)  TIMETEST_OFF;
}


此中断时间为1ms,中断服务程序中片段0-4,严格的按照时序,5ms执行一次。但SpeedControlOutput();DirectionControlOutput();两个函数,而是每1ms执行一次,与
官网上说的每5ms执行一次相悖。不知道大家注意没有。不知道是不是这样的,求大神指点。。。


作者: 吉他手    时间: 2012-3-24 09:09
本帖最后由 吉他手 于 2012-3-24 09:10 编辑

你看到的SpeedControlOutput,DirectionControlOutput函数1ms调用一次,是正确的。
只是这个函数的输出是通过SetMotorVoltage最终输出的。而最终输出的函数的周期是5ms。
所以本质上讲SpeedControlOutput,DirectionControlOutput函数是5ms起作用一次。如下图所示:(在设计指南中的有)
[attach]21144[/attach]

作者: 慕名凤姐而来    时间: 2012-3-24 09:14
吉他手 发表于 2012-3-24 09:09
你看到的SpeedControlOutput,DirectionControlOutput函数1ms调用一次,是正确的。
只是这个函数的输出是通 ...

老师,电机对编码器的干扰怎样能减轻呢?   电机外壳接地行么?
作者: yaozhifeng    时间: 2012-3-24 09:22

作者: wo520    时间: 2012-3-24 10:17

作者: lzy0310    时间: 2012-3-24 11:08
吉他手 发表于 2012-3-24 09:09
你看到的SpeedControlOutput,DirectionControlOutput函数1ms调用一次,是正确的。
只是这个函数的输出是通 ...

老师,,现在我的车子直立的很稳了,但是加速度控制不知怎么加。加了跟没加没什么影响。官网的方案 好像最后是直接通过采集编码器速度 然后与给定速度相差来实现 速度控制,进而获得一个倾角,实现控速。。
请问我这样理解的对吗??还是怎么理解。。

作者: 吉他手    时间: 2012-3-24 11:15
lzy0310 发表于 2012-3-24 11:08
老师,,现在我的车子直立的很稳了,但是加速度控制不知怎么加。加了跟没加没什么影响。官网的方案 好像最 ...

在仔细看看指南方案中的框图,最终的控制方案是将速度差速进行PI之后直接叠加在最终的电机输出控制上了。
请你参考指南中的程序来理解即可。
[attach]21148[/attach]

作者: zhu_xuekui    时间: 2012-3-24 16:21
谢谢指点。。。。。。实验之。。。。




欢迎光临 亿加合和智能车制作 (http://www.znczz.com/) Powered by Discuz! X3.2