F^3RC D班 / Mbed 2 deprecated clubvs2017_momoi

Dependencies:   mbed

Fork of clubvs2017_momoi by ROBOSTEP4期

Revision:
20:26099c7e87c6
Parent:
19:70657aee6fa5
Child:
21:f4c8994122cc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/User.cpp	Thu Mar 30 06:26:57 2017 +0000
@@ -0,0 +1,200 @@
+#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;
+//これより下に関数外に書く要素を記入する
+double flag;
+
+//MD1
+
+PwmOut motorRightOne (p25);
+PwmOut motorRightTwo (p26);
+
+//MD2
+PwmOut motorLeftOne (p24);
+PwmOut motorLeftTwo (p23);
+
+//MD3 Arm1
+PwmOut armRight(p22);
+DigitalOut armOne (p29);
+DigitalOut armTwo (p30);
+
+//MD4 Arm2
+PwmOut armLeft(p21);
+DigitalOut armThree (p19);
+DigitalOut armFour (p20);
+
+/*
+
+PWM->0.xxx
+Digitals->0 and 0.xxx
+for arms(I guess...)
+
+For lergs, turn right or left, and just going go and back.->Probably using sticks.
+How to cha ge speed? Two different tyes of speed.
+
+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!!
+Left stick, speed and right/left
+Push button and max incline -> the max speed
+Just max incline -> usual speed
+Little incline -> slow speed
+
+L1/R2 -> turning?
+
+Lifting ->
+
+*/
+
+
+
+void UserLoopSetting()
+{
+    //一度だけ行いたい初期設定をここに書く
+    /*
+    I need to ask what to do with this!
+    Actually, do we have any LEDs?
+    */
+
+}
+
+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;
+    }
+    //ここより下にプログラムを書く
+
+    /*
+     double thesOne = 64;
+     double thesTwo = 127;
+     double thesThree = 191;
+     double fastSpeed = 1;
+     double slowSpeed = 0.5;
+     */
+
+//motor
+
+    if((ButtonState >> BUTTONL2)&1 == 1) {
+        flag -= 0.1;
+        wait(0.1);
+    } else if((ButtonState >> BUTTONR2)&1 == 1) {
+        flag = 0;
+        wait(0.1);
+    }
+    if(flag <= -0.2) {
+        flag = -0.2;
+    }
+
+    if(LSY>140 && ((ButtonState >> BUTTONLANALOG)&1) == 1) {
+        motorRightOne = 0.9;
+        motorRightTwo = 0;
+        motorLeftOne = 0.9;
+        motorLeftTwo = 0;
+    } else if(LSY<110 && ((ButtonState >> BUTTONLANALOG)&1) == 1) {
+        motorRightOne = 0;
+        motorRightTwo = 0.9;
+        motorLeftOne = 0;
+        motorLeftTwo = 0.9;
+    } else if(  LSY > 140 ) { //forward
+        motorRightOne = 0.6 + flag;
+        motorRightTwo = 0;
+        motorLeftOne = 0.6 + flag;
+        motorLeftTwo = 0;
+
+    } else if( LSY < 110 ) { //back
+        motorRightOne = 0;
+        motorRightTwo = 0.6 + flag;
+        motorLeftOne = 0;
+        motorLeftTwo = 0.6 + flag;
+    } else { //stop
+        motorRightOne = 0;
+        motorRightTwo = 0;
+        motorLeftOne = 0;
+        motorLeftTwo = 0;
+    }
+
+    if(( ButtonState >> BUTTONR1)&1 == 1) {
+        motorRightOne = 0.7 + flag;
+        motorRightTwo = 0;
+        motorLeftOne = 0;
+        motorLeftTwo = 0.7 + flag;
+    }
+    if(( ButtonState >> BUTTONL1)&1 == 1) {
+        motorRightOne = 0;
+        motorRightTwo = 0.6 + flag;
+        motorLeftOne = 0.6 + flag;
+        motorLeftTwo = 0;
+    }
+
+//arm
+
+
+    if((ButtonState >> BUTTONSQUARE)&1 == 1) {
+        armOne = 1;
+        armTwo = 0;
+        armRight = 0.4;
+    } else if((ButtonState >> BUTTONCIRCLE)&1 == 1) {
+        armOne = 0;
+        armTwo = 1;
+        armRight = 0.4;
+    } else {
+        armOne = 0;
+        armTwo = 0;
+        armRight = 0;
+    }
+
+    if(  (ButtonState >> BUTTONCROSS)&1 == 1 ) {
+        armThree = 0;
+        armFour = 1;
+        armLeft = 0.9;
+    } else if( (ButtonState >> BUTTONTRIANGEL)&1 == 1 ) {
+        armThree = 1;
+        armFour = 0;
+        armLeft = 0.8;
+    } else {
+        armThree = 0;
+        armFour = 0;
+        armLeft = 0;
+
+    }
+
+
+    /*
+    With oen if, put both arms and legs.
+
+    Use start and select??
+
+
+    */
+
+
+
+
+
+    /*
+        led3=ButtonState & 0x0400;  //L1の状態
+        led4=ButtonState & 0x0800;  //R1の状態
+      */  //値の取得はps3.hを参照
+
+}
\ No newline at end of file