![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Hari H cuy
Dependencies: Motor PID Joystick_OrdoV5 mbed
Fork of Joystick_OrdoV5new by
Revision 12:e07c59c28c29, committed 2016-12-03
- Comitter:
- franshendri
- Date:
- Sat Dec 03 05:43:10 2016 +0000
- Parent:
- 11:e1efcc958f4b
- Commit message:
- tes H
Changed in this revision
--- a/JoystickPS3.h Tue Nov 29 15:26:09 2016 +0000 +++ b/JoystickPS3.h Sat Dec 03 05:43:10 2016 +0000 @@ -1,17 +1,17 @@ #ifndef MBED_H #include "mbed.h" #endif - + #ifndef JoystickPS3__serialDEFAULT_BAUD #define JoystickPS3__serialDEFAULT_BAUD 115200 #endif - + Serial debug(USBTX,USBRX); - - + + namespace JoystickPS3 { - + class joysticknucleo { public: joysticknucleo(PinName tx, PinName rx) : _serial(tx, rx) @@ -31,7 +31,7 @@ _serial.baud(JoystickPS3__serialDEFAULT_BAUD); debug.baud(9600); } - + /*********************************************************************************************/ /** **/ /** FUNGSI PEMBACAAN DATA **/ @@ -170,8 +170,8 @@ // debug.printf("%2x %2x %2x %2x %3d %3d %3d %3d %3d %3d\n\r",button, RL, button_click, RL_click, R2, L2, RX, RY, LX, LY); } } - - + + int readable(){ return _serial.readable(); @@ -192,7 +192,7 @@ virtual int _getc(){return _serial.getc();} Serial _serial; }; - + }; - + using namespace JoystickPS3; \ No newline at end of file
--- a/PS3Arduino.txt Tue Nov 29 15:26:09 2016 +0000 +++ b/PS3Arduino.txt Sat Dec 03 05:43:10 2016 +0000 @@ -9,7 +9,7 @@ /** **/ /** Last Update : 01 Februar1 2015, 20.30 **/ /*********************************************************************************************/ - + #include <PS3BT.h> #include <usbhub.h> //#include <PS3USB.h> @@ -18,10 +18,10 @@ #ifdef dobogusinclude #include <spi4teensy3.h> #endif - - + + USB Usb; - + // Bluetooth // You can create the instance of the class in two ways BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so @@ -34,25 +34,25 @@ PS3USB PS3(&Usb); // This will just create the instance //PS3USB PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch */ - + boolean printAngle; uint8_t state = 0; - + // Deklarasi tombol boolean kiri_click=0, kanan_click=0, atas_click=0, bawah_click=0; boolean segitiga_click=0, lingkaran_click=0, kotak_click=0, silang_click=0; boolean L1_click=0, R1_click=0, L3_click=0, R3_click=0; boolean START_click=0, SELECT_click=0, PS_click=0; - + // Deklarasi variabel tombol analog unsigned char LX, LY, RX, RY, aL2, aR2; - + // Deklarasi varibel data yang dikirim unsigned char button; unsigned char RL; unsigned int button_click; unsigned int RL_click; - + void setup_joystik() { while (!Serial) // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection @@ -70,7 +70,7 @@ } //Serial.print(F("\r\nPS3 USB Library Started")); } - + /*********************************************************************************************/ /** **/ /** FUNGSI PENGIRIMAN DATA **/ @@ -80,7 +80,7 @@ /** |------|------|--------|----|--------------|----------|----|----|----|----|----|----| **/ /** **/ /*********************************************************************************************/ - + void kirimdatajoystik() { @@ -96,9 +96,9 @@ Serial.write(RY); Serial.write(LX); Serial.write(LY); - + // Debug - + /* Serial.print(millis()); Serial.print("\t"); @@ -123,20 +123,20 @@ Serial.println(LY); */ } - + /*****************************************************************************************/ /** SETUP REGISTER dan INISIALISASI **/ /** - Setup Joystik **/ /** - Baud Rate Serial 115200, 8-bit, 1 stop, 0 parity **/ /*****************************************************************************************/ - + void setup() { Serial.begin(115200); - + setup_joystik(); } - - + + /*****************************************************************************************/ /** **/ /** FUNGSI PEMBACAAN DATA JOYSTIK **/ @@ -168,14 +168,14 @@ /** |----|--------|-------|----|----|----|----| **/ /** **/ /*****************************************************************************************/ - + void loop() { button = 0; RL = 0; button_click=0; RL_click=0; Usb.Task(); - + // Pembacaan data joystik dilakukan jika PS3 tersambung ke Arduino if (PS3.PS3Connected || PS3.PS3NavigationConnected) { // Pembacaan dan penggabungan data segitiga, lingkaran, silang, kotak, atas, kanan, bawah, kiri @@ -204,7 +204,7 @@ if(PS3.getButtonPress(LEFT)){ button = button + (0x1 << 7); } - + // Pembacaan dan penggabungan data R1, R3, L1, L3, START, SELECT, dan PS // Data bernilai '1' jika tombol ditekan if(PS3.getButtonPress(R1)){ @@ -228,7 +228,7 @@ if(PS3.getButtonPress(PS)){ RL = RL + (0x1 << 6); } - + // Pembacaan dan penggabungan data segitiga, lingkaran, silang, kotak, atas, kanan, bawah, kiri // Data bernilai '1' hanya saat tombol pertama kali ditekan if(PS3.getButtonClick(TRIANGLE)){ @@ -255,7 +255,7 @@ if(PS3.getButtonClick(LEFT)){ button_click = button_click + (0x1 << 7); } - + if(PS3.getButtonClick(R1)){ RL_click = RL_click + (0x1 << 0); } @@ -277,7 +277,7 @@ if(PS3.getButtonClick(PS)){ RL_click = RL_click + (0x1 << 6); } - + // Tombol Analog LX = PS3.getAnalogHat(LeftHatX); LY = PS3.getAnalogHat(LeftHatY); @@ -295,3 +295,5 @@ } delay(3); } + + \ No newline at end of file
--- a/main.cpp Tue Nov 29 15:26:09 2016 +0000 +++ b/main.cpp Sat Dec 03 05:43:10 2016 +0000 @@ -54,7 +54,8 @@ float speed2=0.6; float speed3=0.6; float speed4=0.6; -float speedL=0.6; +float speedB=0.43 ; +float speedL=0.4; float KpX=0.5, KpY=0.5, Kp_tetha=0.03; @@ -105,9 +106,6 @@ float getX(); float getTetha(); - - - // Inisialisasi Pin TX-RX Joystik dan PC joysticknucleo joystick(PA_0,PA_1); Serial pc(USBTX,USBRX); @@ -233,13 +231,13 @@ { //Servo if (ServoGo){ - servoS.position(10); + servoS.position(20); wait_ms(500); - servoS.position(-70); + servoS.position(-28); wait_ms(500); - servoS.position(10); + servoS.position(20); wait_ms(500); - for (int i = 0; i<=90; i++){ + for (int i = -0; i<=70; i++){ servoB.position(i); wait_ms(10); } @@ -248,7 +246,7 @@ ServoGo = false; }else{ - servoS.position(10); + servoS.position(20); servoB.position(0); } @@ -256,7 +254,7 @@ // Motor Atas if (Launcher) { motorld.speed(speedL); - motorlb.speed(speedL); + motorlb.speed(speedB); }else{ motorld.speed(0); motorlb.speed(0); @@ -508,13 +506,19 @@ void speedLauncher() { - if (joystick.R3_click and speedL < 0.7){ - speedL = speedL + 0.1;} + if (joystick.R3_click and speedL < 0.8){ + speedL = speedL + 0.01;} if (joystick.L3_click and speedL > 0.1){ - speedL = speedL - 0.1;} - + speedL = speedL - 0.01;} + /* if (joystick.R2>0 and speedB < 0.8){ + speedB = speedB + 0.01;} + if (joystick.L2>0 and speedB > 0.1){ + speedB = speedB - 0.01;}*/ + pc.printf("Pwm depan = %.3f\n ", speedL); } - + + + int main (void) { // Set baud rate - 115200 @@ -530,8 +534,6 @@ Tetha = 0; pc.printf("Ready...\n"); kalibrasi(); - servoS.position(90); - servoB.position(0); waktu.start(); while(1) { @@ -542,11 +544,12 @@ joystick.baca_data(); // Panggil fungsi pengolahan data joystik joystick.olah_data(); + //pc.printf("%3d %3d\n\r",joystick.R2, joystick.L2); //pc.printf("%2x %2x %2x %2x %3d %3d %3d %3d %3d %3d\n\r",joystick.button, joystick.RL, joystick.button_click, joystick.RL_click, joystick.R2, joystick.L2, joystick.RX, joystick.RY, joystick.LX, joystick.LY); case_ger = case_gerak(); aktuator(); - pc.printf("bacaS = %.2f\tbacaB = %.2f\n",servoS.read(), servoB.read()); + //pc.printf("bacaS = %.2f\tbacaB = %.2f\n",servoS.read(), servoB.read()); //kalibrasi if (joystick.START){ @@ -565,6 +568,7 @@ pc.printf("x..\n"); } speedLauncher(); + } else { joystick.idle();