keita noda
/
2016_Sp_momoi_0611
ももいくん
Fork of 2016_Sp_momoi_taka by
momoi_taka.cpp
- Committer:
- atsushika
- Date:
- 2016-06-09
- Revision:
- 12:d811e29e469a
- Child:
- 13:9e04b53e875a
File content as of revision 12:d811e29e469a:
#include "Utils.h" #include "USBHost.h" #include "hci.h" #include "ps3.h" #include "User.h" #include "mbed.h" int RSX,RSY,LSX,LSY,BSU,BSL; //これより下に関数外に書く要素を記入する /* PwmOut led1(LED1); PwmOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); */ //momoi //MD1 right PwmOut motorRightOne (p23); PwmOut motorRightTwo (p24); //MD2 left PwmOut motorLeftOne (p21); PwmOut motorLeftTwo (p22); //MD3 Arm1 PwmOut armOneJun(p26); DigitalOut chocolateOne (p30); DigitalOut chocolateTwo (p29); //MD4 Arm2 PwmOut armTwoTaka(p25); DigitalOut brownieOne (p6); DigitalOut brownieTwo (p5); void UserLoopSetting(){ //一度だけ行いたい初期設定をここに書く /* led1.period_ms(20);*/ } void UserLoop(char n,const u8* data){ u16 ButtonState; if(n==0){//有線Ps3USB.cpp RSX = ((ps3report*)data)->RightStickX; RSY = ((ps3report*)data)->RightStickY; LSX = ((ps3report*)data)->LeftStickX; LSY = ((ps3report*)data)->LeftStickY; BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); BSL = (u8)(((ps3report*)data)->ButtonState >> 8); //ボタンの処理 ButtonState = ((ps3report*)data)->ButtonState; }else {//無線TestShell.cpp RSX = ((ps3report*)(data + 1))->RightStickX; RSY = ((ps3report*)(data + 1))->RightStickY; LSX = ((ps3report*)(data + 1))->LeftStickX; LSY = ((ps3report*)(data + 1))->LeftStickY; BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); //ボタンの処理 ButtonState = ((ps3report*)(data + 1))->ButtonState; } //ここより下にプログラムを書く if(LSY>140 && ((ButtonState >> BUTTONLANALOG)&1) == 1) { motorRightOne = 0.8; motorRightTwo = 0; motorLeftOne = 0.9; motorLeftTwo = 0; } else if(LSY<110 && ((ButtonState >> BUTTONLANALOG)&1) == 1) { motorRightOne = 0; motorRightTwo = 0.8; motorLeftOne = 0; motorLeftTwo = 0.9; } else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 0) {//forward motorRightOne = 0.4; motorRightTwo = 0; motorLeftOne = 0.5; motorLeftTwo = 0; } else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 0) {//turn right motorRightOne = 0; motorRightTwo = 0.4; motorLeftOne = 0.5; motorLeftTwo = 0; } else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 1) {//turn left motorRightOne = 0.4; motorRightTwo = 0; motorLeftOne = 0; motorLeftTwo = 0.5; }else if(LSY>140 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 1) {//forward motorRightOne = 0.4; motorRightTwo = 0; motorLeftOne = 0.5; motorLeftTwo = 0; } else if(LSY<110 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 0) { //back motorRightOne = 0; motorRightTwo = 0.4; motorLeftOne = 0; motorLeftTwo = 0.5; } else if (LSY<110 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 0) { //turn right motorRightOne = 0; motorRightTwo = 0.4; motorLeftOne = 0.5; motorLeftTwo = 0; } else if(LSY<110 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 1) {//turn left motorRightOne = 0.4; motorRightTwo = 0; motorLeftOne = 0; motorLeftTwo = 0.5; }else if (LSY<110 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 1) {//back motorRightOne = 0; motorRightTwo = 0.4; motorLeftOne = 0; motorLeftTwo = 0.5; } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) == 0 && ((ButtonState >> BUTTONR1)&1) == 0) {//stop motorRightOne = 0; motorRightTwo = 0; motorLeftOne = 0; motorLeftTwo = 0; } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) ==1 && ((ButtonState >> BUTTONR1)&1) == 0) { //turn right motorRightOne = 0; motorRightTwo = 0.4; motorLeftOne = 0.5; motorLeftTwo = 0; } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) ==0 && ((ButtonState >> BUTTONR1)&1) == 1) { //turn left motorRightOne = 0.4; motorRightTwo = 0; motorLeftOne = 0; motorLeftTwo = 0.5; } else if(LSY>=110 && RSY<= 140 && ((ButtonState >> BUTTONL1)&1) == 1 && ((ButtonState >> BUTTONR1)&1) == 1) { //stop motorRightOne = 0; motorRightTwo = 0; motorLeftOne = 0; motorLeftTwo = 0; }else{ motorRightOne = 0; motorRightTwo = 0; motorLeftOne = 0; motorLeftTwo = 0; } if(((ButtonState >> BUTTONDOWN)&1) == 1 && ((ButtonState >> BUTTONUP)&1) == 0) { armOneJun = 0.8; chocolateOne = 1; chocolateTwo = 0; } else if (((ButtonState >> BUTTONDOWN)&1) == 0 && ((ButtonState >> BUTTONUP)&1) == 1) { armOneJun = 0.8; chocolateOne = 0; chocolateTwo = 1; } else { armOneJun = 0; chocolateOne = 0; chocolateTwo = 0; } if( ((ButtonState >> BUTTONSQUARE)&1) == 1 && ((ButtonState >> BUTTONCIRCLE)&1) == 0 ) { //つかむか放す armTwoTaka = 0.4; brownieOne = 1; brownieTwo = 0; } else if ( ((ButtonState >> BUTTONSQUARE)&1) == 0 && ((ButtonState >> BUTTONCIRCLE)&1) == 1 ) { armTwoTaka = 0.4; brownieOne = 0; brownieTwo = 1; } else { armTwoTaka = 0; brownieOne = 0; brownieTwo = 0; } //データ取得例 if((ButtonState >> BUTTONCIRCLE)&1) { //○が押されたとき } //値の取得はps3.hを参照 }