ももいくん

Dependencies:   mbed

Fork of 2016_Sp_momoi_0611 by keita noda

Committer:
abcdefgh
Date:
Fri Oct 21 08:17:51 2016 +0000
Revision:
14:caab74db0c6d
Parent:
13:9e04b53e875a
a

Who changed what in which revision?

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