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.
Dependencies: mbed
Fork of clubvs2017_momoi by
KaidaKari.cpp@19:70657aee6fa5, 2017-03-30 (annotated)
- Committer:
- abcdefgh
- Date:
- Thu Mar 30 05:39:06 2017 +0000
- Revision:
- 19:70657aee6fa5
- Parent:
- 18:cab2885dc8fe
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Junbug | 12:b2f3c85cba36 | 1 | #include "Utils.h" |
Junbug | 12:b2f3c85cba36 | 2 | #include "USBHost.h" |
Junbug | 12:b2f3c85cba36 | 3 | #include "hci.h" |
Junbug | 12:b2f3c85cba36 | 4 | #include "ps3.h" |
Junbug | 12:b2f3c85cba36 | 5 | #include "User.h" |
Junbug | 12:b2f3c85cba36 | 6 | #include "mbed.h" |
Junbug | 12:b2f3c85cba36 | 7 | |
Junbug | 12:b2f3c85cba36 | 8 | int RSX,RSY,LSX,LSY,BSU,BSL; |
Junbug | 12:b2f3c85cba36 | 9 | //これより下に関数外に書く要素を記入する |
abcdefgh | 17:efe67bbb927e | 10 | double flag; |
abcdefgh | 18:cab2885dc8fe | 11 | |
Junbug | 12:b2f3c85cba36 | 12 | //MD1 |
abcdefgh | 18:cab2885dc8fe | 13 | |
abcdefgh | 18:cab2885dc8fe | 14 | PwmOut motorRightOne (p26); |
abcdefgh | 18:cab2885dc8fe | 15 | PwmOut motorRightTwo (p25); |
Junbug | 12:b2f3c85cba36 | 16 | |
Junbug | 12:b2f3c85cba36 | 17 | //MD2 |
abcdefgh | 18:cab2885dc8fe | 18 | PwmOut motorLeftOne (p23); |
abcdefgh | 18:cab2885dc8fe | 19 | PwmOut motorLeftTwo (p24); |
Junbug | 12:b2f3c85cba36 | 20 | |
Junbug | 12:b2f3c85cba36 | 21 | //MD3 Arm1 |
abcdefgh | 18:cab2885dc8fe | 22 | PwmOut armRight(p22); |
abcdefgh | 18:cab2885dc8fe | 23 | DigitalOut armOne (p29); |
abcdefgh | 18:cab2885dc8fe | 24 | DigitalOut armTwo (p30); |
Junbug | 12:b2f3c85cba36 | 25 | |
Junbug | 12:b2f3c85cba36 | 26 | //MD4 Arm2 |
abcdefgh | 18:cab2885dc8fe | 27 | PwmOut armLeft(p21); |
abcdefgh | 18:cab2885dc8fe | 28 | DigitalOut armThree (p19); |
abcdefgh | 18:cab2885dc8fe | 29 | DigitalOut armFour (p20); |
Junbug | 12:b2f3c85cba36 | 30 | |
Junbug | 12:b2f3c85cba36 | 31 | /* |
Junbug | 12:b2f3c85cba36 | 32 | |
Junbug | 12:b2f3c85cba36 | 33 | PWM->0.xxx |
Junbug | 12:b2f3c85cba36 | 34 | Digitals->0 and 0.xxx |
Junbug | 12:b2f3c85cba36 | 35 | for arms(I guess...) |
Junbug | 12:b2f3c85cba36 | 36 | |
Junbug | 12:b2f3c85cba36 | 37 | For lergs, turn right or left, and just going go and back.->Probably using sticks. |
Junbug | 12:b2f3c85cba36 | 38 | How to cha ge speed? Two different tyes of speed. |
Junbug | 12:b2f3c85cba36 | 39 | |
Junbug | 12:b2f3c85cba36 | 40 | Wow, Taka-chan will do one of the machine. He wants to do with the angles. Plus I don't understand what they are talking about!! |
Junbug | 12:b2f3c85cba36 | 41 | Left stick, speed and right/left |
Junbug | 12:b2f3c85cba36 | 42 | Push button and max incline -> the max speed |
Junbug | 12:b2f3c85cba36 | 43 | Just max incline -> usual speed |
Junbug | 12:b2f3c85cba36 | 44 | Little incline -> slow speed |
Junbug | 12:b2f3c85cba36 | 45 | |
Junbug | 12:b2f3c85cba36 | 46 | L1/R2 -> turning? |
Junbug | 12:b2f3c85cba36 | 47 | |
Junbug | 12:b2f3c85cba36 | 48 | Lifting -> |
Junbug | 12:b2f3c85cba36 | 49 | |
Junbug | 12:b2f3c85cba36 | 50 | */ |
Junbug | 12:b2f3c85cba36 | 51 | |
Junbug | 12:b2f3c85cba36 | 52 | |
Junbug | 12:b2f3c85cba36 | 53 | |
Junbug | 12:b2f3c85cba36 | 54 | void UserLoopSetting() |
Junbug | 12:b2f3c85cba36 | 55 | { |
Junbug | 12:b2f3c85cba36 | 56 | //一度だけ行いたい初期設定をここに書く |
Junbug | 12:b2f3c85cba36 | 57 | /* |
Junbug | 12:b2f3c85cba36 | 58 | I need to ask what to do with this! |
Junbug | 12:b2f3c85cba36 | 59 | Actually, do we have any LEDs? |
Junbug | 12:b2f3c85cba36 | 60 | */ |
abcdefgh | 15:5e973e6c058c | 61 | |
Junbug | 12:b2f3c85cba36 | 62 | } |
Junbug | 12:b2f3c85cba36 | 63 | |
Junbug | 12:b2f3c85cba36 | 64 | void UserLoop(char n,const u8* data) |
Junbug | 12:b2f3c85cba36 | 65 | { |
Junbug | 12:b2f3c85cba36 | 66 | u16 ButtonState; |
Junbug | 12:b2f3c85cba36 | 67 | if(n==0) { //有線Ps3USB.cpp |
Junbug | 12:b2f3c85cba36 | 68 | RSX = ((ps3report*)data)->RightStickX; |
Junbug | 12:b2f3c85cba36 | 69 | RSY = ((ps3report*)data)->RightStickY; |
Junbug | 12:b2f3c85cba36 | 70 | LSX = ((ps3report*)data)->LeftStickX; |
Junbug | 12:b2f3c85cba36 | 71 | LSY = ((ps3report*)data)->LeftStickY; |
Junbug | 12:b2f3c85cba36 | 72 | BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); |
Junbug | 12:b2f3c85cba36 | 73 | BSL = (u8)(((ps3report*)data)->ButtonState >> 8); |
Junbug | 12:b2f3c85cba36 | 74 | //ボタンの処理 |
Junbug | 12:b2f3c85cba36 | 75 | ButtonState = ((ps3report*)data)->ButtonState; |
Junbug | 12:b2f3c85cba36 | 76 | } else {//無線TestShell.cpp |
Junbug | 12:b2f3c85cba36 | 77 | RSX = ((ps3report*)(data + 1))->RightStickX; |
Junbug | 12:b2f3c85cba36 | 78 | RSY = ((ps3report*)(data + 1))->RightStickY; |
Junbug | 12:b2f3c85cba36 | 79 | LSX = ((ps3report*)(data + 1))->LeftStickX; |
Junbug | 12:b2f3c85cba36 | 80 | LSY = ((ps3report*)(data + 1))->LeftStickY; |
Junbug | 12:b2f3c85cba36 | 81 | BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); |
Junbug | 12:b2f3c85cba36 | 82 | BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); |
Junbug | 12:b2f3c85cba36 | 83 | //ボタンの処理 |
Junbug | 12:b2f3c85cba36 | 84 | ButtonState = ((ps3report*)(data + 1))->ButtonState; |
Junbug | 12:b2f3c85cba36 | 85 | } |
Junbug | 12:b2f3c85cba36 | 86 | //ここより下にプログラムを書く |
Junbug | 12:b2f3c85cba36 | 87 | |
Junbug | 12:b2f3c85cba36 | 88 | /* |
Junbug | 12:b2f3c85cba36 | 89 | double thesOne = 64; |
Junbug | 12:b2f3c85cba36 | 90 | double thesTwo = 127; |
Junbug | 12:b2f3c85cba36 | 91 | double thesThree = 191; |
Junbug | 12:b2f3c85cba36 | 92 | double fastSpeed = 1; |
Junbug | 12:b2f3c85cba36 | 93 | double slowSpeed = 0.5; |
Junbug | 12:b2f3c85cba36 | 94 | */ |
abcdefgh | 15:5e973e6c058c | 95 | |
abcdefgh | 14:67ee8d8f4efe | 96 | //motor |
abcdefgh | 18:cab2885dc8fe | 97 | |
abcdefgh | 19:70657aee6fa5 | 98 | if((ButtonState >> BUTTONL2)&1 == 1) { |
abcdefgh | 19:70657aee6fa5 | 99 | flag -= 0.1; |
abcdefgh | 19:70657aee6fa5 | 100 | wait(0.1); |
abcdefgh | 18:cab2885dc8fe | 101 | } else if((ButtonState >> BUTTONR2)&1 == 1) { |
abcdefgh | 19:70657aee6fa5 | 102 | flag = 0; |
abcdefgh | 18:cab2885dc8fe | 103 | wait(0.1); |
abcdefgh | 17:efe67bbb927e | 104 | } |
abcdefgh | 19:70657aee6fa5 | 105 | if(flag <= -0.2) { |
abcdefgh | 19:70657aee6fa5 | 106 | flag = -0.2; |
abcdefgh | 18:cab2885dc8fe | 107 | } |
abcdefgh | 18:cab2885dc8fe | 108 | |
abcdefgh | 17:efe67bbb927e | 109 | if(LSY>140 && ((ButtonState >> BUTTONLANALOG)&1) == 1) { |
abcdefgh | 19:70657aee6fa5 | 110 | motorRightOne = 0.9; |
Junbug | 12:b2f3c85cba36 | 111 | motorRightTwo = 0; |
abcdefgh | 19:70657aee6fa5 | 112 | motorLeftOne = 0.9; |
abcdefgh | 17:efe67bbb927e | 113 | motorLeftTwo = 0; |
abcdefgh | 18:cab2885dc8fe | 114 | } else if(LSY<110 && ((ButtonState >> BUTTONLANALOG)&1) == 1) { |
abcdefgh | 18:cab2885dc8fe | 115 | motorRightOne = 0; |
abcdefgh | 19:70657aee6fa5 | 116 | motorRightTwo = 0.9; |
abcdefgh | 17:efe67bbb927e | 117 | motorLeftOne = 0; |
abcdefgh | 19:70657aee6fa5 | 118 | motorLeftTwo = 0.9; |
abcdefgh | 18:cab2885dc8fe | 119 | } else if( LSY > 140 ) { //forward |
abcdefgh | 18:cab2885dc8fe | 120 | motorRightOne = 0.6 + flag; |
abcdefgh | 17:efe67bbb927e | 121 | motorRightTwo = 0; |
abcdefgh | 18:cab2885dc8fe | 122 | motorLeftOne = 0.6 + flag; |
Junbug | 12:b2f3c85cba36 | 123 | motorLeftTwo = 0; |
abcdefgh | 15:5e973e6c058c | 124 | |
abcdefgh | 15:5e973e6c058c | 125 | } else if( LSY < 110 ) { //back |
Junbug | 12:b2f3c85cba36 | 126 | motorRightOne = 0; |
abcdefgh | 18:cab2885dc8fe | 127 | motorRightTwo = 0.6 + flag; |
Junbug | 12:b2f3c85cba36 | 128 | motorLeftOne = 0; |
abcdefgh | 18:cab2885dc8fe | 129 | motorLeftTwo = 0.6 + flag; |
abcdefgh | 15:5e973e6c058c | 130 | } else { //stop |
abcdefgh | 14:67ee8d8f4efe | 131 | motorRightOne = 0; |
abcdefgh | 14:67ee8d8f4efe | 132 | motorRightTwo = 0; |
abcdefgh | 14:67ee8d8f4efe | 133 | motorLeftOne = 0; |
abcdefgh | 14:67ee8d8f4efe | 134 | motorLeftTwo = 0; |
abcdefgh | 14:67ee8d8f4efe | 135 | } |
abcdefgh | 14:67ee8d8f4efe | 136 | |
abcdefgh | 14:67ee8d8f4efe | 137 | if(( ButtonState >> BUTTONR1)&1 == 1) { |
abcdefgh | 19:70657aee6fa5 | 138 | motorRightOne = 0.7 + flag; |
abcdefgh | 18:cab2885dc8fe | 139 | motorRightTwo = 0; |
abcdefgh | 18:cab2885dc8fe | 140 | motorLeftOne = 0; |
abcdefgh | 19:70657aee6fa5 | 141 | motorLeftTwo = 0.7 + flag; |
abcdefgh | 15:5e973e6c058c | 142 | } |
abcdefgh | 15:5e973e6c058c | 143 | if(( ButtonState >> BUTTONL1)&1 == 1) { |
abcdefgh | 18:cab2885dc8fe | 144 | motorRightOne = 0; |
abcdefgh | 19:70657aee6fa5 | 145 | motorRightTwo = 0.6 + flag; |
abcdefgh | 19:70657aee6fa5 | 146 | motorLeftOne = 0.6 + flag; |
abcdefgh | 18:cab2885dc8fe | 147 | motorLeftTwo = 0; |
abcdefgh | 14:67ee8d8f4efe | 148 | } |
abcdefgh | 14:67ee8d8f4efe | 149 | |
abcdefgh | 14:67ee8d8f4efe | 150 | //arm |
abcdefgh | 14:67ee8d8f4efe | 151 | |
abcdefgh | 17:efe67bbb927e | 152 | |
abcdefgh | 18:cab2885dc8fe | 153 | if((ButtonState >> BUTTONTRIANGEL)&1 == 1) { |
abcdefgh | 17:efe67bbb927e | 154 | armOne = 1; |
abcdefgh | 17:efe67bbb927e | 155 | armTwo = 0; |
abcdefgh | 17:efe67bbb927e | 156 | armRight = 0.4; |
abcdefgh | 18:cab2885dc8fe | 157 | } else if((ButtonState >> BUTTONCROSS)&1 == 1) { |
abcdefgh | 15:5e973e6c058c | 158 | armOne = 0; |
abcdefgh | 15:5e973e6c058c | 159 | armTwo = 1; |
abcdefgh | 14:67ee8d8f4efe | 160 | armRight = 0.4; |
abcdefgh | 14:67ee8d8f4efe | 161 | } else { |
abcdefgh | 14:67ee8d8f4efe | 162 | armOne = 0; |
abcdefgh | 14:67ee8d8f4efe | 163 | armTwo = 0; |
abcdefgh | 14:67ee8d8f4efe | 164 | armRight = 0; |
abcdefgh | 19:70657aee6fa5 | 165 | } |
abcdefgh | 19:70657aee6fa5 | 166 | |
abcdefgh | 19:70657aee6fa5 | 167 | if( (ButtonState >> BUTTONDOWN)&1 == 1 ) { |
abcdefgh | 19:70657aee6fa5 | 168 | armThree = 0; |
abcdefgh | 19:70657aee6fa5 | 169 | armFour = 1; |
abcdefgh | 19:70657aee6fa5 | 170 | armLeft = 0.9; |
abcdefgh | 19:70657aee6fa5 | 171 | } else if( (ButtonState >> BUTTONUP)&1 == 1 ) { |
abcdefgh | 19:70657aee6fa5 | 172 | armThree = 1; |
abcdefgh | 19:70657aee6fa5 | 173 | armFour = 0; |
abcdefgh | 19:70657aee6fa5 | 174 | armLeft = 0.8; |
abcdefgh | 19:70657aee6fa5 | 175 | } else { |
abcdefgh | 19:70657aee6fa5 | 176 | armThree = 0; |
abcdefgh | 19:70657aee6fa5 | 177 | armFour = 0; |
abcdefgh | 19:70657aee6fa5 | 178 | armLeft = 0; |
abcdefgh | 19:70657aee6fa5 | 179 | |
abcdefgh | 19:70657aee6fa5 | 180 | } |
abcdefgh | 15:5e973e6c058c | 181 | |
abcdefgh | 14:67ee8d8f4efe | 182 | |
abcdefgh | 19:70657aee6fa5 | 183 | /* |
abcdefgh | 19:70657aee6fa5 | 184 | With oen if, put both arms and legs. |
abcdefgh | 14:67ee8d8f4efe | 185 | |
abcdefgh | 19:70657aee6fa5 | 186 | Use start and select?? |
Junbug | 12:b2f3c85cba36 | 187 | |
Junbug | 12:b2f3c85cba36 | 188 | |
abcdefgh | 19:70657aee6fa5 | 189 | */ |
Junbug | 12:b2f3c85cba36 | 190 | |
abcdefgh | 16:ea0808fbbb40 | 191 | |
Junbug | 12:b2f3c85cba36 | 192 | |
abcdefgh | 16:ea0808fbbb40 | 193 | |
Junbug | 12:b2f3c85cba36 | 194 | |
abcdefgh | 19:70657aee6fa5 | 195 | /* |
abcdefgh | 19:70657aee6fa5 | 196 | led3=ButtonState & 0x0400; //L1の状態 |
abcdefgh | 19:70657aee6fa5 | 197 | led4=ButtonState & 0x0800; //R1の状態 |
abcdefgh | 19:70657aee6fa5 | 198 | */ //値の取得はps3.hを参照 |
Junbug | 12:b2f3c85cba36 | 199 | |
Junbug | 12:b2f3c85cba36 | 200 | } |