judgement_ctrl.c
00001
00002
00003
00004
00005
00006
00007 #include "judgement_ctrl.h"
00008 #include "coordinate_ctrl.h"
00009 #include "coordinateCtrl_target.h"
00010 #define C_RUNCTRL_SOURCE
00011 #include "commandCtrl.h"
00012 #include <math.h>
00013
00014
00024 int run_getDiffPos(int crd_id, int x, int y) {
00025
00026 int pos_x, pos_y, pos_div16;
00027 int x_diff, y_diff;
00028 run_getBodyPos(crd_id, &pos_x, &pos_y, &pos_div16);
00029 x_diff = pos_x - x;
00030 y_diff = pos_y - y;
00031
00032 return (int)sqrt((x_diff * x_diff) + (y_diff * y_diff));
00033 }
00034
00035
00044 int run_getDiffAng(int crd_id, int div16) {
00045 int pos_x, pos_y, pos_div16;
00046 run_getBodyPos(crd_id, &pos_x, &pos_y, &pos_div16);
00047
00048 return getSignedDiv16((pos_div16 - div16) & 0xffff);
00049 }
00050
00051
00059 int run_getDiffStraightVel(int mm_vel) {
00060 int straight_vel;
00061 int ret_value = recvStraightVel(&straight_vel);
00062 if (ret_value < 0) {
00063 return ret_value;
00064 }
00065 return (straight_vel - mm_vel);
00066 }
00067
00068
00076 int run_getDiffRotateVel(int div16_vel) {
00077 int rotate_vel;
00078 int ret_value = recvRotateVel(&rotate_vel);
00079 if (ret_value < 0) {
00080 return ret_value;
00081 }
00082 return rotate_vel - div16_vel;
00083 }
00084
00085
00096 int run_getDiffLine(int crd_id, int x, int y, int div16) {
00097 int diff_x, diff_y;
00098 double radian;
00099 int gl_x, gl_y, gl_div16;
00100 int ret_value = run_getBodyPos(crd_id, &gl_x, &gl_y, &gl_div16);
00101 if (ret_value < 0) {
00102 return ret_value;
00103 }
00104 diff_x = gl_x - x;
00105 diff_y = gl_y - y;
00106 radian = 2.0 * M_PI * div16 / 65536.0;
00107
00108 return (int)rint(diff_x * cos(radian) + diff_y * sin(radian));
00109 }
00110