新部内対抗5班 / Mbed 2 deprecated 2016_Spring_kaida_0611

Dependencies:   mbed

Fork of 2016_Spring_kaida by 新部内対抗5班

Committer:
abcdefgh
Date:
Mon Jun 06 12:22:38 2016 +0000
Revision:
14:67ee8d8f4efe
Parent:
13:9b0efec30108
Child:
15:5e973e6c058c
moter and arm;

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