float sin_r(float in_val); float cos_r(float in_val); float tan_r(float in_val); float cos_r(float in_val) { return(sin_r(90.0 - in_val)); } float tan_r(float in_val) { return(sin_r(in_val) / cos_r(in_val)); } /***************************************************************************************/ /*float in_val: 角度の入力*/ /***************************************************************************************/ float sin_r(float in_val) { float sin_table[] = { 0.00000 , 0.01745 ,0.03490 ,0.05234 ,0.06976 ,0.08716 ,0.10453 ,0.12187 ,0.13917 ,0.15643 ,0.17365 , 0.19081 ,0.20791 ,0.22495 ,0.24192 ,0.25882 ,0.27564 ,0.29237 ,0.30902 ,0.32557 ,0.34202 , 0.35837 ,0.37461 ,0.39073 ,0.40674 ,0.42262 ,0.43837 ,0.45399 ,0.46947 ,0.48481 ,0.50000 , 0.51504 ,0.52992 ,0.54464 ,0.55919 ,0.57358 ,0.58779 ,0.60182 ,0.61566 ,0.62932 ,0.64279 , 0.65606 ,0.66913 ,0.68200 ,0.69466 ,0.70711 ,0.71934 ,0.73135 ,0.74314 ,0.75471 ,0.76604 , 0.77715 ,0.78801 ,0.79864 ,0.80902 ,0.81915 ,0.82904 ,0.83867 ,0.84805 ,0.85717 ,0.86603 , 0.87462 ,0.88295 ,0.89101 ,0.89879 ,0.90631 ,0.91355 ,0.92050 ,0.92718 ,0.93358 ,0.93969 , 0.94552 ,0.95106 ,0.95630 ,0.96126 ,0.96593 ,0.97030 ,0.97437 ,0.97815 ,0.98163 ,0.98481 , 0.98769 ,0.99027 ,0.99255 ,0.99452 ,0.99619 ,0.99756 ,0.99863 ,0.99939 ,0.99985 ,1.00000 }; int table_number; float workf, out_val1, out_val2, out_val, sign, sign2; if(in_val >= 360 || in_val <= -360.0) { workf = (int)(in_val / 360.0); in_val = in_val - workf * 360.0; } sign = 1.0; sign2 = 1.0; if(in_val < 0.0) { sign2 = -1.0; in_val = in_val * -1.0; } if(in_val >= 90 && in_val < 180) { sign = 1.0; in_val = 180.0 - in_val; } if(in_val >= 180 && in_val < 270) { sign = -1.0; in_val = in_val - 180; } if(in_val >= 270 && in_val < 360) { sign = -1.0; in_val = 360.0 - in_val; } table_number = (int)in_val; if(table_number < 90) { out_val1 = sin_table[table_number]; out_val2 = sin_table[table_number + 1]; workf = (int)in_val; workf = in_val - workf; out_val = out_val1 + (out_val2 - out_val1) * workf; out_val = out_val * sign * sign2; } else { out_val = sin_table[table_number] * sign * sign2; } return(out_val); } /*****************************************************************/ /*数直線作成サブルーチン */ /*区間の速度はcos関数で変化・・・引数の主は時間 */ /* coo :数直線 */ /* time :トータル時間(制御波形の再生時間) */ /* length :数直線の長さ */ /* 返り値 :数直線の構成要素数 */ /*****************************************************************/ int num_line_w60(float coo[64], int data_num, float length) { int i; float PI = 180.0; /*RCサーボのPWM周期(秒)*/ float a, t, dt_rad; float v; /*エラーの処理・・・あとで書く2003/6/14 */ if(data_num > 64) { return(-1); } dt_rad = 2.0 * PI / (float) data_num; t = dt_rad; a = length / (float) data_num; coo[0] = 0.0; /*デルタを計算*/ for(i = 1; i < data_num; i++) { v = - (a * cos_r(t)) + a; coo[i] = v; t = t + dt_rad; } return(data_num); }