wheelCtrl.c
Go to the documentation of this file.00001
00010 #include "wheelCtrl.h"
00011
00012
00013
00014
00015 int change_wheelVel2Cnt(wheelInfo_t *whl, int mm_sec_vel) {
00016
00017 int cnt_msec_vel = (whl->cnt2vel_const * mm_sec_vel) >> 16;
00018 return cnt_msec_vel;
00019 }
00020
00021
00022 int change_wheelCnt2Vel(wheelInfo_t *whl, int cnt_msec_vel) {
00023
00024 int mm_sec_vel = (whl->vel2cnt_const * cnt_msec_vel) >> 16;
00025 return mm_sec_vel;
00026 }
00027
00028
00029 void initWheelInfo(wheelInfo_t *whl,
00030 motorInfo_t *mtr, encInfo_t *enc, const unsigned char id) {
00031 whl->mtr = mtr;
00032 whl->enc = enc;
00033 whl->next_add = 0;
00034 if (id == WHL_RIGHT) {
00035 whl->cnt2vel_const = WHL_VEL2CNT_16SHIFT_RIGHT;
00036 whl->vel2cnt_const = WHL_CNT2VEL_16SHIFT_RIGHT;
00037 whl->cnt_per_m = WHL_CNT_PER_M_RIGHT;
00038 } else {
00039 whl->cnt2vel_const = WHL_VEL2CNT_16SHIFT_LEFT;
00040 whl->vel2cnt_const = WHL_CNT2VEL_16SHIFT_LEFT;
00041 whl->cnt_per_m = WHL_CNT_PER_M_LEFT;
00042 }
00043 }
00044
00045
00046 void setWheelFree(wheelInfo_t *whl) {
00047 setMotorFree(whl->mtr);
00048 }
00049
00050
00051 void setWheelMoveVelocity(int mm_sec_vel, wheelInfo_t *whl) {
00052
00053
00054 int ref_mm_sec_vel = mm_sec_vel + whl->next_add;
00055 int cnt_msec_vel = change_wheelVel2Cnt(whl, ref_mm_sec_vel);
00056 whl->next_add = ref_mm_sec_vel - change_wheelCnt2Vel(whl, cnt_msec_vel);
00057
00058
00059
00060 setMotorRevolution(cnt_msec_vel, whl->enc->diff, whl->mtr);
00061 }
00062