yuto kawamura
/
F3RC_syudou_master
主導機 mbed用のプログラムです
Fork of F3RC_syudou_master by
User.cpp@12:1254070d444a, 2016-11-06 (annotated)
- Committer:
- hokkyokuh2
- Date:
- Sun Nov 06 01:25:39 2016 +0000
- Revision:
- 12:1254070d444a
- Parent:
- 11:86d717718dbf
takasugi
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hirokimineshita | 0:736c76a75def | 1 | #include "Utils.h" |
hirokimineshita | 0:736c76a75def | 2 | #include "USBHost.h" |
hirokimineshita | 0:736c76a75def | 3 | #include "hci.h" |
hirokimineshita | 0:736c76a75def | 4 | #include "ps3.h" |
hirokimineshita | 0:736c76a75def | 5 | #include "User.h" |
hirokimineshita | 0:736c76a75def | 6 | |
hirokimineshita | 0:736c76a75def | 7 | #include "mbed.h" |
hirokimineshita | 0:736c76a75def | 8 | |
hokkyokuh2 | 12:1254070d444a | 9 | |
hirokimineshita | 0:736c76a75def | 10 | int RSX,RSY,LSX,LSY,BSU,BSL; |
hirokimineshita | 9:e5437ba3e920 | 11 | //これより下に関数外に書く要素を記入する |
hokkyokuh2 | 12:1254070d444a | 12 | |
hokkyokuh2 | 12:1254070d444a | 13 | //SPI通信の宣言 |
hokkyokuh2 | 12:1254070d444a | 14 | SPI spi(p5, p6, p7); // mosi, miso, sclk |
hokkyokuh2 | 12:1254070d444a | 15 | DigitalOut cs(p8); |
baba2357 | 11:86d717718dbf | 16 | |
hokkyokuh2 | 12:1254070d444a | 17 | /* |
hokkyokuh2 | 12:1254070d444a | 18 | 2進数の足回り、昇降機構、開閉機構の情報 |
hokkyokuh2 | 12:1254070d444a | 19 | valmasterは全ての情報の合計 |
hokkyokuh2 | 12:1254070d444a | 20 | */ |
hokkyokuh2 | 12:1254070d444a | 21 | int valArm = 0; |
hokkyokuh2 | 12:1254070d444a | 22 | int valUpDown = 0; |
hokkyokuh2 | 12:1254070d444a | 23 | int valLeg = 0; |
hokkyokuh2 | 12:1254070d444a | 24 | int valMaster = 0; |
hokkyokuh2 | 12:1254070d444a | 25 | |
hokkyokuh2 | 12:1254070d444a | 26 | DigitalOut led (LED1); |
hokkyokuh2 | 12:1254070d444a | 27 | |
hokkyokuh2 | 12:1254070d444a | 28 | |
hokkyokuh2 | 12:1254070d444a | 29 | void UserLoopSetting() |
hokkyokuh2 | 12:1254070d444a | 30 | { |
hirokimineshita | 0:736c76a75def | 31 | //一度だけ行いたい初期設定をここに書く |
hokkyokuh2 | 12:1254070d444a | 32 | |
hirokimineshita | 0:736c76a75def | 33 | } |
hirokimineshita | 0:736c76a75def | 34 | |
hokkyokuh2 | 12:1254070d444a | 35 | void UserLoop(char n,const u8* data) |
hokkyokuh2 | 12:1254070d444a | 36 | { |
hirokimineshita | 0:736c76a75def | 37 | u16 ButtonState; |
hokkyokuh2 | 12:1254070d444a | 38 | if(n==0) { //有線Ps3USB.cpp |
hirokimineshita | 0:736c76a75def | 39 | RSX = ((ps3report*)data)->RightStickX; |
hirokimineshita | 0:736c76a75def | 40 | RSY = ((ps3report*)data)->RightStickY; |
hirokimineshita | 0:736c76a75def | 41 | LSX = ((ps3report*)data)->LeftStickX; |
hirokimineshita | 0:736c76a75def | 42 | LSY = ((ps3report*)data)->LeftStickY; |
hirokimineshita | 0:736c76a75def | 43 | BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 44 | BSL = (u8)(((ps3report*)data)->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 45 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 46 | ButtonState = ((ps3report*)data)->ButtonState; |
hokkyokuh2 | 12:1254070d444a | 47 | } else {//無線TestShell.cpp |
hirokimineshita | 0:736c76a75def | 48 | RSX = ((ps3report*)(data + 1))->RightStickX; |
hirokimineshita | 0:736c76a75def | 49 | RSY = ((ps3report*)(data + 1))->RightStickY; |
hirokimineshita | 0:736c76a75def | 50 | LSX = ((ps3report*)(data + 1))->LeftStickX; |
hirokimineshita | 0:736c76a75def | 51 | LSY = ((ps3report*)(data + 1))->LeftStickY; |
hirokimineshita | 0:736c76a75def | 52 | BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 53 | BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 54 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 55 | ButtonState = ((ps3report*)(data + 1))->ButtonState; |
hirokimineshita | 0:736c76a75def | 56 | } |
hirokimineshita | 0:736c76a75def | 57 | //ここより下にプログラムを書く |
hokkyokuh2 | 12:1254070d444a | 58 | //送る情報は2進数で考えた後、10進数に直して送る。(2進数での書き込みができないため) |
hokkyokuh2 | 12:1254070d444a | 59 | |
hokkyokuh2 | 12:1254070d444a | 60 | /* |
hokkyokuh2 | 12:1254070d444a | 61 | SPI通信の設定 |
hokkyokuh2 | 12:1254070d444a | 62 | 通信量が多い場合、frequencyの値を上げると問題が解決するかもしれない |
hokkyokuh2 | 12:1254070d444a | 63 | */ |
hokkyokuh2 | 12:1254070d444a | 64 | spi.format(16,3); |
hokkyokuh2 | 12:1254070d444a | 65 | spi.frequency(1000000); |
hokkyokuh2 | 12:1254070d444a | 66 | cs = 0; |
hokkyokuh2 | 12:1254070d444a | 67 | |
baba2357 | 11:86d717718dbf | 68 | |
hokkyokuh2 | 12:1254070d444a | 69 | ///////アーム部分///////// |
hokkyokuh2 | 12:1254070d444a | 70 | if(((ButtonState >> BUTTONR1)&1 == 1)&&((ButtonState >> BUTTONL1)&1 == 1)) {//両方閉じる |
hokkyokuh2 | 12:1254070d444a | 71 | valArm = 3584;//0111000000000; |
hokkyokuh2 | 12:1254070d444a | 72 | } else if((ButtonState >> BUTTONR1)&1 == 1) {//右側閉じる |
hokkyokuh2 | 12:1254070d444a | 73 | valArm = 2560;//0101000000000; |
hokkyokuh2 | 12:1254070d444a | 74 | } else if((ButtonState >> BUTTONL1)&1 == 1) {//左側閉じる |
hokkyokuh2 | 12:1254070d444a | 75 | valArm = 3072;//0110000000000; |
hokkyokuh2 | 12:1254070d444a | 76 | } else if(((ButtonState >> BUTTONR2)&1 == 1)&&((ButtonState >> BUTTONL2)&1 == 1)) {//両方開く |
hokkyokuh2 | 12:1254070d444a | 77 | valArm = 1536;//0011000000000; |
hokkyokuh2 | 12:1254070d444a | 78 | } else if ((ButtonState >> BUTTONR2)&1 == 1) {//右側開く |
hokkyokuh2 | 12:1254070d444a | 79 | valArm = 512;//0001000000000; |
hokkyokuh2 | 12:1254070d444a | 80 | } else if((ButtonState >> BUTTONL2)&1 == 1) {//左側開く |
hokkyokuh2 | 12:1254070d444a | 81 | valArm = 1024;//0010000000000; |
hokkyokuh2 | 12:1254070d444a | 82 | } else { |
hokkyokuh2 | 12:1254070d444a | 83 | valArm = 0;//0000000000000; |
hokkyokuh2 | 12:1254070d444a | 84 | } |
hokkyokuh2 | 12:1254070d444a | 85 | if((ButtonState >> BUTTONCIRCLE)&1 == 1) { //開く時、○ボタンを押すとスピードが上がる |
hokkyokuh2 | 12:1254070d444a | 86 | valArm = valArm + 4096;//1000000000000; |
hokkyokuh2 | 12:1254070d444a | 87 | } |
hokkyokuh2 | 12:1254070d444a | 88 | |
hokkyokuh2 | 12:1254070d444a | 89 | //昇降機構 |
hokkyokuh2 | 12:1254070d444a | 90 | if((ButtonState >> BUTTONSQUARE)&1 == 1) {//big up |
hokkyokuh2 | 12:1254070d444a | 91 | valUpDown = 24;//11000; |
hokkyokuh2 | 12:1254070d444a | 92 | } else if((ButtonState >> BUTTONCROSS)&1 == 1) {//big down |
hokkyokuh2 | 12:1254070d444a | 93 | valUpDown = 16;//10000; |
hokkyokuh2 | 12:1254070d444a | 94 | } else {//not moving |
hokkyokuh2 | 12:1254070d444a | 95 | valUpDown = 0;//00000; |
hirokimineshita | 0:736c76a75def | 96 | } |
hokkyokuh2 | 12:1254070d444a | 97 | |
hokkyokuh2 | 12:1254070d444a | 98 | //足回り |
hokkyokuh2 | 12:1254070d444a | 99 | if(RSY < 110 && LSY < 110) { //forward |
hokkyokuh2 | 12:1254070d444a | 100 | valLeg =480; //111100000; |
hokkyokuh2 | 12:1254070d444a | 101 | led = 1; |
hokkyokuh2 | 12:1254070d444a | 102 | } else if( RSY < 140 && RSY >= 110 && LSY < 110) { //small turn right1 |
hokkyokuh2 | 12:1254070d444a | 103 | valLeg = 384;//110000000; |
hokkyokuh2 | 12:1254070d444a | 104 | } else if(RSY >= 140 && LSY < 110) { //big turn right |
hokkyokuh2 | 12:1254070d444a | 105 | valLeg = 416;//110100000; |
hokkyokuh2 | 12:1254070d444a | 106 | } else if(RSY >= 140 && LSY >= 110 && LSY < 140) { //small turn right2 |
hokkyokuh2 | 12:1254070d444a | 107 | valLeg = 32;//000100000; |
hokkyokuh2 | 12:1254070d444a | 108 | } else if(RSY < 110 && LSY >= 110 && LSY < 140) { //small turn left1 |
hokkyokuh2 | 12:1254070d444a | 109 | valLeg = 96;//001100000; |
hokkyokuh2 | 12:1254070d444a | 110 | } else if(RSY < 110 && LSY >= 140) { //big turn left |
hokkyokuh2 | 12:1254070d444a | 111 | valLeg = 224;//011100000; |
hokkyokuh2 | 12:1254070d444a | 112 | } else if(RSY < 140 && RSY >= 110 && LSY >=140) { //small turn left2 |
hokkyokuh2 | 12:1254070d444a | 113 | valLeg = 128;//010000000; |
hokkyokuh2 | 12:1254070d444a | 114 | } else if(RSY >= 140 && LSY >= 140) {//back |
hokkyokuh2 | 12:1254070d444a | 115 | valLeg = 160;//010100000; |
hokkyokuh2 | 12:1254070d444a | 116 | } else if((ButtonState >> BUTTONUP)&1 == 1) { //微調整前進 |
hokkyokuh2 | 12:1254070d444a | 117 | valLeg = 256;//100000000; |
hokkyokuh2 | 12:1254070d444a | 118 | } else if((ButtonState >> BUTTONDOWN)&1 == 1) { //微調整後進 |
hokkyokuh2 | 12:1254070d444a | 119 | valLeg = 288;//100100000 |
hokkyokuh2 | 12:1254070d444a | 120 | } else if((ButtonState >> BUTTONRIGHT)&1 == 1) { //微調整右折 |
hokkyokuh2 | 12:1254070d444a | 121 | valLeg = 320;//101000000 |
hokkyokuh2 | 12:1254070d444a | 122 | } else if((ButtonState >> BUTTONLEFT)&1 == 1) { //微調整左折 |
hokkyokuh2 | 12:1254070d444a | 123 | valLeg = 352;//101100000 |
hokkyokuh2 | 12:1254070d444a | 124 | } else { |
hokkyokuh2 | 12:1254070d444a | 125 | valLeg = 0;//000000000; |
hokkyokuh2 | 12:1254070d444a | 126 | } |
hokkyokuh2 | 12:1254070d444a | 127 | |
hokkyokuh2 | 12:1254070d444a | 128 | valMaster = valLeg + valUpDown + valArm;//この値をSPI通信で送る |
baba2357 | 11:86d717718dbf | 129 | |
hokkyokuh2 | 12:1254070d444a | 130 | spi.write(valMaster); |
hokkyokuh2 | 12:1254070d444a | 131 | cs = 1; |
hokkyokuh2 | 12:1254070d444a | 132 | } |