bodyCtrl.c
Go to the documentation of this file.00001
00011 #include "bodyCtrl.h"
00012 #include <math.h>
00013
00014
00015
00016
00017 void initBodyInfo(bodyInfo_t *body, wheelInfo_t *right, wheelInfo_t *left) {
00018 body->whl[BODY_WHL_RIGHT] = right;
00019 body->whl[BODY_WHL_LEFT] = left;
00020 body->tread_mm = (int)(BODY_TREAD_MM);
00021 body->div2vel_const =
00022 (int)((1 << DIV2VEL_CONST_SHIFT) * BODY_TREAD_MM * M_PI);
00023
00024
00025 body->mtr_direction[BODY_WHL_RIGHT] = DEFAULT_WHL_RIGHT;
00026 body->mtr_direction[BODY_WHL_LEFT] = DEFAULT_WHL_LEFT;
00027 }
00028
00029
00030 int change_bodyDiv2Whl(int div16_vel, bodyInfo_t *body) {
00031
00032 int whl_mm_vel =
00033 (div16_vel * body->div2vel_const) >> (16 + DIV2VEL_CONST_SHIFT);
00034
00035 return whl_mm_vel;
00036 }
00037
00038
00039 void setBodyMove(bodyInfo_t *body, int straight_mm_vel, int rotate_div16_vel) {
00040 int i;
00041
00042 int rotate_mm_vel = change_bodyDiv2Whl(rotate_div16_vel, body);
00043 int whl_mm_vel[2];
00044 whl_mm_vel[WHL_RIGHT] = straight_mm_vel + rotate_mm_vel;
00045 whl_mm_vel[WHL_LEFT] = straight_mm_vel - rotate_mm_vel;
00046
00047
00048
00049
00050 for (i = 0; i < 2; ++i) {
00051 setWheelMoveVelocity(body->mtr_direction[i] * whl_mm_vel[i], body->whl[i]);
00052 }
00053 }
00054