F^3RC D班 / Mbed 2 deprecated clubvs2017_momoi

Dependencies:   mbed

Fork of clubvs2017_momoi by ROBOSTEP4期

Committer:
abcdefgh
Date:
Fri Jun 10 17:29:55 2016 +0000
Revision:
18:cab2885dc8fe
Parent:
17:efe67bbb927e
Child:
19:70657aee6fa5
2016/06/10

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 //これより下に関数外に書く要素を記入する
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 18:cab2885dc8fe 98 if((ButtonState >> BUTTONSTART)&1 == 1) {
abcdefgh 17:efe67bbb927e 99 flag = 0;
abcdefgh 18:cab2885dc8fe 100 } else if((ButtonState >> BUTTONR2)&1 == 1) {
abcdefgh 17:efe67bbb927e 101 flag += 0.05;
abcdefgh 18:cab2885dc8fe 102 wait(0.1);
abcdefgh 18:cab2885dc8fe 103 } else if((ButtonState >> BUTTONL2)&1 == 1) {
abcdefgh 17:efe67bbb927e 104 flag -= 0.05;
abcdefgh 18:cab2885dc8fe 105 wait(0.1);
abcdefgh 17:efe67bbb927e 106 }
abcdefgh 18:cab2885dc8fe 107 if(flag >= 1.0) {
abcdefgh 18:cab2885dc8fe 108 flag = 1.0;
abcdefgh 18:cab2885dc8fe 109 }
abcdefgh 18:cab2885dc8fe 110 if(flag <= -0.5) {
abcdefgh 18:cab2885dc8fe 111 flag = 0.5;
abcdefgh 18:cab2885dc8fe 112 }
abcdefgh 18:cab2885dc8fe 113
abcdefgh 17:efe67bbb927e 114 if(LSY>140 && ((ButtonState >> BUTTONLANALOG)&1) == 1) {
abcdefgh 18:cab2885dc8fe 115 motorRightOne = 0.8;
Junbug 12:b2f3c85cba36 116 motorRightTwo = 0;
abcdefgh 17:efe67bbb927e 117 motorLeftOne = 0.8;
abcdefgh 17:efe67bbb927e 118 motorLeftTwo = 0;
abcdefgh 18:cab2885dc8fe 119 } else if(LSY<110 && ((ButtonState >> BUTTONLANALOG)&1) == 1) {
abcdefgh 18:cab2885dc8fe 120 motorRightOne = 0;
abcdefgh 17:efe67bbb927e 121 motorRightTwo = 0.8;
abcdefgh 17:efe67bbb927e 122 motorLeftOne = 0;
abcdefgh 18:cab2885dc8fe 123 motorLeftTwo = 0.8;
abcdefgh 18:cab2885dc8fe 124 } else if( LSY > 140 ) { //forward
abcdefgh 18:cab2885dc8fe 125 motorRightOne = 0.6 + flag;
abcdefgh 17:efe67bbb927e 126 motorRightTwo = 0;
abcdefgh 18:cab2885dc8fe 127 motorLeftOne = 0.6 + flag;
Junbug 12:b2f3c85cba36 128 motorLeftTwo = 0;
abcdefgh 15:5e973e6c058c 129
abcdefgh 15:5e973e6c058c 130 } else if( LSY < 110 ) { //back
Junbug 12:b2f3c85cba36 131 motorRightOne = 0;
abcdefgh 18:cab2885dc8fe 132 motorRightTwo = 0.6 + flag;
Junbug 12:b2f3c85cba36 133 motorLeftOne = 0;
abcdefgh 18:cab2885dc8fe 134 motorLeftTwo = 0.6 + flag;
abcdefgh 15:5e973e6c058c 135 } else { //stop
abcdefgh 14:67ee8d8f4efe 136 motorRightOne = 0;
abcdefgh 14:67ee8d8f4efe 137 motorRightTwo = 0;
abcdefgh 14:67ee8d8f4efe 138 motorLeftOne = 0;
abcdefgh 14:67ee8d8f4efe 139 motorLeftTwo = 0;
abcdefgh 14:67ee8d8f4efe 140 }
abcdefgh 14:67ee8d8f4efe 141
abcdefgh 14:67ee8d8f4efe 142 if(( ButtonState >> BUTTONR1)&1 == 1) {
abcdefgh 18:cab2885dc8fe 143 motorRightOne = 0.5 + flag;
abcdefgh 18:cab2885dc8fe 144 motorRightTwo = 0;
abcdefgh 18:cab2885dc8fe 145 motorLeftOne = 0;
abcdefgh 18:cab2885dc8fe 146 motorLeftTwo = 0.5 + flag;
abcdefgh 15:5e973e6c058c 147 }
abcdefgh 15:5e973e6c058c 148 if(( ButtonState >> BUTTONL1)&1 == 1) {
abcdefgh 18:cab2885dc8fe 149 motorRightOne = 0;
abcdefgh 18:cab2885dc8fe 150 motorRightTwo = 0.5 + flag;
abcdefgh 18:cab2885dc8fe 151 motorLeftOne = 0.5 + flag;
abcdefgh 18:cab2885dc8fe 152 motorLeftTwo = 0;
abcdefgh 14:67ee8d8f4efe 153 }
abcdefgh 14:67ee8d8f4efe 154
abcdefgh 14:67ee8d8f4efe 155 //arm
abcdefgh 14:67ee8d8f4efe 156
abcdefgh 18:cab2885dc8fe 157 if( (ButtonState >> BUTTONDOWN)&1 == 1 ) {
abcdefgh 17:efe67bbb927e 158 armThree = 0;
abcdefgh 17:efe67bbb927e 159 armFour = 1;
abcdefgh 18:cab2885dc8fe 160 armLeft = 0.8;
abcdefgh 18:cab2885dc8fe 161 } else if( (ButtonState >> BUTTONUP)&1 == 1 ) {
abcdefgh 17:efe67bbb927e 162 armThree = 1;
abcdefgh 17:efe67bbb927e 163 armFour = 0;
abcdefgh 17:efe67bbb927e 164 armLeft = 0.4;
abcdefgh 17:efe67bbb927e 165 } else {
abcdefgh 17:efe67bbb927e 166 armThree = 0;
abcdefgh 17:efe67bbb927e 167 armFour = 0;
abcdefgh 17:efe67bbb927e 168 armLeft = 0;
abcdefgh 17:efe67bbb927e 169
abcdefgh 17:efe67bbb927e 170 }
abcdefgh 17:efe67bbb927e 171
abcdefgh 18:cab2885dc8fe 172 if((ButtonState >> BUTTONTRIANGEL)&1 == 1) {
abcdefgh 17:efe67bbb927e 173 armOne = 1;
abcdefgh 17:efe67bbb927e 174 armTwo = 0;
abcdefgh 17:efe67bbb927e 175 armRight = 0.4;
abcdefgh 18:cab2885dc8fe 176 } else if((ButtonState >> BUTTONCROSS)&1 == 1) {
abcdefgh 15:5e973e6c058c 177 armOne = 0;
abcdefgh 15:5e973e6c058c 178 armTwo = 1;
abcdefgh 14:67ee8d8f4efe 179 armRight = 0.4;
abcdefgh 14:67ee8d8f4efe 180 } else {
abcdefgh 14:67ee8d8f4efe 181 armOne = 0;
abcdefgh 14:67ee8d8f4efe 182 armTwo = 0;
abcdefgh 14:67ee8d8f4efe 183 armRight = 0;
abcdefgh 15:5e973e6c058c 184
abcdefgh 14:67ee8d8f4efe 185
abcdefgh 17:efe67bbb927e 186 /*
abcdefgh 17:efe67bbb927e 187 With oen if, put both arms and legs.
abcdefgh 14:67ee8d8f4efe 188
abcdefgh 17:efe67bbb927e 189 Use start and select??
Junbug 12:b2f3c85cba36 190
Junbug 12:b2f3c85cba36 191
abcdefgh 17:efe67bbb927e 192 */
Junbug 12:b2f3c85cba36 193
abcdefgh 16:ea0808fbbb40 194
Junbug 12:b2f3c85cba36 195
abcdefgh 16:ea0808fbbb40 196
Junbug 12:b2f3c85cba36 197
abcdefgh 17:efe67bbb927e 198 /*
abcdefgh 17:efe67bbb927e 199 led3=ButtonState & 0x0400; //L1の状態
abcdefgh 17:efe67bbb927e 200 led4=ButtonState & 0x0800; //R1の状態
abcdefgh 17:efe67bbb927e 201 */ //値の取得はps3.hを参照
Junbug 12:b2f3c85cba36 202
abcdefgh 17:efe67bbb927e 203 }
Junbug 12:b2f3c85cba36 204
Junbug 12:b2f3c85cba36 205 }