PS3下の階
Dependencies: FatFileSystem PS3_BlueUSB QEI RoboClaw_mine_ mbed
Fork of PS3_BlueUSB by
Diff: Ps3USB.cpp
- Revision:
- 1:b2063ffa4927
- Parent:
- 0:99a111b75cb4
--- a/Ps3USB.cpp Tue Apr 26 16:09:17 2011 +0000 +++ b/Ps3USB.cpp Thu Jan 11 07:47:26 2018 +0000 @@ -36,10 +36,61 @@ #define AUTOEVT(_class,_subclass,_protocol) (((_class) << 16) | ((_subclass) << 8) | _protocol) #define PS3EVT AUTOEVT(CLASS_HID,0,0) #define byteswap(x) ((x >> 8) | (x << 8)) +#define device_baud 115200 //上のマイコンにするバンド数 +#define send_device_rate 0.03 //割り込みレート + u8 ps3_data[48]; +Serial order_device(p28,p27);//上のマイコンに反応させるための初期化宣言 +//*************追加項目ピン設定 +PwmOut led1(LED1); +PwmOut led2(LED2); +PwmOut led3(LED3); +PwmOut led4(LED4); +int joyL_x =0; +int joyL_y =0; +int joyR_x =0; +int joyR_y =0; +int L1 =0; +int R1 =0; +int up =0; +int down =0; +int right =0; +int left =0; +int Xmove =0; +int Ymove =0; +int angle_omni =0; + +int speed_mode =1; + +void omni_move(double x_speed,double y_speed,double angle); +char Buf[8]; + + +//************** + +//以下項目上への指令を送るためのBuf +/* +void send_device(){ + char Buf[8]; + Buf[0] = up; + Buf[1] = down; + Buf[2] = right; + Buf[3] = left; + Buf[4] = 0; + Buf[5] = 0; + order_device.putc(Buf[0]); + order_device.putc(Buf[1]); + order_device.putc(Buf[2]); + order_device.putc(Buf[3]); + order_device.putc(Buf[4]); + order_device.putc(Buf[5]); +} +*/ +//*********まで + Ps3USB::Ps3USB(int device, int configuration, int interfaceNumber) { printf("Creating new sixaxis \r\n"); @@ -211,9 +262,18 @@ wait_ms(4); } + /* + void Connect(){ + order_device.baud(device_baud);//上のマイコンとのbaud指定 + tick_device.attach(&send_device,send_device_rate);//割り込み + } + */ + + int ParsePs3Result(const u8* data,int len,int count) - { + { + order_device.baud(device_baud); ps3report* _ps3report = (ps3report*)data; if (count == 24) printf("LSX LSY RSX RSY UPA RPA DPA RPA L2 R2 L1 R1 TRI CIR CRO SQU ACX ACY ACZ GYZ \r\n"); printf("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %4d %4d %4d %4d \r\n", @@ -238,6 +298,59 @@ (_ps3report->AccelZ), (_ps3report->GyroZ)); //printfBytes("data",data,len); - } + joyL_x =_ps3report->LeftStickX; + joyL_y =_ps3report->LeftStickY; + joyR_x =_ps3report->RightStickY; + joyR_y =_ps3report->RightStickX; + L1 =_ps3report->PressureL1; + R1 =_ps3report->PressureR1; + up =_ps3report->PressureUp; + down =_ps3report->PressureDown; + right =_ps3report->PressureRight; + left =_ps3report->PressureLeft; + + + //デットバンドの設定 + if(120<=joyL_x&&joyL_x<=129) + { + joyL_x=126; + } + if(120<=joyL_y&&joyL_y<=129) + { + joyL_y=126; + } + if(120<=joyR_x&&joyR_x<=129) + { + joyR_x=126; + } + if(120<=joyR_y&&joyR_y<=129) + { + joyR_y=126; + } + + + //低速モードと高速モード設定 + if(L1>=100){ + speed_mode=2; + } + else{ + speed_mode=20; + } + + + order_device.printf("%d,%d,%d,%d\n", up, down, right, left); + + + Xmove =(joyL_x-126)*speed_mode; + Ymove =(joyL_y-126)*speed_mode; + angle_omni =(joyR_y-126)*speed_mode; + + omni_move(angle_omni,Ymove,Xmove); + led1=joyL_x/255.0; + led2=joyL_y/255.0; + led3=joyR_y/255.0; + + printf("joyL_x:%d joyL_y:%d angle_omni:%d \r\n" , Xmove, Ymove, angle_omni); + }