modeCtrl.c
Go to the documentation of this file.00001
00010 #include "modeCtrl.h"
00011
00012
00013 void initModeInfo(modeInfo_t *mode) {
00014 mode->ctrl = MODE_SERVO_FREE;
00015 mode->straight_ctrl = MODE_HOLD_POSITION_FIRST;
00016 mode->rotate_ctrl = MODE_HOLD_ANGLE_FIRST;
00017 mode->pre_straight_ctrl = mode->straight_ctrl;
00018 mode->pre_rotate_ctrl = mode->rotate_ctrl;
00019 }
00020
00021
00022
00023 int calcStraightRefVel(velocityCtrlInfo_t *velCtrl, modeInfo_t *mode,
00024 bodyPosition_t *bodyPos, velocityInfo_t *velInfo,
00025 coordinateInfo_t *run_crd) {
00026 int straight_mm_vel = 0;
00027 velCtrl->stable = CONTROL_UNSTABLE;
00028
00029 switch (mode->straight_ctrl) {
00030
00031 case MODE_HOLD_VELOCITY_FIRST:
00032 if (mode->pre_straight_ctrl == MODE_NO_CTRL) {
00033 getFirstHoldVelocity(velCtrl, velInfo->straight_mm_sec_vel);
00034 }
00035 mode->straight_ctrl = MODE_HOLD_VELOCITY;
00036 case MODE_HOLD_VELOCITY:
00037 straight_mm_vel = holdVelocityCtrl(velCtrl);
00038 break;
00039
00040 case MODE_HOLD_POSITION_FIRST:
00041 if (mode->pre_straight_ctrl == MODE_NO_CTRL) {
00042 getFirstHoldVelocity(velCtrl, velInfo->straight_mm_sec_vel);
00043 }
00044 mode->straight_ctrl = MODE_HOLD_POSITION;
00045 case MODE_HOLD_POSITION:
00046 get_mmCoordinate(run_crd, &velCtrl->current_pos, NULL);
00047 straight_mm_vel = holdPositionCtrl(velCtrl, MM_STABLE_SHIFT);
00048 break;
00049
00050 case MODE_STOP_FIRST:
00051 if (mode->pre_straight_ctrl == MODE_NO_CTRL) {
00052 getFirstHoldVelocity(velCtrl, velInfo->straight_mm_sec_vel);
00053 }
00054 mode->straight_ctrl = MODE_STOP;
00055 case MODE_STOP:
00056 velCtrl->ref_vel = 0;
00057 straight_mm_vel = holdVelocityCtrl(velCtrl);
00058 break;
00059
00060 case MODE_NO_CTRL:
00061 default:
00062 straight_mm_vel = 0;
00063 velCtrl->stable = CONTROL_STABLE;
00064 break;
00065 }
00066
00067 mode->pre_straight_ctrl = mode->straight_ctrl;
00068 return straight_mm_vel;
00069 }
00070
00071
00072
00073 int calcRotateRefVel(velocityCtrlInfo_t *velCtrl, modeInfo_t *mode,
00074 bodyPosition_t *bodyPos, velocityInfo_t *velInfo,
00075 coordinateInfo_t *run_crd) {
00076 int x, y;
00077 int rotate_div16_vel = 0;
00078 velCtrl->stable = CONTROL_UNSTABLE;
00079
00080 switch (mode->rotate_ctrl) {
00081
00082 case MODE_HOLD_ROTATE_VELOCITY_FIRST:
00083 if (mode->pre_rotate_ctrl == MODE_NO_CTRL) {
00084 getFirstHoldVelocity(velCtrl, velInfo->rotate_div16_sec_vel);
00085 }
00086 mode->rotate_ctrl = MODE_HOLD_ROTATE_VELOCITY;
00087 case MODE_HOLD_ROTATE_VELOCITY:
00088 rotate_div16_vel = holdVelocityCtrl(velCtrl);
00089 break;
00090
00091 case MODE_HOLD_ANGLE_FIRST:
00092 if (mode->pre_rotate_ctrl == MODE_NO_CTRL) {
00093 getFirstHoldVelocity(velCtrl, velInfo->rotate_div16_sec_vel);
00094 }
00095 mode->rotate_ctrl = MODE_HOLD_ANGLE;
00096 case MODE_HOLD_ANGLE:
00097 velCtrl->current_pos = getSignedDiv16(run_crd->div16);
00098 rotate_div16_vel = holdPositionCtrl(velCtrl, DIV16_STABLE_SHIFT);
00099 break;
00100
00101 case MODE_ROTATE_ANGLE_FIRST:
00102 if (mode->pre_rotate_ctrl == MODE_NO_CTRL) {
00103 getFirstHoldVelocity(velCtrl, velInfo->rotate_div16_sec_vel);
00104 }
00105 velCtrl->circle_r += (bodyPos->rotate_num << 16) + bodyPos->body_crd.div16;
00106 mode->rotate_ctrl = MODE_ROTATE_ANGLE;
00107 case MODE_ROTATE_ANGLE:
00108 velCtrl->current_pos =
00109 ((bodyPos->rotate_num << 16) + bodyPos->body_crd.div16)
00110 - velCtrl->circle_r;
00111 rotate_div16_vel = holdPositionCtrl(velCtrl, DIV16_STABLE_SHIFT);
00112 break;
00113
00114 case MODE_FOLLOW_LINE_FIRST:
00115 if (mode->pre_rotate_ctrl == MODE_NO_CTRL) {
00116 getFirstHoldVelocity(velCtrl, velInfo->rotate_div16_sec_vel);
00117 }
00118 velCtrl->circle_r = mode->follow_r;
00119 mode->rotate_ctrl = MODE_FOLLOW_LINE;
00120 case MODE_FOLLOW_LINE:
00121 get_mmCoordinate(run_crd, NULL, &velCtrl->current_pos);
00122 rotate_div16_vel = followLineCtrl(velCtrl, mode->follow_r,
00123 velInfo, run_crd->div16);
00124 break;
00125
00126 case MODE_FOLLOW_CIRCLE_FIRST:
00127 if (mode->pre_rotate_ctrl == MODE_NO_CTRL) {
00128 getFirstHoldVelocity(velCtrl, velInfo->rotate_div16_sec_vel);
00129 }
00130 mode->rotate_ctrl = MODE_FOLLOW_CIRCLE;
00131 case MODE_FOLLOW_CIRCLE:
00132 get_mmCoordinate(run_crd, &x, &y);
00133 rotate_div16_vel =
00134 followCircleCtrl(velCtrl, mode->follow_r, x, y, velInfo, run_crd->div16);
00135 break;
00136
00137 case MODE_ROTATE_STOP_FIRST:
00138 if (mode->pre_rotate_ctrl == MODE_NO_CTRL) {
00139 getFirstHoldVelocity(velCtrl, velInfo->rotate_div16_sec_vel);
00140 }
00141 mode->straight_ctrl = MODE_ROTATE_STOP;
00142 case MODE_ROTATE_STOP:
00143 velCtrl->ref_vel = 0;
00144 rotate_div16_vel = holdVelocityCtrl(velCtrl);
00145 break;
00146
00147 case MODE_NO_CTRL:
00148 default:
00149 rotate_div16_vel = 0;
00150 velCtrl->stable = CONTROL_STABLE;
00151 break;
00152 }
00153
00154 mode->pre_rotate_ctrl = mode->rotate_ctrl;
00155 return rotate_div16_vel;
00156 }
00157