Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 11:bf37710355ff, committed 2016-03-23
- Comitter:
- kanakin
- Date:
- Wed Mar 23 16:31:20 2016 +0000
- Parent:
- 10:82f5a6e95dc2
- Commit message:
- ziguzagu
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Mar 09 15:44:32 2016 +0000 +++ b/main.cpp Wed Mar 23 16:31:20 2016 +0000 @@ -9,8 +9,8 @@ //#define SLOPE //#define TURN //#define RIVER -//#define RIVER2 -#define DOWNHILL +#define RIVER2 +//#define DOWNHILL /*白との差*/ @@ -51,6 +51,79 @@ int river_fin; +int sikii=2000; //cdsの青と白の閾値 +int ko=0; + +int alpha; +int out_alpha; + + +//int max_dasi(void){ + /*cdsの値の最大*/ + /* max_dh=1; + if(max_dh<s2)max_dh=2; + if(max_dh<s3)max_dh=3; + if(max_dh<s4)max_dh=4; + if(max_dh<s5)max_dh=5; + if(max_dh<s6)max_dh=6; + if(max_dh<s7)max_dh=7; + if(max_dh<s8)max_dh=8; + if(max_dh<s9)max_dh=9; + if(max_dh<s10)max_dh=10; + if(max_dh<s11)max_dh=11; + if(max_dh<s12)max_dh=12; + return max_dh; + }*/ + +//ジャイロ使わないとき +/*int hidari_magari1(void){ + gyro_keisan(); + kosuu(); + if(ko=){ + if(s1>sikii){ + if(s2>sikii)} + } + */ +//ジャイロ使うとき +void hidari_magari(){ //最大値がある側とは逆側の端のcdsが白になったら曲がる + + if(now==-1||now==-2||now==-3||now==-4||now==-5||now==-6){ + alpha=-45-fixed_rot_data; + out_alpha=alpha*5;//出力5で1度.1度で出力5 + out=naka-out_alpha+90*5+100; + } + if(now==1||now==2||now==3||now==4||now==5||now==6){ + alpha=-45-fixed_rot_data; + out_alpha=alpha*5; + out=naka-out_alpha+90*5+100; + } +} + +void migi_magari(){ + if(now==-1||now==-2||now==-3||now==-4||now==-5||now==-6){ + alpha=-135-fixed_rot_data; + out_alpha=alpha*5; + out=naka-out_alpha-90*5-150; + } + if(now==1||now==2||now==3||now==4||now==5||now==6){ + alpha=-135-fixed_rot_data; + out_alpha=alpha*5; + out=naka-out_alpha-90*5-150; + } +} + + +int kosuu(){ + int ko; + if(s3>sikii&&s4>sikii&&s5>sikii)ko=3; + else if(s4>sikii&&s5>sikii&&s6>sikii)ko=4; + else if(s5>sikii&&s6>sikii&&s7>sikii)ko=5; + else if(s6>sikii&&s7>sikii&&s8>sikii)ko=6; + else if(s7>sikii&&s8>sikii&&s9>sikii)ko=7; + else if(s8>sikii&&s9>sikii&&s10>sikii)ko=8; + return ko; + } + /////////////////////////////////////////////////////////////////////////////////////////////// @@ -65,13 +138,13 @@ /*キャリブレーション*/ calibration(); - while(1){if(push_switch==1)break;} + //while(1){if(push_switch==1)break;} /*ファイル*/ - if(switch_1==0){ + /* if(switch_1==0){ //if ( NULL == (fp = fopen( "/local/test.csv", "w" )) )error( "" ); file=1; - } + }*/ /* if(switch_1==0&&switch_2==1&&switch_3==1){ //最初から #define SLOPE @@ -270,6 +343,117 @@ } #endif +/////////////////////////////////////////////////////////////////////////////////// +#ifdef RIVER2 + +/* blue_led=1; + yellow_pin=0; +while(1){ //ライントレース + judge_color(); + static int river_start; + river_start++; + if(river_start<10)blue=0; + LF(); + //out-=50; + servo.pulsewidth_us(out);*/ + /*if(file==1)fprintf(fp,*///pc.printf("blue=%d, river kyori_m45=%f,theta=%d linetrace\r\n",blue,kyori_m45,fixed_rot_data); + /* if(file==1&&switch_1==1)fclose( fp ); + pc.printf("out=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",out,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12); + + if(blue==1){ //青になったらリバースタート + river_flag=1; + blue_led=0; + out=naka-250; + servo.pulsewidth_us(out); + led1=1; + break; + } + } + */ +/*1*/ + //while(1){ + gyro_keisan(); + // LF(); + pc.printf("%d,||out=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",fixed_rot_data,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12); + //} + wait(10); + while(1){ + gyro_keisan(); + LF(); + pc.printf("%d,s1=%d\n\r",fixed_rot_data,s1); + //kosuu(); + //max_dasi(); + //pc.printf("out=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",out,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12); + //migi_magari(); + while(s12>sikii){ + hidari_magari(); + servo.pulsewidth_us(out); + //pc.printf("%d||%d\n\r",out,fixed_rot_data); + pc.printf("%d||out=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",fixed_rot_data,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12); + if(fixed_rot_data>-140&&fixed_rot_data<-130){break;}} + if(fixed_rot_data>-140&&fixed_rot_data<-130){led1=1;break;} + + } +/*2*/ + while(1){ + gyro_keisan(); + LF(); + pc.printf("%d,s10=%d,s11=%d,s12=%d\n\r",fixed_rot_data,s10,s11,s12); + // max_dasi(); + //hidari_magari(); + //kosuu(); + while(s1>sikii){ + migi_magari(); + servo.pulsewidth_us(out); + //pc.printf("%d||%d\n\r",out,fixed_rot_data); + pc.printf("%d||out=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",fixed_rot_data,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12); + if(fixed_rot_data>-60&&fixed_rot_data<-35){break;}} + if(fixed_rot_data>-60&&fixed_rot_data<-35){led2=1;break;} + } +/*3*/ + while(1){ + gyro_keisan(); + LF(); + pc.printf("%d,s1=%d\n\r",fixed_rot_data,s1); + //max_dasi(); + //kosuu(); + while(s12>sikii){ + hidari_magari(); + servo.pulsewidth_us(out); + //pc.printf("%d||%d\n\r",out,fixed_rot_data); + pc.printf("%d||out=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",fixed_rot_data,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12); + if(fixed_rot_data>-145&&fixed_rot_data<-125){break;}} + if(fixed_rot_data>-145&&fixed_rot_data<-125){ + + led3=1;break;} + } +/*4*/ + while(1){ + gyro_keisan(); + LF(); + pc.printf("%d,s10=%d,s11=%d,s12=%d\n\r",fixed_rot_data,s10,s11,s12); + //max_dasi(); + while(s1>sikii){ + migi_magari(); + servo.pulsewidth_us(out); + //pc.printf("%d||%d\n\r",out,fixed_rot_data); + pc.printf("%d||out=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",fixed_rot_data,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12); + if(fixed_rot_data>-55&&fixed_rot_data<-35){break;}} + if(fixed_rot_data>-55&&fixed_rot_data<-35){led4=1;break;} + } +/*5*/ + while(1){ + gyro_keisan(); + LF(); + judge_color(); + + if(red==1){kyori_reset(); led1=0; + led2=0; + led3=0; + led4=0; + break;} + } +#endif ////////////////////////////////////////////////////////////////////////////