F^3RC D班 / Mbed 2 deprecated clubvs2017_momoi

Dependencies:   mbed

Fork of clubvs2017_momoi by ROBOSTEP4期

Committer:
abcdefgh
Date:
Thu Jun 09 02:53:48 2016 +0000
Revision:
15:5e973e6c058c
Parent:
14:67ee8d8f4efe
Child:
16:ea0808fbbb40
aaaaaaa

Who changed what in which revision?

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