didadida 发表于 2013-12-8 11:58:04

【分享】MWC四轴源码结构浅析

之前的帖子分享过我国赛准备的模块以及上位机,不管怎么说,国赛切切实实的准备了一个多月,从早8点到晚9点一直在实验室。最后没有比赛成绩,我也没啥好说的了。本来拿个所谓的省奖神马的是一点问题没有的,然后就能顺利保研了(成绩平均成绩82.1+一些加分项)。选择了四轴的题目,也许就是对自己太自信了,最后赔了夫人又折兵。真的是没有收获么?absolutely not!
这个帖子主要分享一下我对MWC代码结构的一点点理解,我觉得,总有一些美好的东西,值得我们去追寻的~
之前的帖子也分享过其他版本的MWC源码中,不开us级中断测量程序运行时间以及超声波测距的分析,如果感兴趣,请自行搜索我的帖子。
这次分享的MWC源码,是另一个版本。这个版本吸引我的地方主要有两点:1.十分清晰的程序结构(稍后分析)2.十分强大的调试手段
首先谈谈第一点。这个工程的整体思路就是,一个ms时基中断用于更新所有任务的时间标志(在相应的时间到达后,更新时间标志,一共七个时间标志,依次是2ms,5ms,10ms,20ms,100ms,200ms,1000ms),然后在main循环体中依次判断相应的时间标志,如果为true,则执行此时应当执行的任务,当然,在执行任务之前,先将时间标志复位为false。以此循环往复。。。这个思路其实是典型的时间片的思路,对于多任务系统,又要求一定的实时性,具有十分重要的参考意义。更进一步的学习请参考《时间触发嵌入式系统设计模式》一书,在后边有下载链接。
然后谈谈第二点。我们知道,做一个控制系统,一个十分便捷的调试系统是十分关键和必要的,有时候甚至决定了成败。这个工程里边,serial.c文件就是一个强大完备的调试系统,实现人机交互的所有细节。src文件夹下的executiveAnalysis.xlsx文件详细描述了所有的指令对应的反馈数据类型,比如说,上位机发送字母‘a’,反馈的数据为Loop Delta Times,也就是各个任务循环的周期。说这个是一个强大完备的调试系统,一个表现就是它支持的输入指令范围为'a'--'x'、'A'--'Z'以及几个特殊字符。想了解具体含义,参见上边提到的xlsx文件。
文末,附上我本次比赛移植到瑞萨的MWC源码。去掉了PPM遥控解码部分,去掉了地磁传感器部分,加入了自己的简单控制方法,
其中,我对serial.c文件中这个调试手段做了比较详细的分析,详见//部分。之所以用英文,因为瑞萨坑爹的环境对中文的支持很一般,对本次瑞萨编译环境的吐槽就免了吧。。。
在最后,还有我初步调试的一些视频,其实效果一般吧,因为后来就投身找工作的大潮去了。。。本文还是重在分析思想吧,欢迎讨论交流。

switch (queryType)
    {
                //it took me a lot of headache time to figure out that
                //why the serial function won't increase the time of other functions' deltaTime...
                //now,I finally make it clear...
                //first,it dose increase the time of others,but the serial function is executed per 100ms,not all the time
                //second,the time of functions which are executed quicker than 100ms(eg.20ms,2ms)will appear "normally",
                //because they are influenced only when the serial function is executed,the time is refreshed later...
                //the time of slower functions(eg.200ms,1000ms) will be influenced,but the interval time won't be((A+c)-(B+c)=(A-B))
                //something still needs to be awared of is the executed time of the serial function must not be too long
                //because the time of other functions need to be refreshed before the serial function looped again
                //oh my god,if the slower function is executed before the serial function,it won't be influenced at all...
      case 'a': // Loop Delta Times
              itoa( deltaTime1000Hz, numberString, 10 ); my_printf(numberString); my_printf(", ");
              itoa( deltaTime500Hz,numberString, 10 ); my_printf(numberString); my_printf(", ");
              itoa( deltaTime200Hz,numberString, 10 ); my_printf(numberString); my_printf(", ");
              itoa( deltaTime100Hz,numberString, 10 ); my_printf(numberString); my_printf(", ");
              itoa( deltaTime50Hz,   numberString, 10 ); my_printf(numberString); my_printf(", ");
              itoa( deltaTime10Hz,   numberString, 10 ); my_printf(numberString); my_printf(", ");
              itoa( deltaTime5Hz,    numberString, 10 ); my_printf(numberString); my_printf(", ");
              itoa( deltaTime1Hz,    numberString, 10 ); my_printf(numberString); my_printf(rn);
              break;
移植版工程源码(瑞萨):

原版工程源码(stm32):

《时间触发嵌入式系统设计模式》下载链接:
http://pan.baidu.com/s/1CIae2
测试视频链接:
http://v.youku.com/v_show/id_XNjQ1Mjg3MDg4.html
http://v.youku.com/v_show/id_XNjQ1Mjg3MjMy.html
http://v.youku.com/v_show/id_XNjQ1Mjg3Mzky.html
最后一个视频桨打断了。。。

mahengyu 发表于 2013-12-8 12:06:16

帮顶            

didadida 发表于 2013-12-8 20:14:58

mahengyu 发表于 2013-12-8 12:06
帮顶

多谢帮顶~

zmkj520 发表于 2013-12-10 22:35:27

顶楼主~~

bygreencn 发表于 2013-12-10 23:08:07

顶楼主~~

tornadoes 发表于 2013-12-15 14:01:33

顶楼主*^_^*

victor9079 发表于 2013-12-16 15:35:08

正需要谢谢分享

yue621 发表于 2014-1-29 14:52:09

太牛叉了必须顶起~!!!

bli19 发表于 2014-1-31 19:21:48

帮顶,建议以后四轴测试找宽一点的地方。

小乖 发表于 2014-2-26 10:10:59

楼主真是强人,我也对这个感兴趣
页: [1]
查看完整版本: 【分享】MWC四轴源码结构浅析