velocityInfo.c

Go to the documentation of this file.
00001 
00010 #include "velocityInfo.h"
00011 #include "movingAverage.h"
00012 
00013 enum { SIZE_SHIFT = 4 };
00014 static movingAverage_t Straight, Rotate;
00015 static int Straight_buff[1 << SIZE_SHIFT];
00016 static int Rotate_buff[1 << SIZE_SHIFT];
00017 
00018 
00019 void initVelocityInfo(velocityInfo_t *vel) {
00020   vel->straight_mm_sec_vel = 0;
00021   vel->rotate_div16_sec_vel = 0;
00022   initMovingAverage(&Straight, Straight_buff, SIZE_SHIFT);
00023   initMovingAverage(&Rotate, Rotate_buff, SIZE_SHIFT);
00024 }
00025 
00026 
00027 static int change_bodyCnt2vel(int straight_cnt_vel, bodyPosition_t *bodyPos) {
00028 
00029   int straight_mm_sec_vel = (bodyPos->cnt2mm_const * straight_cnt_vel) >> 16;
00030   return straight_mm_sec_vel;
00031 }
00032 
00033 
00034 static int change_bodyCnt2div16(int rotate_cnt_vel,
00035                                 bodyPosition_t *bodyPos) {
00036 
00037   int rotate_div16_sec_vel =
00038     (bodyPos->div16_cnt_mul * rotate_cnt_vel) >> (DIV16_MUL_SHIFT - 16);
00039   return rotate_div16_sec_vel;
00040 }
00041 
00042 
00043 void updateVelocityInfo(velocityInfo_t *velInfo,
00044                         bodyPosition_t *bodyPos) {
00045 
00046   setMovingAverage(&Straight,
00047                    change_bodyCnt2vel(1000 * bodyPos->straight_cnt_vel,
00048                                       bodyPos));
00049   setMovingAverage(&Rotate,
00050                    change_bodyCnt2div16(1000 * bodyPos->rotate_cnt_vel,
00051                                         bodyPos));
00052 
00053   velInfo->straight_mm_sec_vel = getAverageValue(&Straight) >> 1;
00054   velInfo->rotate_div16_sec_vel = getAverageValue(&Rotate);
00055 }
00056 

Generated on Mon Apr 13 22:52:04 2009 by  doxygen 1.5.7.1