涼太郎 中村
/
f3rc2
めいん
main.cpp@2:b204cf2f9b60, 2016-08-31 (annotated)
- Committer:
- choutin
- Date:
- Wed Aug 31 11:09:45 2016 +0000
- Revision:
- 2:b204cf2f9b60
- Parent:
- 1:a1e592eca305
- Child:
- 4:dcb03da10fa7
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
choutin | 0:df2659fd8031 | 1 | //受渡前での妨害に対応したい |
choutin | 0:df2659fd8031 | 2 | #include"header.h" |
choutin | 2:b204cf2f9b60 | 3 | Serial pc(SERIAL_TX, SERIAL_RX); |
choutin | 0:df2659fd8031 | 4 | |
choutin | 2:b204cf2f9b60 | 5 | void movelength(int length){ |
choutin | 2:b204cf2f9b60 | 6 | int px,py,pt; |
choutin | 2:b204cf2f9b60 | 7 | update(-right.getPulses(), left.getPulses()); |
choutin | 2:b204cf2f9b60 | 8 | px=coordinateX(); |
choutin | 2:b204cf2f9b60 | 9 | py=coordinateY(); |
choutin | 2:b204cf2f9b60 | 10 | pt=coordinateTheta(); |
choutin | 0:df2659fd8031 | 11 | |
choutin | 2:b204cf2f9b60 | 12 | move(30,30); |
choutin | 2:b204cf2f9b60 | 13 | while(1){ |
choutin | 2:b204cf2f9b60 | 14 | update(-right.getPulses(), left.getPulses()); |
choutin | 2:b204cf2f9b60 | 15 | if((px-coordinateX())*(px-coordinateX())+(py-coordinateY())*(py-coordinateY())>length*length){break;} |
choutin | 0:df2659fd8031 | 16 | |
choutin | 2:b204cf2f9b60 | 17 | } |
choutin | 2:b204cf2f9b60 | 18 | } |
choutin | 0:df2659fd8031 | 19 | |
choutin | 0:df2659fd8031 | 20 | |
choutin | 2:b204cf2f9b60 | 21 | void turncw(int degree) { |
choutin | 2:b204cf2f9b60 | 22 | initencorder(); |
choutin | 2:b204cf2f9b60 | 23 | initmotor(); |
choutin | 2:b204cf2f9b60 | 24 | |
choutin | 2:b204cf2f9b60 | 25 | int rad=0,np=1; |
choutin | 2:b204cf2f9b60 | 26 | if(degree<0){np=-1;} |
choutin | 2:b204cf2f9b60 | 27 | rad=degree*PI/180; |
choutin | 2:b204cf2f9b60 | 28 | move(30*np,-30*np); |
choutin | 2:b204cf2f9b60 | 29 | float t,theta; |
choutin | 2:b204cf2f9b60 | 30 | int x,y; |
choutin | 2:b204cf2f9b60 | 31 | update(-right.getPulses(), left.getPulses()); |
choutin | 2:b204cf2f9b60 | 32 | t=coordinateTheta(); |
choutin | 2:b204cf2f9b60 | 33 | while(1){ |
choutin | 2:b204cf2f9b60 | 34 | |
choutin | 2:b204cf2f9b60 | 35 | pc.printf("x:%d y:%d t:%f \n\r",x,y,theta*180/PI); |
choutin | 2:b204cf2f9b60 | 36 | x=coordinateX(); |
choutin | 2:b204cf2f9b60 | 37 | y=coordinateY(); |
choutin | 2:b204cf2f9b60 | 38 | theta=coordinateTheta(); |
choutin | 2:b204cf2f9b60 | 39 | update(-right.getPulses(), left.getPulses()); |
choutin | 2:b204cf2f9b60 | 40 | if(theta-t > np*rad){break;} |
choutin | 2:b204cf2f9b60 | 41 | if(theta-t < (-1)*np*rad){break;} |
choutin | 2:b204cf2f9b60 | 42 | // moveto (30,30); |
choutin | 2:b204cf2f9b60 | 43 | /* |
choutin | 2:b204cf2f9b60 | 44 | move(30,30); |
choutin | 2:b204cf2f9b60 | 45 | update(-right.getPulses(), left.getPulses()); |
choutin | 2:b204cf2f9b60 | 46 | pc.printf("x:%d y:%d t:%f \n\r",coordinateX(), coordinateY(), coordinateTheta()); |
choutin | 2:b204cf2f9b60 | 47 | if(coordinateX()>300){ |
choutin | 2:b204cf2f9b60 | 48 | while(1){*/ |
choutin | 2:b204cf2f9b60 | 49 | |
choutin | 2:b204cf2f9b60 | 50 | } |
choutin | 2:b204cf2f9b60 | 51 | move(0,0); |
choutin | 2:b204cf2f9b60 | 52 | } |
choutin | 2:b204cf2f9b60 | 53 | |
choutin | 2:b204cf2f9b60 | 54 | |
choutin | 2:b204cf2f9b60 | 55 | int main(){ |
choutin | 0:df2659fd8031 | 56 | |
choutin | 2:b204cf2f9b60 | 57 | movelength(600); |
choutin | 2:b204cf2f9b60 | 58 | turncw(90); |
choutin | 2:b204cf2f9b60 | 59 | movelength(1200); |
choutin | 2:b204cf2f9b60 | 60 | turncw(90); |
choutin | 0:df2659fd8031 | 61 | |
choutin | 0:df2659fd8031 | 62 | } |