ももいくん
Dependencies: mbed
Fork of 2016_Sp_momoi_0611 by
momoi_taka.cpp@12:d811e29e469a, 2016-06-09 (annotated)
- Committer:
- atsushika
- Date:
- Thu Jun 09 11:58:32 2016 +0000
- Revision:
- 12:d811e29e469a
- Child:
- 13:9e04b53e875a
????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
atsushika | 12:d811e29e469a | 1 | #include "Utils.h" |
atsushika | 12:d811e29e469a | 2 | #include "USBHost.h" |
atsushika | 12:d811e29e469a | 3 | #include "hci.h" |
atsushika | 12:d811e29e469a | 4 | #include "ps3.h" |
atsushika | 12:d811e29e469a | 5 | #include "User.h" |
atsushika | 12:d811e29e469a | 6 | |
atsushika | 12:d811e29e469a | 7 | #include "mbed.h" |
atsushika | 12:d811e29e469a | 8 | |
atsushika | 12:d811e29e469a | 9 | int RSX,RSY,LSX,LSY,BSU,BSL; |
atsushika | 12:d811e29e469a | 10 | //これより下に関数外に書く要素を記入する |
atsushika | 12:d811e29e469a | 11 | /* |
atsushika | 12:d811e29e469a | 12 | PwmOut led1(LED1); |
atsushika | 12:d811e29e469a | 13 | PwmOut led2(LED2); |
atsushika | 12:d811e29e469a | 14 | DigitalOut led3(LED3); |
atsushika | 12:d811e29e469a | 15 | DigitalOut led4(LED4); |
atsushika | 12:d811e29e469a | 16 | */ |
atsushika | 12:d811e29e469a | 17 | |
atsushika | 12:d811e29e469a | 18 | |
atsushika | 12:d811e29e469a | 19 | |
atsushika | 12:d811e29e469a | 20 | |
atsushika | 12:d811e29e469a | 21 | |
atsushika | 12:d811e29e469a | 22 | |
atsushika | 12:d811e29e469a | 23 | |
atsushika | 12:d811e29e469a | 24 | |
atsushika | 12:d811e29e469a | 25 | //momoi |
atsushika | 12:d811e29e469a | 26 | |
atsushika | 12:d811e29e469a | 27 | //MD1 right |
atsushika | 12:d811e29e469a | 28 | |
atsushika | 12:d811e29e469a | 29 | PwmOut motorRightOne (p23); |
atsushika | 12:d811e29e469a | 30 | PwmOut motorRightTwo (p24); |
atsushika | 12:d811e29e469a | 31 | |
atsushika | 12:d811e29e469a | 32 | //MD2 left |
atsushika | 12:d811e29e469a | 33 | PwmOut motorLeftOne (p21); |
atsushika | 12:d811e29e469a | 34 | PwmOut motorLeftTwo (p22); |
atsushika | 12:d811e29e469a | 35 | |
atsushika | 12:d811e29e469a | 36 | //MD3 Arm1 |
atsushika | 12:d811e29e469a | 37 | PwmOut armOneJun(p26); |
atsushika | 12:d811e29e469a | 38 | DigitalOut chocolateOne (p30); |
atsushika | 12:d811e29e469a | 39 | DigitalOut chocolateTwo (p29); |
atsushika | 12:d811e29e469a | 40 | |
atsushika | 12:d811e29e469a | 41 | //MD4 Arm2 |
atsushika | 12:d811e29e469a | 42 | PwmOut armTwoTaka(p25); |
atsushika | 12:d811e29e469a | 43 | DigitalOut brownieOne (p6); |
atsushika | 12:d811e29e469a | 44 | DigitalOut brownieTwo (p5); |
atsushika | 12:d811e29e469a | 45 | |
atsushika | 12:d811e29e469a | 46 | void UserLoopSetting(){ |
atsushika | 12:d811e29e469a | 47 | //一度だけ行いたい初期設定をここに書く |
atsushika | 12:d811e29e469a | 48 | /* led1.period_ms(20);*/ |
atsushika | 12:d811e29e469a | 49 | } |
atsushika | 12:d811e29e469a | 50 | |
atsushika | 12:d811e29e469a | 51 | void UserLoop(char n,const u8* data){ |
atsushika | 12:d811e29e469a | 52 | u16 ButtonState; |
atsushika | 12:d811e29e469a | 53 | if(n==0){//有線Ps3USB.cpp |
atsushika | 12:d811e29e469a | 54 | RSX = ((ps3report*)data)->RightStickX; |
atsushika | 12:d811e29e469a | 55 | RSY = ((ps3report*)data)->RightStickY; |
atsushika | 12:d811e29e469a | 56 | LSX = ((ps3report*)data)->LeftStickX; |
atsushika | 12:d811e29e469a | 57 | LSY = ((ps3report*)data)->LeftStickY; |
atsushika | 12:d811e29e469a | 58 | BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); |
atsushika | 12:d811e29e469a | 59 | BSL = (u8)(((ps3report*)data)->ButtonState >> 8); |
atsushika | 12:d811e29e469a | 60 | //ボタンの処理 |
atsushika | 12:d811e29e469a | 61 | ButtonState = ((ps3report*)data)->ButtonState; |
atsushika | 12:d811e29e469a | 62 | }else {//無線TestShell.cpp |
atsushika | 12:d811e29e469a | 63 | RSX = ((ps3report*)(data + 1))->RightStickX; |
atsushika | 12:d811e29e469a | 64 | RSY = ((ps3report*)(data + 1))->RightStickY; |
atsushika | 12:d811e29e469a | 65 | LSX = ((ps3report*)(data + 1))->LeftStickX; |
atsushika | 12:d811e29e469a | 66 | LSY = ((ps3report*)(data + 1))->LeftStickY; |
atsushika | 12:d811e29e469a | 67 | BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); |
atsushika | 12:d811e29e469a | 68 | BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); |
atsushika | 12:d811e29e469a | 69 | //ボタンの処理 |
atsushika | 12:d811e29e469a | 70 | ButtonState = ((ps3report*)(data + 1))->ButtonState; |
atsushika | 12:d811e29e469a | 71 | } |
atsushika | 12:d811e29e469a | 72 | //ここより下にプログラムを書く |
atsushika | 12:d811e29e469a | 73 | |
atsushika | 12:d811e29e469a | 74 | if(LSY>140 && ((ButtonState >> BUTTONLANALOG)&1) == 1) { |
atsushika | 12:d811e29e469a | 75 | motorRightOne = 0.8; |
atsushika | 12:d811e29e469a | 76 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 77 | motorLeftOne = 0.9; |
atsushika | 12:d811e29e469a | 78 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 79 | } else if(LSY<110 && ((ButtonState >> BUTTONLANALOG)&1) == 1) { |
atsushika | 12:d811e29e469a | 80 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 81 | motorRightTwo = 0.8; |
atsushika | 12:d811e29e469a | 82 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 83 | motorLeftTwo = 0.9; |
atsushika | 12:d811e29e469a | 84 | |
atsushika | 12:d811e29e469a | 85 | |
atsushika | 12:d811e29e469a | 86 | } else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 0) {//forward |
atsushika | 12:d811e29e469a | 87 | motorRightOne = 0.4; |
atsushika | 12:d811e29e469a | 88 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 89 | motorLeftOne = 0.5; |
atsushika | 12:d811e29e469a | 90 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 91 | } else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 0) {//turn right |
atsushika | 12:d811e29e469a | 92 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 93 | motorRightTwo = 0.4; |
atsushika | 12:d811e29e469a | 94 | motorLeftOne = 0.5; |
atsushika | 12:d811e29e469a | 95 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 96 | } else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 1) {//turn left |
atsushika | 12:d811e29e469a | 97 | motorRightOne = 0.4; |
atsushika | 12:d811e29e469a | 98 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 99 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 100 | motorLeftTwo = 0.5; |
atsushika | 12:d811e29e469a | 101 | }else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 1) {//forward |
atsushika | 12:d811e29e469a | 102 | motorRightOne = 0.4; |
atsushika | 12:d811e29e469a | 103 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 104 | motorLeftOne = 0.5; |
atsushika | 12:d811e29e469a | 105 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 106 | } else if(LSY<110 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 0) { //back |
atsushika | 12:d811e29e469a | 107 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 108 | motorRightTwo = 0.4; |
atsushika | 12:d811e29e469a | 109 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 110 | motorLeftTwo = 0.5; |
atsushika | 12:d811e29e469a | 111 | } else if (LSY<110 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 0) { //turn right |
atsushika | 12:d811e29e469a | 112 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 113 | motorRightTwo = 0.4; |
atsushika | 12:d811e29e469a | 114 | motorLeftOne = 0.5; |
atsushika | 12:d811e29e469a | 115 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 116 | } else if(LSY<110 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 1) {//turn left |
atsushika | 12:d811e29e469a | 117 | motorRightOne = 0.4; |
atsushika | 12:d811e29e469a | 118 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 119 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 120 | motorLeftTwo = 0.5; |
atsushika | 12:d811e29e469a | 121 | }else if (LSY<110 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 1) {//back |
atsushika | 12:d811e29e469a | 122 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 123 | motorRightTwo = 0.4; |
atsushika | 12:d811e29e469a | 124 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 125 | motorLeftTwo = 0.5; |
atsushika | 12:d811e29e469a | 126 | } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 0) {//stop |
atsushika | 12:d811e29e469a | 127 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 128 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 129 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 130 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 131 | } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) ==1 && ((ButtonState >> BUTTONR1)&1) == 0) { //turn right |
atsushika | 12:d811e29e469a | 132 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 133 | motorRightTwo = 0.4; |
atsushika | 12:d811e29e469a | 134 | motorLeftOne = 0.5; |
atsushika | 12:d811e29e469a | 135 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 136 | } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) ==0 && ((ButtonState >> BUTTONR1)&1) == 1) { //turn left |
atsushika | 12:d811e29e469a | 137 | motorRightOne = 0.4; |
atsushika | 12:d811e29e469a | 138 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 139 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 140 | motorLeftTwo = 0.5; |
atsushika | 12:d811e29e469a | 141 | } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 1) { //stop |
atsushika | 12:d811e29e469a | 142 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 143 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 144 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 145 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 146 | }else{ |
atsushika | 12:d811e29e469a | 147 | motorRightOne = 0; |
atsushika | 12:d811e29e469a | 148 | motorRightTwo = 0; |
atsushika | 12:d811e29e469a | 149 | motorLeftOne = 0; |
atsushika | 12:d811e29e469a | 150 | motorLeftTwo = 0; |
atsushika | 12:d811e29e469a | 151 | } |
atsushika | 12:d811e29e469a | 152 | |
atsushika | 12:d811e29e469a | 153 | if(((ButtonState >> BUTTONDOWN)&1) == 1 && ((ButtonState >> BUTTONUP)&1) == 0) { |
atsushika | 12:d811e29e469a | 154 | armOneJun = 0.8; |
atsushika | 12:d811e29e469a | 155 | chocolateOne = 1; |
atsushika | 12:d811e29e469a | 156 | chocolateTwo = 0; |
atsushika | 12:d811e29e469a | 157 | } else if (((ButtonState >> BUTTONDOWN)&1) == 0 && ((ButtonState >> BUTTONUP)&1) == 1) { |
atsushika | 12:d811e29e469a | 158 | armOneJun = 0.8; |
atsushika | 12:d811e29e469a | 159 | chocolateOne = 0; |
atsushika | 12:d811e29e469a | 160 | chocolateTwo = 1; |
atsushika | 12:d811e29e469a | 161 | } else { |
atsushika | 12:d811e29e469a | 162 | armOneJun = 0; |
atsushika | 12:d811e29e469a | 163 | chocolateOne = 0; |
atsushika | 12:d811e29e469a | 164 | chocolateTwo = 0; |
atsushika | 12:d811e29e469a | 165 | } |
atsushika | 12:d811e29e469a | 166 | |
atsushika | 12:d811e29e469a | 167 | |
atsushika | 12:d811e29e469a | 168 | if( ((ButtonState >> BUTTONSQUARE)&1) == 1 && ((ButtonState >> BUTTONCIRCLE)&1) == 0 ) { //つかむか放す |
atsushika | 12:d811e29e469a | 169 | armTwoTaka = 0.4; |
atsushika | 12:d811e29e469a | 170 | brownieOne = 1; |
atsushika | 12:d811e29e469a | 171 | brownieTwo = 0; |
atsushika | 12:d811e29e469a | 172 | } else if ( ((ButtonState >> BUTTONSQUARE)&1) == 0 && ((ButtonState >> BUTTONCIRCLE)&1) == 1 ) { |
atsushika | 12:d811e29e469a | 173 | armTwoTaka = 0.4; |
atsushika | 12:d811e29e469a | 174 | brownieOne = 0; |
atsushika | 12:d811e29e469a | 175 | brownieTwo = 1; |
atsushika | 12:d811e29e469a | 176 | } else { |
atsushika | 12:d811e29e469a | 177 | armTwoTaka = 0; |
atsushika | 12:d811e29e469a | 178 | brownieOne = 0; |
atsushika | 12:d811e29e469a | 179 | brownieTwo = 0; |
atsushika | 12:d811e29e469a | 180 | } |
atsushika | 12:d811e29e469a | 181 | |
atsushika | 12:d811e29e469a | 182 | |
atsushika | 12:d811e29e469a | 183 | |
atsushika | 12:d811e29e469a | 184 | |
atsushika | 12:d811e29e469a | 185 | |
atsushika | 12:d811e29e469a | 186 | |
atsushika | 12:d811e29e469a | 187 | |
atsushika | 12:d811e29e469a | 188 | |
atsushika | 12:d811e29e469a | 189 | |
atsushika | 12:d811e29e469a | 190 | |
atsushika | 12:d811e29e469a | 191 | |
atsushika | 12:d811e29e469a | 192 | |
atsushika | 12:d811e29e469a | 193 | |
atsushika | 12:d811e29e469a | 194 | //データ取得例 |
atsushika | 12:d811e29e469a | 195 | |
atsushika | 12:d811e29e469a | 196 | if((ButtonState >> BUTTONCIRCLE)&1) { |
atsushika | 12:d811e29e469a | 197 | //○が押されたとき |
atsushika | 12:d811e29e469a | 198 | } |
atsushika | 12:d811e29e469a | 199 | |
atsushika | 12:d811e29e469a | 200 | |
atsushika | 12:d811e29e469a | 201 | |
atsushika | 12:d811e29e469a | 202 | //値の取得はps3.hを参照 |
atsushika | 12:d811e29e469a | 203 | |
atsushika | 12:d811e29e469a | 204 | } |