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.
global.cpp@0:ae5d19a716e1, 2014-03-05 (annotated)
- Committer:
- Nishii
- Date:
- Wed Mar 05 05:17:45 2014 +0000
- Revision:
- 0:ae5d19a716e1
for Robot Grand Prix
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Nishii | 0:ae5d19a716e1 | 1 | /* global.cpp */ |
| Nishii | 0:ae5d19a716e1 | 2 | |
| Nishii | 0:ae5d19a716e1 | 3 | #include "global.h" |
| Nishii | 0:ae5d19a716e1 | 4 | |
| Nishii | 0:ae5d19a716e1 | 5 | /** |
| Nishii | 0:ae5d19a716e1 | 6 | * Classes |
| Nishii | 0:ae5d19a716e1 | 7 | */ |
| Nishii | 0:ae5d19a716e1 | 8 | PwmOut mortar_A(p21); //aori |
| Nishii | 0:ae5d19a716e1 | 9 | PwmOut mortar_U(p22); //UFO up down |
| Nishii | 0:ae5d19a716e1 | 10 | PwmOut mortar_M(p23); //merry-go-round |
| Nishii | 0:ae5d19a716e1 | 11 | PwmOut mortar_S(p24); //yosou |
| Nishii | 0:ae5d19a716e1 | 12 | |
| Nishii | 0:ae5d19a716e1 | 13 | DigitalOut UFO(p6); //UFO ON:close, OFF:open |
| Nishii | 0:ae5d19a716e1 | 14 | DigitalOut RISE1(p5); //rise |
| Nishii | 0:ae5d19a716e1 | 15 | DigitalOut RISE2(p7); |
| Nishii | 0:ae5d19a716e1 | 16 | DigitalOut RISE3(p8); |
| Nishii | 0:ae5d19a716e1 | 17 | |
| Nishii | 0:ae5d19a716e1 | 18 | DigitalOut led1(LED1); |
| Nishii | 0:ae5d19a716e1 | 19 | DigitalOut led2(LED2); |
| Nishii | 0:ae5d19a716e1 | 20 | DigitalOut led3(LED3); |
| Nishii | 0:ae5d19a716e1 | 21 | DigitalOut led4(LED4); |
| Nishii | 0:ae5d19a716e1 | 22 | |
| Nishii | 0:ae5d19a716e1 | 23 | DigitalIn MS_A(p20); //microswitch |
| Nishii | 0:ae5d19a716e1 | 24 | DigitalIn MS_U(p19); |
| Nishii | 0:ae5d19a716e1 | 25 | DigitalIn MS_M(p18); |
| Nishii | 0:ae5d19a716e1 | 26 | DigitalIn MS_S(p17); |
| Nishii | 0:ae5d19a716e1 | 27 | |
| Nishii | 0:ae5d19a716e1 | 28 | QEI hight(p29, p30, NC, 100); |
| Nishii | 0:ae5d19a716e1 | 29 | |
| Nishii | 0:ae5d19a716e1 | 30 | Serial pc(USBTX, USBRX); //serialport |
| Nishii | 0:ae5d19a716e1 | 31 | |
| Nishii | 0:ae5d19a716e1 | 32 | /** |
| Nishii | 0:ae5d19a716e1 | 33 | * Parameters |
| Nishii | 0:ae5d19a716e1 | 34 | */ |
| Nishii | 0:ae5d19a716e1 | 35 | double duty_A=0.13, dutyr_A=0.42, dutyu_U=0.30, dutyd_U=0.65, duty_M=0.30, dutyr_M=0.70, duty_S=0.40, dutyr_S=0.60; |
| Nishii | 0:ae5d19a716e1 | 36 | double speed[4] = {STOP, STOP, STOP, STOP}; |
| Nishii | 0:ae5d19a716e1 | 37 | double wait_A=0.45, wait_U=0.2, wait_M=0.2, wait_S=0.15; |
| Nishii | 0:ae5d19a716e1 | 38 | |
| Nishii | 0:ae5d19a716e1 | 39 | bool STOP_STATUS=true; //false:stop |
| Nishii | 0:ae5d19a716e1 | 40 | |
| Nishii | 0:ae5d19a716e1 | 41 | /** |
| Nishii | 0:ae5d19a716e1 | 42 | * Functions |
| Nishii | 0:ae5d19a716e1 | 43 | */ |
| Nishii | 0:ae5d19a716e1 | 44 | void led_all(int s){ |
| Nishii | 0:ae5d19a716e1 | 45 | if ( s==ON ){ |
| Nishii | 0:ae5d19a716e1 | 46 | led1=led2=led3=led4=ON; |
| Nishii | 0:ae5d19a716e1 | 47 | } |
| Nishii | 0:ae5d19a716e1 | 48 | else if ( s==OFF ) { |
| Nishii | 0:ae5d19a716e1 | 49 | led1=led2=led3=led4=OFF; |
| Nishii | 0:ae5d19a716e1 | 50 | } |
| Nishii | 0:ae5d19a716e1 | 51 | } |
| Nishii | 0:ae5d19a716e1 | 52 | |
| Nishii | 0:ae5d19a716e1 | 53 | void setspeed( double t_speed, int x ) { |
| Nishii | 0:ae5d19a716e1 | 54 | double step, waittime; |
| Nishii | 0:ae5d19a716e1 | 55 | if(speed[x]<t_speed) { |
| Nishii | 0:ae5d19a716e1 | 56 | while (speed[x]<t_speed) { |
| Nishii | 0:ae5d19a716e1 | 57 | if(t_speed-speed[x]>0.05) step = 0.05; |
| Nishii | 0:ae5d19a716e1 | 58 | else step = 0.01; |
| Nishii | 0:ae5d19a716e1 | 59 | speed[x]+=step; |
| Nishii | 0:ae5d19a716e1 | 60 | switch(x) { |
| Nishii | 0:ae5d19a716e1 | 61 | case _A_: |
| Nishii | 0:ae5d19a716e1 | 62 | waittime = wait_A; |
| Nishii | 0:ae5d19a716e1 | 63 | mortar_A = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 64 | break; |
| Nishii | 0:ae5d19a716e1 | 65 | case _U_: |
| Nishii | 0:ae5d19a716e1 | 66 | waittime = wait_U; |
| Nishii | 0:ae5d19a716e1 | 67 | mortar_U = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 68 | break; |
| Nishii | 0:ae5d19a716e1 | 69 | case _M_: |
| Nishii | 0:ae5d19a716e1 | 70 | waittime = wait_M; |
| Nishii | 0:ae5d19a716e1 | 71 | mortar_M = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 72 | break; |
| Nishii | 0:ae5d19a716e1 | 73 | case _S_: |
| Nishii | 0:ae5d19a716e1 | 74 | waittime = wait_S; |
| Nishii | 0:ae5d19a716e1 | 75 | mortar_S = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 76 | break; |
| Nishii | 0:ae5d19a716e1 | 77 | } |
| Nishii | 0:ae5d19a716e1 | 78 | wait(waittime); |
| Nishii | 0:ae5d19a716e1 | 79 | } |
| Nishii | 0:ae5d19a716e1 | 80 | } |
| Nishii | 0:ae5d19a716e1 | 81 | else { |
| Nishii | 0:ae5d19a716e1 | 82 | while(speed[x]>t_speed) { |
| Nishii | 0:ae5d19a716e1 | 83 | if(speed[x]-t_speed>0.05) step = 0.05; |
| Nishii | 0:ae5d19a716e1 | 84 | else step = 0.01; |
| Nishii | 0:ae5d19a716e1 | 85 | speed[x]-=step; |
| Nishii | 0:ae5d19a716e1 | 86 | switch(x) { |
| Nishii | 0:ae5d19a716e1 | 87 | case _A_: |
| Nishii | 0:ae5d19a716e1 | 88 | waittime = wait_A; |
| Nishii | 0:ae5d19a716e1 | 89 | mortar_A = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 90 | break; |
| Nishii | 0:ae5d19a716e1 | 91 | case _U_: |
| Nishii | 0:ae5d19a716e1 | 92 | waittime = wait_U; |
| Nishii | 0:ae5d19a716e1 | 93 | mortar_U = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 94 | break; |
| Nishii | 0:ae5d19a716e1 | 95 | case _M_: |
| Nishii | 0:ae5d19a716e1 | 96 | waittime = wait_M; |
| Nishii | 0:ae5d19a716e1 | 97 | mortar_M = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 98 | break; |
| Nishii | 0:ae5d19a716e1 | 99 | case _S_: |
| Nishii | 0:ae5d19a716e1 | 100 | waittime = wait_S; |
| Nishii | 0:ae5d19a716e1 | 101 | mortar_S = speed[x]; |
| Nishii | 0:ae5d19a716e1 | 102 | break; |
| Nishii | 0:ae5d19a716e1 | 103 | } |
| Nishii | 0:ae5d19a716e1 | 104 | wait(waittime); |
| Nishii | 0:ae5d19a716e1 | 105 | } |
| Nishii | 0:ae5d19a716e1 | 106 | } |
| Nishii | 0:ae5d19a716e1 | 107 | } |
| Nishii | 0:ae5d19a716e1 | 108 | |
| Nishii | 0:ae5d19a716e1 | 109 | void ALLSTOP() { |
| Nishii | 0:ae5d19a716e1 | 110 | setspeed(STOP, _A_); |
| Nishii | 0:ae5d19a716e1 | 111 | setspeed(STOP, _U_); |
| Nishii | 0:ae5d19a716e1 | 112 | setspeed(STOP, _M_); |
| Nishii | 0:ae5d19a716e1 | 113 | setspeed(STOP, _S_); |
| Nishii | 0:ae5d19a716e1 | 114 | } |