![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
dear josh
Dependencies: DigitDisplay Motor PID Ping mbed millis
Fork of DagonFly__RoadToJapan_15Mei by
main.cpp@51:292c5807a93f, 2017-05-15 (annotated)
- Committer:
- Najib_irvani
- Date:
- Mon May 15 12:51:35 2017 +0000
- Revision:
- 51:292c5807a93f
- Parent:
- 50:8bc9dbca2ffa
dear josh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Najib_irvani | 47:6cac4f1a3c8e | 1 | /*tuning motor baru untuk konstanta pid baru */ |
rahmadirizki18 | 5:3aa203218306 | 2 | /****************************************************************************/ |
rahmadirizki18 | 5:3aa203218306 | 3 | /* PROGRAM UNTUK PID CLOSED LOOP */ |
rahmadirizki18 | 5:3aa203218306 | 4 | /* */ |
Najib_irvani | 47:6cac4f1a3c8e | 5 | /* Last Update : 16 April 2017 */ |
gustavaditya | 31:d5cbda07fd95 | 6 | /* */ |
rahmadirizki18 | 5:3aa203218306 | 7 | /* - Digunakan encoder autonics */ |
rahmadirizki18 | 5:3aa203218306 | 8 | /* - Konfigurasi Motor dan Encoder sbb : */ |
MarchioKevin | 22:4632f58461e0 | 9 | /* ______________________ */ |
MarchioKevin | 22:4632f58461e0 | 10 | /* / \ Rode Depan Belakang: */ |
MarchioKevin | 22:4632f58461e0 | 11 | /* / 2 (Belakang) \ Omniwheel */ |
MarchioKevin | 22:4632f58461e0 | 12 | /* | | */ |
Najib_irvani | 43:3807a95aa284 | 13 | /* | 3 (kiri) 4 (kanan) | Roda Kiri Kanan: */ |
Najib_irvani | 43:3807a95aa284 | 14 | /* | | Omniwheel */ |
MarchioKevin | 22:4632f58461e0 | 15 | /* \ 1 (Depan) / */ |
MarchioKevin | 22:4632f58461e0 | 16 | /* \______________________/ Putaran berlawanan arah */ |
MarchioKevin | 22:4632f58461e0 | 17 | /* jarum jam positif */ |
rahmadirizki18 | 5:3aa203218306 | 18 | /* SETTINGS (WAJIB!) : */ |
rahmadirizki18 | 5:3aa203218306 | 19 | /* 1. Settings Pin Encoder, Resolusi, dan Tipe encoding di omniPos.h */ |
rahmadirizki18 | 5:3aa203218306 | 20 | /* 2. Deklarasi penggunaan library omniPos pada bagian deklarasi encoder */ |
rahmadirizki18 | 5:3aa203218306 | 21 | /* */ |
rahmadirizki18 | 5:3aa203218306 | 22 | /****************************************************************************/ |
rahmadirizki18 | 6:68293bed71ea | 23 | /* */ |
MarchioKevin | 20:54dc93e7b016 | 24 | /* Joystick */ |
Sufa | 30:d69cc27ac644 | 25 | /* Kanan => */ |
Sufa | 30:d69cc27ac644 | 26 | /* Kiri => */ |
rahmadirizki18 | 6:68293bed71ea | 27 | /* */ |
Najib_irvani | 44:452c214d9cf5 | 28 | /* Tombol silang => Pneumatik aktif */ |
Sufa | 30:d69cc27ac644 | 29 | /* Tombol segitiga => Aktif motor Launcher */ |
Najib_irvani | 44:452c214d9cf5 | 30 | /* Tombol lingkaran => Reloader naik */ |
Najib_irvani | 44:452c214d9cf5 | 31 | /* Tombol kotak => Reloader turun */ |
Sufa | 30:d69cc27ac644 | 32 | /* Tombol L1 => Pivot Kiri */ |
Sufa | 30:d69cc27ac644 | 33 | /* Tombol R1 => Pivot Kanan */ |
Najib_irvani | 44:452c214d9cf5 | 34 | /* Tombol L2 => Kurang PWM Motor Launcher */ |
Najib_irvani | 44:452c214d9cf5 | 35 | /* Tombol R2 => Tambah PWM Motor Launcher */ |
rahmadirizki18 | 13:8ab42383a2ca | 36 | /* */ |
calmantara186 | 16:90119f03c5d1 | 37 | /* Bismillahirahmanirrahim */ |
MarchioKevin | 20:54dc93e7b016 | 38 | /* Jagalah Kebersihan Kodingan */ |
rahmadirizki18 | 6:68293bed71ea | 39 | /****************************************************************************/ |
rahmadirizki18 | 6:68293bed71ea | 40 | |
fanny868 | 0:9072e932503c | 41 | #include "mbed.h" |
fanny868 | 0:9072e932503c | 42 | #include "JoystickPS3.h" |
fanny868 | 0:9072e932503c | 43 | #include "Motor.h" |
rahmadirizki18 | 5:3aa203218306 | 44 | #include "encoderKRAI.h" |
be_bryan | 26:256160a1a82d | 45 | #include "millis.h" |
gustavaditya | 40:5b937cac959a | 46 | #include "Ping.h" |
franshendri | 42:6caf8bd5abbc | 47 | #include "DigitDisplay.h" |
franshendri | 42:6caf8bd5abbc | 48 | |
calmantara186 | 16:90119f03c5d1 | 49 | /***********************************************/ |
calmantara186 | 16:90119f03c5d1 | 50 | /* Konstanta dan Variabel */ |
calmantara186 | 16:90119f03c5d1 | 51 | /***********************************************/ |
calmantara186 | 16:90119f03c5d1 | 52 | #define PI 3.14159265 |
be_bryan | 26:256160a1a82d | 53 | #define D_ENCODER 10 // Diameter Roda Encoder |
be_bryan | 26:256160a1a82d | 54 | #define D_ROBOT 80 // Diameter Roda Robot |
rahmadirizki18 | 5:3aa203218306 | 55 | |
Najib_irvani | 46:85169ae8659b | 56 | // Variable Atas |
Najib_irvani | 46:85169ae8659b | 57 | // indek 2 untuk motor depan, 1 untuk motor belakang |
gustavaditya | 38:3ef6754bd8d8 | 58 | double speed, speed2; |
Najib_irvani | 47:6cac4f1a3c8e | 59 | const double maxSpeed = 0.95, minSpeed = -0.95, Ts = 12.5; |
Najib_irvani | 49:0c9148ab8585 | 60 | const double kpA1=0.19982, kdA1=0.91824, kiA1=0.00072609; |
Najib_irvani | 49:0c9148ab8585 | 61 | const double kpA2=0.20481, kdA2=0.92191, kiA2=0.00076326; |
Najib_irvani | 46:85169ae8659b | 62 | double a1,b1,c1; |
Najib_irvani | 46:85169ae8659b | 63 | double a2,b2,c2; |
Najib_irvani | 46:85169ae8659b | 64 | double current_error1, previous_error1_1 = 0, previous_error1_2 = 0; |
Najib_irvani | 46:85169ae8659b | 65 | double current_error2, previous_error2_1 = 0, previous_error2_2 = 0; |
Najib_irvani | 46:85169ae8659b | 66 | double previous_speed1 = 0; |
Najib_irvani | 46:85169ae8659b | 67 | double previous_speed2 = 0; |
Najib_irvani | 46:85169ae8659b | 68 | |
gustavaditya | 38:3ef6754bd8d8 | 69 | float rpm, rpm2; |
Najib_irvani | 50:8bc9dbca2ffa | 70 | double target_rpm = 17.0, target_rpm2 = 17.0; // selisih 4 bagus, sama bagus |
Najib_irvani | 46:85169ae8659b | 71 | const float maxRPM = 35, minRPM = 0; // Limit 25 atau 27 |
gustavaditya | 38:3ef6754bd8d8 | 72 | |
Najib_irvani | 44:452c214d9cf5 | 73 | const float pwmPowerUp = 1.0; |
Najib_irvani | 44:452c214d9cf5 | 74 | const float pwmPowerDown = -1.0; |
gustavaditya | 40:5b937cac959a | 75 | |
Najib_irvani | 46:85169ae8659b | 76 | double jarak_ping=0; |
Najib_irvani | 51:292c5807a93f | 77 | double ping_target = 17; |
Najib_irvani | 46:85169ae8659b | 78 | double ping_current_error, ping_previous_error1 = 0, ping_sum_error=0; |
Najib_irvani | 51:292c5807a93f | 79 | double ping_Kp = -0.3747, ping_Kd = -0.535, ping_Ts=10; |
Najib_irvani | 46:85169ae8659b | 80 | double ping_pwm, ping_previous_pwm = 0; |
Najib_irvani | 46:85169ae8659b | 81 | |
be_bryan | 26:256160a1a82d | 82 | // Variable Bawah |
Najib_irvani | 44:452c214d9cf5 | 83 | float PIVOT = 0.17; // PWM Pivot Kanan, Pivot Kiri |
Najib_irvani | 46:85169ae8659b | 84 | float tuneDpn = 1.0; // Tunning PWM motor Depan |
Najib_irvani | 46:85169ae8659b | 85 | float tuneBlk = 1.0; // Tunning PWM motor belakang |
gustavaditya | 45:964ae71a30e3 | 86 | float tuneAksel = 0.6; |
gustavaditya | 45:964ae71a30e3 | 87 | int aksel = 0; |
gustavaditya | 45:964ae71a30e3 | 88 | float tuneAkselBlk = 0.4; |
Najib_irvani | 46:85169ae8659b | 89 | float tuneR = 1.0; |
Najib_irvani | 46:85169ae8659b | 90 | float tuneL = 1.0; |
Najib_irvani | 44:452c214d9cf5 | 91 | float serong = 0.4; |
Najib_irvani | 47:6cac4f1a3c8e | 92 | float rasio = 1.4545; |
Najib_irvani | 47:6cac4f1a3c8e | 93 | float t_new = 0.1; |
Najib_irvani | 43:3807a95aa284 | 94 | |
Najib_irvani | 43:3807a95aa284 | 95 | /* variable tunning */ |
Najib_irvani | 43:3807a95aa284 | 96 | float tunning_L; |
Najib_irvani | 43:3807a95aa284 | 97 | float tunning_R; |
Najib_irvani | 43:3807a95aa284 | 98 | float tunning_Dpn; |
Najib_irvani | 43:3807a95aa284 | 99 | float tunning_Blk; |
gustavaditya | 31:d5cbda07fd95 | 100 | |
gustavaditya | 31:d5cbda07fd95 | 101 | /* Deklarasi Variable Millis */ |
gustavaditya | 33:69d266bc3fe9 | 102 | unsigned long int previousMillis = 0; // PID launcher |
gustavaditya | 31:d5cbda07fd95 | 103 | unsigned long int currentMillis; |
gustavaditya | 33:69d266bc3fe9 | 104 | unsigned long int previousMillis2 = 0; // PID launcher |
gustavaditya | 31:d5cbda07fd95 | 105 | unsigned long int currentMillis2; |
gustavaditya | 33:69d266bc3fe9 | 106 | unsigned long int previousMillis3 = 0; // Pneumatik |
gustavaditya | 40:5b937cac959a | 107 | unsigned long int previousMillis4 = 0; // Ping |
franshendri | 42:6caf8bd5abbc | 108 | unsigned long int previousMillis5 = 0; // Display |
Najib_irvani | 50:8bc9dbca2ffa | 109 | unsigned long int previousMillis6 = 0; // Display |
MarchioKevin | 22:4632f58461e0 | 110 | |
gustavaditya | 31:d5cbda07fd95 | 111 | /* Variabel Stick */ |
gustavaditya | 31:d5cbda07fd95 | 112 | //Logic untuk masuk aktuator |
gustavaditya | 31:d5cbda07fd95 | 113 | int case_joy; |
gustavaditya | 31:d5cbda07fd95 | 114 | bool isLauncher = false; |
gustavaditya | 31:d5cbda07fd95 | 115 | bool isReload = false; |
rizqicahyo | 36:5963c9a49485 | 116 | bool ReloadOn = false; |
gustavaditya | 31:d5cbda07fd95 | 117 | bool flag_Pneu = false; |
Najib_irvani | 47:6cac4f1a3c8e | 118 | bool flag_paku = false; |
Najib_irvani | 44:452c214d9cf5 | 119 | bool ready = false; |
gustavaditya | 31:d5cbda07fd95 | 120 | |
gustavaditya | 31:d5cbda07fd95 | 121 | /*****************************************************/ |
gustavaditya | 31:d5cbda07fd95 | 122 | /* Definisi Prosedur, Fungsi dan Setting Pinout */ |
gustavaditya | 31:d5cbda07fd95 | 123 | /*****************************************************/ |
gustavaditya | 31:d5cbda07fd95 | 124 | |
gustavaditya | 31:d5cbda07fd95 | 125 | /* Fungsi dan Procedur Encoder */ |
gustavaditya | 31:d5cbda07fd95 | 126 | void init_speed(); // |
gustavaditya | 31:d5cbda07fd95 | 127 | void aktuator(); // Pergerakan aktuator berdasarkan case joystick |
gustavaditya | 31:d5cbda07fd95 | 128 | int case_joystick(); // Mendapatkan case dari joystick |
gustavaditya | 33:69d266bc3fe9 | 129 | //void speedKalibrasiMotor(); // Pertambahan target RPM motor atas melalui joystick |
gustavaditya | 31:d5cbda07fd95 | 130 | |
gustavaditya | 31:d5cbda07fd95 | 131 | /* Inisialisasi Pin TX-RX Joystik dan PC */ |
gustavaditya | 31:d5cbda07fd95 | 132 | joysticknucleo joystick(PA_0,PA_1); |
gustavaditya | 31:d5cbda07fd95 | 133 | Serial pc(USBTX,USBRX); |
calmantara186 | 16:90119f03c5d1 | 134 | |
be_bryan | 26:256160a1a82d | 135 | /* Deklarasi Encoder Launcher */ |
Najib_irvani | 44:452c214d9cf5 | 136 | encoderKRAI encLauncherDpn( PC_10, PC_11, 28, encoderKRAI::X4_ENCODING); |
Najib_irvani | 44:452c214d9cf5 | 137 | encoderKRAI encLauncherBlk( PC_12, PD_2, 28, encoderKRAI::X4_ENCODING); |
be_bryan | 26:256160a1a82d | 138 | |
calmantara186 | 16:90119f03c5d1 | 139 | /* Deklarasi Motor Base */ |
Najib_irvani | 44:452c214d9cf5 | 140 | Motor motorDpn(PB_7, PC_3, PC_0); //(PB_9, PA_12, PC_5); |
Najib_irvani | 44:452c214d9cf5 | 141 | //Motor motorBlk(PB_6, PC_14, PC_13); //(PB_6, PB_1, PB_12); (PC_7, PC_14, PC_13); |
Najib_irvani | 44:452c214d9cf5 | 142 | Motor motorBlk(PB_2, PB_15, PB_1); |
Najib_irvani | 44:452c214d9cf5 | 143 | Motor motorL (PB_9, PA_12, PA_6); |
Najib_irvani | 46:85169ae8659b | 144 | Motor motorR (PB_8, PC_6, PC_5); //(PC_6, PB_4, PB_5); |
fanny868 | 0:9072e932503c | 145 | |
calmantara186 | 16:90119f03c5d1 | 146 | /* Deklarasi Motor Launcher */ |
Najib_irvani | 47:6cac4f1a3c8e | 147 | Motor launcherDpn(PA_5,PA_11,PB_12); // pwm ,fwd, rev |
Najib_irvani | 44:452c214d9cf5 | 148 | Motor launcherBlk(PB_3, PC_4, PA_10); // pwm, fwd, rev |
Najib_irvani | 44:452c214d9cf5 | 149 | Motor powerScrew(PB_10, PB_14, PB_13); // pwm, fwd, rev |
rahmadirizki18 | 5:3aa203218306 | 150 | |
be_bryan | 26:256160a1a82d | 151 | /* Deklarasi Penumatik Launcher */ |
Najib_irvani | 44:452c214d9cf5 | 152 | DigitalOut pneumatik(PA_4, PullUp); |
Najib_irvani | 47:6cac4f1a3c8e | 153 | DigitalOut pneu_paku(PC_2, PullUp); |
be_bryan | 26:256160a1a82d | 154 | |
be_bryan | 27:68efb1622985 | 155 | /*Dekalrasi Limit Switch */ |
gustavaditya | 40:5b937cac959a | 156 | //DigitalIn infraAtas(PC_9, PullUp); |
Najib_irvani | 44:452c214d9cf5 | 157 | DigitalIn limitTengah(PA_9, PullUp); |
Najib_irvani | 44:452c214d9cf5 | 158 | DigitalIn limitBawah(PC_7, PullUp); |
Najib_irvani | 44:452c214d9cf5 | 159 | DigitalIn limitBawah1(PA_7, PullUp); |
rahmadirizki18 | 5:3aa203218306 | 160 | |
gustavaditya | 40:5b937cac959a | 161 | /*deklarasi PING ultrasonic*/ |
Najib_irvani | 44:452c214d9cf5 | 162 | Ping pingAtas(PC_15); |
fanny868 | 0:9072e932503c | 163 | |
franshendri | 42:6caf8bd5abbc | 164 | /*Deklarasi Display*/ |
Najib_irvani | 44:452c214d9cf5 | 165 | DigitDisplay display (PA_8, PC_8); |
franshendri | 42:6caf8bd5abbc | 166 | |
MarchioKevin | 22:4632f58461e0 | 167 | /****************************************************/ |
MarchioKevin | 22:4632f58461e0 | 168 | /* Deklarasi Fungsi dan Procedure */ |
MarchioKevin | 22:4632f58461e0 | 169 | /****************************************************/ |
gustavaditya | 31:d5cbda07fd95 | 170 | int case_joystick() |
gustavaditya | 31:d5cbda07fd95 | 171 | { |
gustavaditya | 31:d5cbda07fd95 | 172 | //---------------------------------------------------// |
gustavaditya | 31:d5cbda07fd95 | 173 | // Gerak Motor Base // |
gustavaditya | 31:d5cbda07fd95 | 174 | // Case 1 : Pivot kanan // |
gustavaditya | 31:d5cbda07fd95 | 175 | // Case 2 : Pivot Kiri // |
gustavaditya | 31:d5cbda07fd95 | 176 | // Case 3 : Kanan // |
gustavaditya | 31:d5cbda07fd95 | 177 | // Case 4 : Kiri // |
gustavaditya | 31:d5cbda07fd95 | 178 | // Case 5 : Break // |
gustavaditya | 31:d5cbda07fd95 | 179 | //---------------------------------------------------// |
gustavaditya | 31:d5cbda07fd95 | 180 | |
gustavaditya | 31:d5cbda07fd95 | 181 | int caseJoystick; |
Najib_irvani | 43:3807a95aa284 | 182 | if ((joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
gustavaditya | 31:d5cbda07fd95 | 183 | // Pivot Kanan |
gustavaditya | 31:d5cbda07fd95 | 184 | caseJoystick = 1; |
gustavaditya | 31:d5cbda07fd95 | 185 | } |
Najib_irvani | 43:3807a95aa284 | 186 | else if ((!joystick.R1)&&(joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
gustavaditya | 31:d5cbda07fd95 | 187 | // Pivot Kiri |
gustavaditya | 31:d5cbda07fd95 | 188 | caseJoystick = 2; |
Najib_irvani | 43:3807a95aa284 | 189 | } |
Najib_irvani | 44:452c214d9cf5 | 190 | else if ((joystick.START_click)&&(!joystick.SELECT_click)&&(!joystick.R3_click)) { |
Najib_irvani | 44:452c214d9cf5 | 191 | // tambah rpm dengan nilai tertentu |
Najib_irvani | 44:452c214d9cf5 | 192 | caseJoystick = 31; |
Najib_irvani | 44:452c214d9cf5 | 193 | } |
Najib_irvani | 44:452c214d9cf5 | 194 | else if ((!joystick.START_click)&&(joystick.SELECT_click)&&(!joystick.R3_click)) { |
Najib_irvani | 44:452c214d9cf5 | 195 | // kurangi rpm dengan nilai tertentu |
Najib_irvani | 44:452c214d9cf5 | 196 | caseJoystick = 32; |
Najib_irvani | 44:452c214d9cf5 | 197 | } |
Najib_irvani | 44:452c214d9cf5 | 198 | else if ((!joystick.START_click)&&(!joystick.SELECT_click)&&(joystick.R3_click)) { |
Najib_irvani | 44:452c214d9cf5 | 199 | // kurangi rpm dengan nilai tertentu |
Najib_irvani | 44:452c214d9cf5 | 200 | caseJoystick = 33; |
Najib_irvani | 44:452c214d9cf5 | 201 | } |
Najib_irvani | 43:3807a95aa284 | 202 | else if ((joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 203 | // Kanan + Rotasi kanan |
Najib_irvani | 43:3807a95aa284 | 204 | caseJoystick = 17; |
Najib_irvani | 43:3807a95aa284 | 205 | } |
Najib_irvani | 43:3807a95aa284 | 206 | else if ((!joystick.R1)&&(joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 207 | // Kanan + Rotasi kiri |
Najib_irvani | 43:3807a95aa284 | 208 | caseJoystick = 18; |
Najib_irvani | 43:3807a95aa284 | 209 | } |
Najib_irvani | 43:3807a95aa284 | 210 | else if ((joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 211 | // Kiri + Rotasi kanan |
Najib_irvani | 43:3807a95aa284 | 212 | caseJoystick = 19; |
Najib_irvani | 43:3807a95aa284 | 213 | } |
Najib_irvani | 43:3807a95aa284 | 214 | else if ((!joystick.R1)&&(joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 215 | // Kanan + Rotasi kiri |
Najib_irvani | 43:3807a95aa284 | 216 | caseJoystick = 20; |
Najib_irvani | 43:3807a95aa284 | 217 | } |
Najib_irvani | 43:3807a95aa284 | 218 | else if ((joystick.R1)&&(!joystick.L1)&&(joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 219 | // Maju + Rotasi kanan |
Najib_irvani | 43:3807a95aa284 | 220 | caseJoystick = 21; |
Najib_irvani | 43:3807a95aa284 | 221 | } |
Najib_irvani | 43:3807a95aa284 | 222 | else if ((!joystick.R1)&&(joystick.L1)&&(joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 223 | // Maju + Rotasi kiri |
Najib_irvani | 43:3807a95aa284 | 224 | caseJoystick = 22; |
Najib_irvani | 43:3807a95aa284 | 225 | } |
Najib_irvani | 43:3807a95aa284 | 226 | else if ((joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 227 | // Mundur + Rotasi kanan |
Najib_irvani | 43:3807a95aa284 | 228 | caseJoystick = 23; |
Najib_irvani | 43:3807a95aa284 | 229 | } |
Najib_irvani | 43:3807a95aa284 | 230 | else if ((!joystick.R1)&&(joystick.L1)&&(!joystick.atas)&&(joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 231 | // Mundur + Rotasi kiri |
Najib_irvani | 43:3807a95aa284 | 232 | caseJoystick = 24; |
Najib_irvani | 43:3807a95aa284 | 233 | } |
Najib_irvani | 43:3807a95aa284 | 234 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)&&(joystick.segitiga_click)) { |
Najib_irvani | 43:3807a95aa284 | 235 | // Kanan + segitiga |
Najib_irvani | 43:3807a95aa284 | 236 | caseJoystick = 25; |
Najib_irvani | 43:3807a95aa284 | 237 | } |
Najib_irvani | 43:3807a95aa284 | 238 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)&&(joystick.segitiga_click)) { |
Najib_irvani | 43:3807a95aa284 | 239 | // Kiri + segitiga |
Najib_irvani | 43:3807a95aa284 | 240 | caseJoystick = 26; |
Najib_irvani | 43:3807a95aa284 | 241 | } |
Najib_irvani | 43:3807a95aa284 | 242 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)&&(joystick.lingkaran_click)) { |
Najib_irvani | 43:3807a95aa284 | 243 | // Kanan + lingkaran |
Najib_irvani | 43:3807a95aa284 | 244 | caseJoystick = 27; |
Najib_irvani | 43:3807a95aa284 | 245 | } |
Najib_irvani | 43:3807a95aa284 | 246 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)&&(joystick.lingkaran_click)) { |
Najib_irvani | 43:3807a95aa284 | 247 | // Kiri + lingkaran |
Najib_irvani | 43:3807a95aa284 | 248 | caseJoystick = 28; |
Najib_irvani | 43:3807a95aa284 | 249 | } |
Najib_irvani | 43:3807a95aa284 | 250 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)&&(joystick.kotak_click)) { |
Najib_irvani | 43:3807a95aa284 | 251 | // Kanan + kotak |
Najib_irvani | 43:3807a95aa284 | 252 | caseJoystick = 29; |
Najib_irvani | 43:3807a95aa284 | 253 | } |
Najib_irvani | 43:3807a95aa284 | 254 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)&&(joystick.kotak_click)) { |
Najib_irvani | 43:3807a95aa284 | 255 | // Kiri + kotak |
Najib_irvani | 43:3807a95aa284 | 256 | caseJoystick = 30; |
Najib_irvani | 43:3807a95aa284 | 257 | } |
Najib_irvani | 43:3807a95aa284 | 258 | else if ((!joystick.R1)&&(!joystick.L1)&&(joystick.atas)&&(!joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 259 | // Serong kanan maju |
Najib_irvani | 44:452c214d9cf5 | 260 | caseJoystick = 13; |
Najib_irvani | 43:3807a95aa284 | 261 | } |
Najib_irvani | 43:3807a95aa284 | 262 | else if ((!joystick.R1)&&(!joystick.L1)&&(joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 263 | // Serong kiri maju |
Najib_irvani | 44:452c214d9cf5 | 264 | caseJoystick = 14; |
Najib_irvani | 43:3807a95aa284 | 265 | } |
Najib_irvani | 43:3807a95aa284 | 266 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 267 | // Serong kanan mundur |
Najib_irvani | 44:452c214d9cf5 | 268 | caseJoystick = 15; |
Najib_irvani | 43:3807a95aa284 | 269 | } |
Najib_irvani | 43:3807a95aa284 | 270 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 271 | // Serong kiri mundur |
Najib_irvani | 44:452c214d9cf5 | 272 | caseJoystick = 16; |
gustavaditya | 31:d5cbda07fd95 | 273 | } |
gustavaditya | 31:d5cbda07fd95 | 274 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(joystick.kanan)&&(!joystick.kiri)) { |
gustavaditya | 31:d5cbda07fd95 | 275 | // Kanan |
gustavaditya | 31:d5cbda07fd95 | 276 | caseJoystick = 3; |
gustavaditya | 31:d5cbda07fd95 | 277 | } |
gustavaditya | 31:d5cbda07fd95 | 278 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(joystick.kiri)) { |
gustavaditya | 31:d5cbda07fd95 | 279 | // Kiri |
gustavaditya | 31:d5cbda07fd95 | 280 | caseJoystick = 4; |
Najib_irvani | 43:3807a95aa284 | 281 | } |
Najib_irvani | 43:3807a95aa284 | 282 | else if ((!joystick.R1)&&(!joystick.L1)&&(joystick.atas)&&(!joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 283 | // Atas -- Maju |
Najib_irvani | 44:452c214d9cf5 | 284 | caseJoystick = 8; |
Najib_irvani | 43:3807a95aa284 | 285 | } |
Najib_irvani | 43:3807a95aa284 | 286 | else if ((!joystick.R1)&&(!joystick.L1)&&(!joystick.atas)&&(joystick.bawah)&&(!joystick.kanan)&&(!joystick.kiri)) { |
Najib_irvani | 43:3807a95aa284 | 287 | // Bawah -- Mundur |
Najib_irvani | 44:452c214d9cf5 | 288 | caseJoystick = 9; |
gustavaditya | 31:d5cbda07fd95 | 289 | } |
gustavaditya | 38:3ef6754bd8d8 | 290 | else if (joystick.segitiga_click){ |
gustavaditya | 31:d5cbda07fd95 | 291 | // Motor Launcher |
gustavaditya | 31:d5cbda07fd95 | 292 | caseJoystick = 5; |
gustavaditya | 31:d5cbda07fd95 | 293 | } |
gustavaditya | 38:3ef6754bd8d8 | 294 | else if (joystick.R2_click){ |
gustavaditya | 31:d5cbda07fd95 | 295 | // Target Pulse PID ++ Motor Depan |
gustavaditya | 31:d5cbda07fd95 | 296 | caseJoystick = 6; |
gustavaditya | 31:d5cbda07fd95 | 297 | } |
gustavaditya | 38:3ef6754bd8d8 | 298 | else if (joystick.L2_click){ |
Najib_irvani | 43:3807a95aa284 | 299 | // Target Pulse PID -- Motor |
gustavaditya | 31:d5cbda07fd95 | 300 | caseJoystick = 7; |
gustavaditya | 31:d5cbda07fd95 | 301 | } |
gustavaditya | 31:d5cbda07fd95 | 302 | else if (joystick.silang_click){ |
gustavaditya | 31:d5cbda07fd95 | 303 | // Pnemuatik ON |
gustavaditya | 31:d5cbda07fd95 | 304 | caseJoystick = 10; |
gustavaditya | 31:d5cbda07fd95 | 305 | } |
Najib_irvani | 43:3807a95aa284 | 306 | else if ((joystick.lingkaran_click)&&(!joystick.kotak_click)) { |
gustavaditya | 31:d5cbda07fd95 | 307 | // Power Screw Up |
gustavaditya | 31:d5cbda07fd95 | 308 | caseJoystick = 11; |
gustavaditya | 31:d5cbda07fd95 | 309 | } |
Najib_irvani | 43:3807a95aa284 | 310 | else if ((joystick.kotak_click)&&(!joystick.lingkaran_click)) { |
gustavaditya | 31:d5cbda07fd95 | 311 | // Power Screw Down |
gustavaditya | 31:d5cbda07fd95 | 312 | caseJoystick = 12; |
gustavaditya | 31:d5cbda07fd95 | 313 | } |
Najib_irvani | 47:6cac4f1a3c8e | 314 | else if (joystick.L3){ |
Najib_irvani | 47:6cac4f1a3c8e | 315 | // Paku Bumi ON/OFF |
Najib_irvani | 47:6cac4f1a3c8e | 316 | caseJoystick = 34; |
Najib_irvani | 47:6cac4f1a3c8e | 317 | } |
gustavaditya | 45:964ae71a30e3 | 318 | else |
gustavaditya | 45:964ae71a30e3 | 319 | { |
gustavaditya | 45:964ae71a30e3 | 320 | tuneAksel = 0.6; |
gustavaditya | 45:964ae71a30e3 | 321 | aksel = 0; |
gustavaditya | 45:964ae71a30e3 | 322 | } |
gustavaditya | 31:d5cbda07fd95 | 323 | |
gustavaditya | 31:d5cbda07fd95 | 324 | return(caseJoystick); |
gustavaditya | 31:d5cbda07fd95 | 325 | } |
gustavaditya | 31:d5cbda07fd95 | 326 | |
fanny868 | 0:9072e932503c | 327 | |
gustavaditya | 37:67d54563af90 | 328 | void init_rpm (){ |
gustavaditya | 38:3ef6754bd8d8 | 329 | if (target_rpm>maxRPM-2){ |
gustavaditya | 38:3ef6754bd8d8 | 330 | target_rpm = maxRPM-2; |
gustavaditya | 37:67d54563af90 | 331 | } |
franshendri | 42:6caf8bd5abbc | 332 | if (target_rpm<minRPM){ |
gustavaditya | 37:67d54563af90 | 333 | target_rpm = minRPM; |
gustavaditya | 37:67d54563af90 | 334 | } |
gustavaditya | 37:67d54563af90 | 335 | if (target_rpm2>maxRPM){ |
gustavaditya | 37:67d54563af90 | 336 | target_rpm2 = maxRPM; |
gustavaditya | 37:67d54563af90 | 337 | } |
franshendri | 42:6caf8bd5abbc | 338 | if (target_rpm2<minRPM+2){ |
gustavaditya | 38:3ef6754bd8d8 | 339 | target_rpm2 = minRPM+2; |
gustavaditya | 37:67d54563af90 | 340 | } |
gustavaditya | 37:67d54563af90 | 341 | } |
gustavaditya | 37:67d54563af90 | 342 | |
gustavaditya | 31:d5cbda07fd95 | 343 | void aktuator() |
gustavaditya | 31:d5cbda07fd95 | 344 | { |
gustavaditya | 31:d5cbda07fd95 | 345 | switch (case_joy) { |
gustavaditya | 31:d5cbda07fd95 | 346 | case (1): |
gustavaditya | 31:d5cbda07fd95 | 347 | { |
gustavaditya | 31:d5cbda07fd95 | 348 | // Pivot Kanan |
gustavaditya | 31:d5cbda07fd95 | 349 | motorDpn.speed(-PIVOT); |
gustavaditya | 31:d5cbda07fd95 | 350 | motorBlk.speed(-PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 351 | motorR.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 352 | motorL.speed(-rasio*PIVOT-t_new); |
gustavaditya | 31:d5cbda07fd95 | 353 | break; |
gustavaditya | 31:d5cbda07fd95 | 354 | } |
gustavaditya | 31:d5cbda07fd95 | 355 | case (2): |
gustavaditya | 31:d5cbda07fd95 | 356 | { |
gustavaditya | 31:d5cbda07fd95 | 357 | // Pivot Kiri |
gustavaditya | 31:d5cbda07fd95 | 358 | motorDpn.speed(PIVOT); |
gustavaditya | 31:d5cbda07fd95 | 359 | motorBlk.speed(PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 360 | motorR.speed(rasio*PIVOT+t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 361 | motorL.speed(rasio*PIVOT+t_new); |
Najib_irvani | 43:3807a95aa284 | 362 | break; |
Najib_irvani | 43:3807a95aa284 | 363 | } |
Najib_irvani | 43:3807a95aa284 | 364 | case (17): |
Najib_irvani | 43:3807a95aa284 | 365 | { |
Najib_irvani | 43:3807a95aa284 | 366 | // Kanan + Rotasi Kanan |
Najib_irvani | 43:3807a95aa284 | 367 | motorDpn.speed(-PIVOT); |
Najib_irvani | 43:3807a95aa284 | 368 | motorBlk.speed(-PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 369 | motorR.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 370 | motorL.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 43:3807a95aa284 | 371 | break; |
Najib_irvani | 43:3807a95aa284 | 372 | } |
Najib_irvani | 43:3807a95aa284 | 373 | case (18): |
Najib_irvani | 43:3807a95aa284 | 374 | { |
Najib_irvani | 43:3807a95aa284 | 375 | // Kanan + Rotasi Kiri |
Najib_irvani | 43:3807a95aa284 | 376 | motorDpn.speed(PIVOT); |
Najib_irvani | 43:3807a95aa284 | 377 | motorBlk.speed(PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 378 | motorR.speed(rasio*PIVOT+t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 379 | motorL.speed(rasio*PIVOT+t_new); |
Najib_irvani | 43:3807a95aa284 | 380 | break; |
Najib_irvani | 43:3807a95aa284 | 381 | } |
Najib_irvani | 43:3807a95aa284 | 382 | case (19): |
Najib_irvani | 43:3807a95aa284 | 383 | { |
Najib_irvani | 43:3807a95aa284 | 384 | // Kiri + Rotasi Kanan |
Najib_irvani | 43:3807a95aa284 | 385 | motorDpn.speed(-PIVOT); |
Najib_irvani | 43:3807a95aa284 | 386 | motorBlk.speed(-PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 387 | motorR.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 388 | motorL.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 43:3807a95aa284 | 389 | break; |
Najib_irvani | 43:3807a95aa284 | 390 | } |
Najib_irvani | 43:3807a95aa284 | 391 | case (20): |
Najib_irvani | 43:3807a95aa284 | 392 | { |
Najib_irvani | 43:3807a95aa284 | 393 | // Kiri + Rotasi Kiri |
Najib_irvani | 43:3807a95aa284 | 394 | motorDpn.speed(PIVOT); |
Najib_irvani | 43:3807a95aa284 | 395 | motorBlk.speed(PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 396 | motorR.speed(rasio*PIVOT+t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 397 | motorL.speed(rasio*PIVOT+t_new); |
Najib_irvani | 43:3807a95aa284 | 398 | break; |
Najib_irvani | 43:3807a95aa284 | 399 | } |
Najib_irvani | 43:3807a95aa284 | 400 | case (21): |
Najib_irvani | 43:3807a95aa284 | 401 | { |
Najib_irvani | 43:3807a95aa284 | 402 | // Maju + Rotasi Kanan |
Najib_irvani | 43:3807a95aa284 | 403 | motorDpn.speed(-PIVOT); |
Najib_irvani | 43:3807a95aa284 | 404 | motorBlk.speed(-PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 405 | motorR.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 406 | motorL.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 43:3807a95aa284 | 407 | break; |
Najib_irvani | 43:3807a95aa284 | 408 | } |
Najib_irvani | 43:3807a95aa284 | 409 | case (22): |
Najib_irvani | 43:3807a95aa284 | 410 | { |
Najib_irvani | 43:3807a95aa284 | 411 | // Maju + Rotasi Kiri |
Najib_irvani | 43:3807a95aa284 | 412 | motorDpn.speed(PIVOT); |
Najib_irvani | 43:3807a95aa284 | 413 | motorBlk.speed(PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 414 | motorR.speed(rasio*PIVOT+t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 415 | motorL.speed(rasio*PIVOT+t_new); |
Najib_irvani | 43:3807a95aa284 | 416 | break; |
Najib_irvani | 43:3807a95aa284 | 417 | } |
Najib_irvani | 43:3807a95aa284 | 418 | case (23): |
Najib_irvani | 43:3807a95aa284 | 419 | { |
Najib_irvani | 43:3807a95aa284 | 420 | // Mundur + Rotasi Kanan |
Najib_irvani | 43:3807a95aa284 | 421 | motorDpn.speed(-PIVOT); |
Najib_irvani | 43:3807a95aa284 | 422 | motorBlk.speed(-PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 423 | motorR.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 424 | motorL.speed(-rasio*PIVOT-t_new); |
Najib_irvani | 43:3807a95aa284 | 425 | break; |
Najib_irvani | 43:3807a95aa284 | 426 | } |
Najib_irvani | 43:3807a95aa284 | 427 | case (24): |
Najib_irvani | 43:3807a95aa284 | 428 | { |
Najib_irvani | 43:3807a95aa284 | 429 | // Mundur + Rotasi Kiri |
Najib_irvani | 43:3807a95aa284 | 430 | motorDpn.speed(PIVOT); |
Najib_irvani | 43:3807a95aa284 | 431 | motorBlk.speed(PIVOT); |
Najib_irvani | 47:6cac4f1a3c8e | 432 | motorR.speed(rasio*PIVOT+t_new); |
Najib_irvani | 47:6cac4f1a3c8e | 433 | motorL.speed(rasio*PIVOT+t_new); |
Najib_irvani | 43:3807a95aa284 | 434 | break; |
Najib_irvani | 43:3807a95aa284 | 435 | } |
Najib_irvani | 43:3807a95aa284 | 436 | case (25): |
Najib_irvani | 43:3807a95aa284 | 437 | { |
Najib_irvani | 43:3807a95aa284 | 438 | // Kanan + segitiga |
Najib_irvani | 43:3807a95aa284 | 439 | isLauncher = !isLauncher; |
Najib_irvani | 43:3807a95aa284 | 440 | break; |
Najib_irvani | 43:3807a95aa284 | 441 | } |
Najib_irvani | 43:3807a95aa284 | 442 | case (26): |
Najib_irvani | 43:3807a95aa284 | 443 | { |
Najib_irvani | 43:3807a95aa284 | 444 | // Kiri + segitiga |
Najib_irvani | 43:3807a95aa284 | 445 | isLauncher = !isLauncher; |
Najib_irvani | 43:3807a95aa284 | 446 | break; |
Najib_irvani | 43:3807a95aa284 | 447 | } |
Najib_irvani | 43:3807a95aa284 | 448 | case (27): |
Najib_irvani | 43:3807a95aa284 | 449 | { |
Najib_irvani | 43:3807a95aa284 | 450 | // Kanan + lingkaran |
Najib_irvani | 43:3807a95aa284 | 451 | ReloadOn = !ReloadOn; |
Najib_irvani | 43:3807a95aa284 | 452 | isReload = false; |
Najib_irvani | 43:3807a95aa284 | 453 | break; |
Najib_irvani | 43:3807a95aa284 | 454 | } |
Najib_irvani | 43:3807a95aa284 | 455 | case (28): |
Najib_irvani | 43:3807a95aa284 | 456 | { |
Najib_irvani | 43:3807a95aa284 | 457 | // Kiri + lingkaran |
Najib_irvani | 43:3807a95aa284 | 458 | ReloadOn = !ReloadOn; |
Najib_irvani | 43:3807a95aa284 | 459 | isReload = false; |
Najib_irvani | 43:3807a95aa284 | 460 | break; |
Najib_irvani | 43:3807a95aa284 | 461 | } |
Najib_irvani | 43:3807a95aa284 | 462 | case (29): |
Najib_irvani | 43:3807a95aa284 | 463 | { |
Najib_irvani | 43:3807a95aa284 | 464 | // Kanan + kotak |
Najib_irvani | 43:3807a95aa284 | 465 | ReloadOn = !ReloadOn; |
Najib_irvani | 43:3807a95aa284 | 466 | isReload = true; |
Najib_irvani | 43:3807a95aa284 | 467 | break; |
Najib_irvani | 43:3807a95aa284 | 468 | } |
Najib_irvani | 43:3807a95aa284 | 469 | case (30): |
Najib_irvani | 43:3807a95aa284 | 470 | { |
Najib_irvani | 43:3807a95aa284 | 471 | // Kiri + kotak |
Najib_irvani | 43:3807a95aa284 | 472 | ReloadOn = !ReloadOn; |
Najib_irvani | 43:3807a95aa284 | 473 | isReload = true; |
Najib_irvani | 43:3807a95aa284 | 474 | break; |
Najib_irvani | 43:3807a95aa284 | 475 | } |
Najib_irvani | 43:3807a95aa284 | 476 | case (13) : |
Najib_irvani | 43:3807a95aa284 | 477 | { |
Najib_irvani | 43:3807a95aa284 | 478 | // Serong kanan maju |
Najib_irvani | 43:3807a95aa284 | 479 | motorDpn.speed(-serong); |
Najib_irvani | 46:85169ae8659b | 480 | motorL.speed(-serong-t_new); |
Najib_irvani | 43:3807a95aa284 | 481 | motorBlk.speed(serong); |
Najib_irvani | 46:85169ae8659b | 482 | motorR.speed(serong+t_new); |
Najib_irvani | 43:3807a95aa284 | 483 | break; |
Najib_irvani | 43:3807a95aa284 | 484 | } |
Najib_irvani | 43:3807a95aa284 | 485 | case (14) : |
Najib_irvani | 43:3807a95aa284 | 486 | { |
Najib_irvani | 43:3807a95aa284 | 487 | // Serong kiri maju |
Najib_irvani | 43:3807a95aa284 | 488 | motorDpn.speed(serong); |
Najib_irvani | 46:85169ae8659b | 489 | motorR.speed(serong+t_new); |
Najib_irvani | 43:3807a95aa284 | 490 | motorBlk.speed(-serong); |
Najib_irvani | 46:85169ae8659b | 491 | motorL.speed(-serong-t_new); |
Najib_irvani | 43:3807a95aa284 | 492 | break; |
Najib_irvani | 43:3807a95aa284 | 493 | } |
Najib_irvani | 43:3807a95aa284 | 494 | case (15) : |
Najib_irvani | 43:3807a95aa284 | 495 | { |
Najib_irvani | 43:3807a95aa284 | 496 | // Serong kanan mundur |
Najib_irvani | 44:452c214d9cf5 | 497 | motorDpn.speed(-serong); |
Najib_irvani | 46:85169ae8659b | 498 | motorR.speed(-serong-t_new); |
Najib_irvani | 43:3807a95aa284 | 499 | motorBlk.speed(serong); |
Najib_irvani | 46:85169ae8659b | 500 | motorL.speed(serong+t_new); |
Najib_irvani | 43:3807a95aa284 | 501 | break; |
Najib_irvani | 43:3807a95aa284 | 502 | } |
Najib_irvani | 43:3807a95aa284 | 503 | case (16) : |
Najib_irvani | 43:3807a95aa284 | 504 | { |
Najib_irvani | 43:3807a95aa284 | 505 | // Serong kiri mundur |
Najib_irvani | 43:3807a95aa284 | 506 | motorDpn.speed(serong); |
Najib_irvani | 46:85169ae8659b | 507 | motorL.speed(serong+t_new); |
Najib_irvani | 43:3807a95aa284 | 508 | motorBlk.speed(-serong); |
Najib_irvani | 46:85169ae8659b | 509 | motorR.speed(-serong-t_new); |
gustavaditya | 31:d5cbda07fd95 | 510 | break; |
gustavaditya | 31:d5cbda07fd95 | 511 | } |
gustavaditya | 31:d5cbda07fd95 | 512 | case (3) : |
gustavaditya | 31:d5cbda07fd95 | 513 | { |
gustavaditya | 31:d5cbda07fd95 | 514 | // Kanan |
gustavaditya | 45:964ae71a30e3 | 515 | aksel++; |
gustavaditya | 45:964ae71a30e3 | 516 | if (aksel>300) |
gustavaditya | 45:964ae71a30e3 | 517 | tuneAksel = 0.9; |
gustavaditya | 45:964ae71a30e3 | 518 | |
gustavaditya | 45:964ae71a30e3 | 519 | motorDpn.speed(-tuneAksel); |
gustavaditya | 45:964ae71a30e3 | 520 | motorBlk.speed(tuneAksel); |
Najib_irvani | 43:3807a95aa284 | 521 | motorR.brake(1); |
Najib_irvani | 43:3807a95aa284 | 522 | motorL.brake(1); |
gustavaditya | 31:d5cbda07fd95 | 523 | break; |
gustavaditya | 31:d5cbda07fd95 | 524 | } |
gustavaditya | 31:d5cbda07fd95 | 525 | case (4) : |
gustavaditya | 31:d5cbda07fd95 | 526 | { |
gustavaditya | 31:d5cbda07fd95 | 527 | // Kiri |
gustavaditya | 45:964ae71a30e3 | 528 | aksel++; |
gustavaditya | 45:964ae71a30e3 | 529 | if (aksel>300) |
gustavaditya | 45:964ae71a30e3 | 530 | tuneAksel = 0.9; |
gustavaditya | 45:964ae71a30e3 | 531 | |
gustavaditya | 45:964ae71a30e3 | 532 | motorDpn.speed(tuneAksel); |
gustavaditya | 45:964ae71a30e3 | 533 | motorBlk.speed(-tuneAksel); |
Najib_irvani | 43:3807a95aa284 | 534 | motorR.brake(1); |
Najib_irvani | 43:3807a95aa284 | 535 | motorL.brake(1); |
Najib_irvani | 43:3807a95aa284 | 536 | break; |
Najib_irvani | 43:3807a95aa284 | 537 | } |
Najib_irvani | 43:3807a95aa284 | 538 | case (8) : |
Najib_irvani | 43:3807a95aa284 | 539 | { |
Najib_irvani | 43:3807a95aa284 | 540 | // Maju |
gustavaditya | 45:964ae71a30e3 | 541 | aksel++; |
gustavaditya | 45:964ae71a30e3 | 542 | if (aksel>300) |
gustavaditya | 45:964ae71a30e3 | 543 | tuneAksel = 0.9; |
gustavaditya | 45:964ae71a30e3 | 544 | |
Najib_irvani | 47:6cac4f1a3c8e | 545 | motorR.speed(tuneAksel); |
Najib_irvani | 47:6cac4f1a3c8e | 546 | motorL.speed(-tuneAksel); |
Najib_irvani | 43:3807a95aa284 | 547 | motorDpn.brake(1); |
Najib_irvani | 43:3807a95aa284 | 548 | motorBlk.brake(1); |
Najib_irvani | 43:3807a95aa284 | 549 | break; |
Najib_irvani | 43:3807a95aa284 | 550 | } |
Najib_irvani | 43:3807a95aa284 | 551 | case (9) : |
Najib_irvani | 43:3807a95aa284 | 552 | { |
Najib_irvani | 43:3807a95aa284 | 553 | // Mundur |
gustavaditya | 45:964ae71a30e3 | 554 | aksel++; |
gustavaditya | 45:964ae71a30e3 | 555 | if (aksel>300) |
gustavaditya | 45:964ae71a30e3 | 556 | tuneAksel = 0.9; |
gustavaditya | 45:964ae71a30e3 | 557 | |
Najib_irvani | 47:6cac4f1a3c8e | 558 | motorR.speed(-tuneAksel); |
Najib_irvani | 47:6cac4f1a3c8e | 559 | motorL.speed(tuneAksel); |
Najib_irvani | 43:3807a95aa284 | 560 | motorDpn.brake(1); |
Najib_irvani | 43:3807a95aa284 | 561 | motorBlk.brake(1); |
gustavaditya | 31:d5cbda07fd95 | 562 | break; |
gustavaditya | 31:d5cbda07fd95 | 563 | } |
gustavaditya | 31:d5cbda07fd95 | 564 | case (5) : |
gustavaditya | 31:d5cbda07fd95 | 565 | { |
gustavaditya | 31:d5cbda07fd95 | 566 | // Aktifkan motor atas |
gustavaditya | 31:d5cbda07fd95 | 567 | isLauncher = !isLauncher; |
gustavaditya | 31:d5cbda07fd95 | 568 | break; |
Joshua23 | 8:0711dea61312 | 569 | } |
gustavaditya | 31:d5cbda07fd95 | 570 | case (6) : |
gustavaditya | 31:d5cbda07fd95 | 571 | { |
gustavaditya | 31:d5cbda07fd95 | 572 | // Target Pulse PID ++ Motor Depan |
gustavaditya | 39:11358f3f61ff | 573 | target_rpm2 = target_rpm2+1.0; |
gustavaditya | 39:11358f3f61ff | 574 | target_rpm = target_rpm+1.0; |
gustavaditya | 37:67d54563af90 | 575 | init_rpm(); |
gustavaditya | 31:d5cbda07fd95 | 576 | break; |
gustavaditya | 31:d5cbda07fd95 | 577 | } |
gustavaditya | 31:d5cbda07fd95 | 578 | case (7) : |
gustavaditya | 31:d5cbda07fd95 | 579 | { |
gustavaditya | 31:d5cbda07fd95 | 580 | // Target Pulse PID -- Motor Depan |
gustavaditya | 39:11358f3f61ff | 581 | target_rpm2 = target_rpm2-1.0; |
gustavaditya | 39:11358f3f61ff | 582 | target_rpm = target_rpm-1.0; |
gustavaditya | 37:67d54563af90 | 583 | init_rpm(); |
gustavaditya | 31:d5cbda07fd95 | 584 | break; |
gustavaditya | 31:d5cbda07fd95 | 585 | } |
gustavaditya | 31:d5cbda07fd95 | 586 | case (10) : |
gustavaditya | 31:d5cbda07fd95 | 587 | { |
gustavaditya | 31:d5cbda07fd95 | 588 | // Pneumatik |
Najib_irvani | 44:452c214d9cf5 | 589 | if (ready) |
Najib_irvani | 44:452c214d9cf5 | 590 | { |
Najib_irvani | 44:452c214d9cf5 | 591 | pneumatik = 0; |
Najib_irvani | 44:452c214d9cf5 | 592 | previousMillis3 = millis(); |
Najib_irvani | 44:452c214d9cf5 | 593 | flag_Pneu = true; |
Najib_irvani | 44:452c214d9cf5 | 594 | ready = false; |
Najib_irvani | 50:8bc9dbca2ffa | 595 | //ReloadOn = !ReloadOn; |
Najib_irvani | 50:8bc9dbca2ffa | 596 | //previousMillis6 = millis(); |
gustavaditya | 45:964ae71a30e3 | 597 | |
Najib_irvani | 44:452c214d9cf5 | 598 | } |
gustavaditya | 31:d5cbda07fd95 | 599 | break; |
gustavaditya | 31:d5cbda07fd95 | 600 | } |
gustavaditya | 31:d5cbda07fd95 | 601 | case (11) : |
gustavaditya | 31:d5cbda07fd95 | 602 | { |
gustavaditya | 31:d5cbda07fd95 | 603 | // Power Screw Up |
gustavaditya | 40:5b937cac959a | 604 | ReloadOn = !ReloadOn; |
Najib_irvani | 43:3807a95aa284 | 605 | isReload = false; |
gustavaditya | 31:d5cbda07fd95 | 606 | break; |
gustavaditya | 31:d5cbda07fd95 | 607 | } |
Najib_irvani | 44:452c214d9cf5 | 608 | case (31) : |
Najib_irvani | 44:452c214d9cf5 | 609 | { |
Najib_irvani | 44:452c214d9cf5 | 610 | // start |
Najib_irvani | 50:8bc9dbca2ffa | 611 | target_rpm2 = 24; |
Najib_irvani | 50:8bc9dbca2ffa | 612 | target_rpm = 24; |
Najib_irvani | 44:452c214d9cf5 | 613 | init_rpm(); |
Najib_irvani | 44:452c214d9cf5 | 614 | break; |
Najib_irvani | 44:452c214d9cf5 | 615 | } |
Najib_irvani | 44:452c214d9cf5 | 616 | case (32) : |
Najib_irvani | 44:452c214d9cf5 | 617 | { |
Najib_irvani | 44:452c214d9cf5 | 618 | // select |
Najib_irvani | 46:85169ae8659b | 619 | target_rpm2 = 11; |
Najib_irvani | 46:85169ae8659b | 620 | target_rpm = 11; |
Najib_irvani | 44:452c214d9cf5 | 621 | init_rpm(); |
Najib_irvani | 44:452c214d9cf5 | 622 | break; |
Najib_irvani | 44:452c214d9cf5 | 623 | } |
Najib_irvani | 44:452c214d9cf5 | 624 | case (33) : |
Najib_irvani | 44:452c214d9cf5 | 625 | { |
Najib_irvani | 44:452c214d9cf5 | 626 | // R3 |
Najib_irvani | 50:8bc9dbca2ffa | 627 | target_rpm2 = 17; |
Najib_irvani | 50:8bc9dbca2ffa | 628 | target_rpm = 17; |
Najib_irvani | 44:452c214d9cf5 | 629 | init_rpm(); |
Najib_irvani | 44:452c214d9cf5 | 630 | break; |
Najib_irvani | 44:452c214d9cf5 | 631 | } |
gustavaditya | 31:d5cbda07fd95 | 632 | case (12) : |
gustavaditya | 31:d5cbda07fd95 | 633 | { |
gustavaditya | 31:d5cbda07fd95 | 634 | // Power Screw Down |
Najib_irvani | 43:3807a95aa284 | 635 | ReloadOn = !ReloadOn; |
Najib_irvani | 43:3807a95aa284 | 636 | isReload = true; |
gustavaditya | 31:d5cbda07fd95 | 637 | break; |
gustavaditya | 31:d5cbda07fd95 | 638 | } |
Najib_irvani | 47:6cac4f1a3c8e | 639 | case (34) :{ |
Najib_irvani | 47:6cac4f1a3c8e | 640 | pneu_paku = !pneu_paku; |
Najib_irvani | 47:6cac4f1a3c8e | 641 | wait_ms(50); |
Najib_irvani | 47:6cac4f1a3c8e | 642 | if (pneu_paku == 1){ |
Najib_irvani | 47:6cac4f1a3c8e | 643 | PIVOT = 0.17; |
Najib_irvani | 47:6cac4f1a3c8e | 644 | }else{ |
Najib_irvani | 47:6cac4f1a3c8e | 645 | PIVOT = 0.8; |
Najib_irvani | 47:6cac4f1a3c8e | 646 | } |
Najib_irvani | 47:6cac4f1a3c8e | 647 | } |
gustavaditya | 31:d5cbda07fd95 | 648 | default : |
gustavaditya | 31:d5cbda07fd95 | 649 | { |
gustavaditya | 45:964ae71a30e3 | 650 | tuneAksel = 0.6; |
gustavaditya | 45:964ae71a30e3 | 651 | aksel = 0; |
gustavaditya | 31:d5cbda07fd95 | 652 | motorDpn.brake(1); |
gustavaditya | 31:d5cbda07fd95 | 653 | motorBlk.brake(1); |
Najib_irvani | 43:3807a95aa284 | 654 | motorR.brake(1); |
Najib_irvani | 43:3807a95aa284 | 655 | motorL.brake(1); |
gustavaditya | 31:d5cbda07fd95 | 656 | } |
gustavaditya | 31:d5cbda07fd95 | 657 | } // End Switch |
gustavaditya | 31:d5cbda07fd95 | 658 | } |
gustavaditya | 31:d5cbda07fd95 | 659 | |
gustavaditya | 40:5b937cac959a | 660 | void reloader() |
rizqicahyo | 36:5963c9a49485 | 661 | { |
rizqicahyo | 36:5963c9a49485 | 662 | if(ReloadOn){ |
rizqicahyo | 36:5963c9a49485 | 663 | if(isReload){ |
rizqicahyo | 36:5963c9a49485 | 664 | powerScrew.speed(pwmPowerDown); |
Najib_irvani | 47:6cac4f1a3c8e | 665 | pc.printf("%.2f\n", jarak_ping); |
Najib_irvani | 44:452c214d9cf5 | 666 | if((!limitBawah)||(!limitBawah1)){ |
rizqicahyo | 36:5963c9a49485 | 667 | isReload = false; |
rizqicahyo | 36:5963c9a49485 | 668 | ReloadOn = false; |
rizqicahyo | 36:5963c9a49485 | 669 | } |
rizqicahyo | 36:5963c9a49485 | 670 | } |
rizqicahyo | 36:5963c9a49485 | 671 | else if(!limitTengah){ |
rizqicahyo | 36:5963c9a49485 | 672 | isReload = true; |
rizqicahyo | 36:5963c9a49485 | 673 | } |
Najib_irvani | 46:85169ae8659b | 674 | else if(!flag_Pneu){ |
Najib_irvani | 46:85169ae8659b | 675 | //pc.printf("%.2f\n", ping_pwm); |
Najib_irvani | 46:85169ae8659b | 676 | ping_current_error = (double) (ping_target-jarak_ping); |
Najib_irvani | 46:85169ae8659b | 677 | |
Najib_irvani | 46:85169ae8659b | 678 | ping_sum_error += ping_current_error*ping_Ts; |
Najib_irvani | 50:8bc9dbca2ffa | 679 | ping_pwm = (double) ping_Kp*ping_current_error + ping_Kd*(ping_current_error-ping_previous_error1)/ping_Ts; |
Najib_irvani | 46:85169ae8659b | 680 | |
Najib_irvani | 51:292c5807a93f | 681 | if ((ping_pwm<0.7) && (ping_pwm>0.0)) ping_pwm = 0.7; |
Najib_irvani | 51:292c5807a93f | 682 | if ((ping_pwm>-0.5) && (ping_pwm<0.0)) ping_pwm = -0.5; |
Najib_irvani | 51:292c5807a93f | 683 | if (ping_pwm>1) ping_pwm=1; |
Najib_irvani | 51:292c5807a93f | 684 | if (ping_pwm<-1) ping_pwm=-1; |
Najib_irvani | 47:6cac4f1a3c8e | 685 | pc.printf("%.2f\n", jarak_ping); |
Najib_irvani | 46:85169ae8659b | 686 | powerScrew.speed(ping_pwm); |
Najib_irvani | 46:85169ae8659b | 687 | |
Najib_irvani | 46:85169ae8659b | 688 | ping_previous_error1 = ping_current_error; |
gustavaditya | 40:5b937cac959a | 689 | } |
Najib_irvani | 47:6cac4f1a3c8e | 690 | if ((jarak_ping>(ping_target-2))&&(jarak_ping<(ping_target+2))){ |
Najib_irvani | 46:85169ae8659b | 691 | ready = true; |
Najib_irvani | 46:85169ae8659b | 692 | }else{ |
Najib_irvani | 44:452c214d9cf5 | 693 | ready = false; |
rizqicahyo | 36:5963c9a49485 | 694 | } |
rizqicahyo | 36:5963c9a49485 | 695 | } |
rizqicahyo | 36:5963c9a49485 | 696 | else{ |
rizqicahyo | 36:5963c9a49485 | 697 | powerScrew.brake(1); |
rizqicahyo | 36:5963c9a49485 | 698 | } |
gustavaditya | 40:5b937cac959a | 699 | } |
rizqicahyo | 36:5963c9a49485 | 700 | |
rizqicahyo | 36:5963c9a49485 | 701 | |
gustavaditya | 31:d5cbda07fd95 | 702 | void launcher() |
gustavaditya | 31:d5cbda07fd95 | 703 | { |
gustavaditya | 31:d5cbda07fd95 | 704 | if (isLauncher) |
Sufa | 30:d69cc27ac644 | 705 | { |
be_bryan | 28:2d0746dc2d7d | 706 | currentMillis = millis(); |
be_bryan | 28:2d0746dc2d7d | 707 | currentMillis2 = millis(); |
be_bryan | 28:2d0746dc2d7d | 708 | |
Najib_irvani | 46:85169ae8659b | 709 | // PID Launcher Belakang |
Najib_irvani | 46:85169ae8659b | 710 | if (currentMillis-previousMillis>=Ts) |
be_bryan | 26:256160a1a82d | 711 | { |
gustavaditya | 31:d5cbda07fd95 | 712 | rpm = (float)encLauncherBlk.getPulses(); |
Najib_irvani | 46:85169ae8659b | 713 | current_error1 = target_rpm - rpm; |
Najib_irvani | 46:85169ae8659b | 714 | a1 = kpA1 + kiA1*Ts/2 + kdA1/Ts; |
Najib_irvani | 46:85169ae8659b | 715 | b1 = -kpA1 + kiA1*Ts/2 - 2*kdA1/Ts; |
Najib_irvani | 46:85169ae8659b | 716 | c1 = kdA1/Ts; |
Najib_irvani | 46:85169ae8659b | 717 | speed = previous_speed1 + a1*current_error1 + b1*previous_error1_1 + c1*previous_error1_2; |
gustavaditya | 38:3ef6754bd8d8 | 718 | //init_speed(); |
gustavaditya | 38:3ef6754bd8d8 | 719 | if(speed > maxSpeed){ |
gustavaditya | 38:3ef6754bd8d8 | 720 | launcherBlk.speed(maxSpeed); |
gustavaditya | 38:3ef6754bd8d8 | 721 | } |
gustavaditya | 39:11358f3f61ff | 722 | else if ( speed < minSpeed){ |
gustavaditya | 39:11358f3f61ff | 723 | launcherBlk.speed(minSpeed); |
gustavaditya | 39:11358f3f61ff | 724 | } |
gustavaditya | 38:3ef6754bd8d8 | 725 | else { |
gustavaditya | 38:3ef6754bd8d8 | 726 | launcherBlk.speed(speed); |
gustavaditya | 38:3ef6754bd8d8 | 727 | } |
Najib_irvani | 46:85169ae8659b | 728 | previous_speed1 = speed; |
Najib_irvani | 46:85169ae8659b | 729 | previous_error1_2 = previous_error1_1; |
Najib_irvani | 46:85169ae8659b | 730 | previous_error1_1 = current_error1; |
gustavaditya | 31:d5cbda07fd95 | 731 | encLauncherBlk.reset(); |
be_bryan | 26:256160a1a82d | 732 | previousMillis = currentMillis; |
Najib_irvani | 46:85169ae8659b | 733 | |
be_bryan | 26:256160a1a82d | 734 | } |
Najib_irvani | 46:85169ae8659b | 735 | // PID Launcher Depan |
Najib_irvani | 46:85169ae8659b | 736 | if (currentMillis2-previousMillis2>=Ts) |
be_bryan | 27:68efb1622985 | 737 | { |
gustavaditya | 31:d5cbda07fd95 | 738 | rpm2 = (float)encLauncherDpn.getPulses(); |
be_bryan | 27:68efb1622985 | 739 | current_error2 = target_rpm2 - rpm2; |
Najib_irvani | 46:85169ae8659b | 740 | a2 = kpA2 + kiA2*Ts/2 + kdA2/Ts; |
Najib_irvani | 46:85169ae8659b | 741 | b2 = -kpA2 + kiA2*Ts/2 - 2*kdA2/Ts; |
Najib_irvani | 46:85169ae8659b | 742 | c2 = kdA2/Ts; |
Najib_irvani | 46:85169ae8659b | 743 | speed2 = previous_speed2 + a2*current_error2 + b2*previous_error2_1 + c2*previous_error2_2; |
gustavaditya | 38:3ef6754bd8d8 | 744 | //init_speed(); |
gustavaditya | 38:3ef6754bd8d8 | 745 | if (speed2 > maxSpeed){ |
gustavaditya | 38:3ef6754bd8d8 | 746 | launcherDpn.speed(maxSpeed); |
gustavaditya | 38:3ef6754bd8d8 | 747 | } |
Najib_irvani | 46:85169ae8659b | 748 | else if ( speed2 < minSpeed){ |
gustavaditya | 39:11358f3f61ff | 749 | launcherDpn.speed(minSpeed); |
gustavaditya | 39:11358f3f61ff | 750 | } |
gustavaditya | 38:3ef6754bd8d8 | 751 | else{ |
gustavaditya | 38:3ef6754bd8d8 | 752 | launcherDpn.speed(speed2); |
gustavaditya | 38:3ef6754bd8d8 | 753 | } |
Najib_irvani | 46:85169ae8659b | 754 | previous_speed2 = speed2; |
Najib_irvani | 46:85169ae8659b | 755 | previous_error2_2 = previous_error2_1; |
Najib_irvani | 46:85169ae8659b | 756 | previous_error2_1 = current_error2; |
gustavaditya | 31:d5cbda07fd95 | 757 | encLauncherDpn.reset(); |
be_bryan | 27:68efb1622985 | 758 | previousMillis2 = currentMillis2; |
be_bryan | 27:68efb1622985 | 759 | } |
Najib_irvani | 47:6cac4f1a3c8e | 760 | //pc.printf("%.2f\t%.2f\n",rpm,rpm2); |
rahmadirizki18 | 6:68293bed71ea | 761 | } |
Sufa | 29:7b372b0aaa61 | 762 | else |
Sufa | 29:7b372b0aaa61 | 763 | { |
gustavaditya | 31:d5cbda07fd95 | 764 | launcherDpn.brake(1); |
gustavaditya | 31:d5cbda07fd95 | 765 | launcherBlk.brake(1); |
Najib_irvani | 46:85169ae8659b | 766 | |
Najib_irvani | 46:85169ae8659b | 767 | previous_error1_1 = 0; |
Najib_irvani | 46:85169ae8659b | 768 | previous_error1_2 = 0; |
Najib_irvani | 46:85169ae8659b | 769 | previous_error2_1 = 0; |
Najib_irvani | 46:85169ae8659b | 770 | previous_error2_2 = 0; |
Najib_irvani | 46:85169ae8659b | 771 | previous_speed1 = 0; |
Najib_irvani | 46:85169ae8659b | 772 | previous_speed2 = 0; |
gustavaditya | 31:d5cbda07fd95 | 773 | } |
rahmadirizki18 | 5:3aa203218306 | 774 | } |
gustavaditya | 31:d5cbda07fd95 | 775 | |
MarchioKevin | 22:4632f58461e0 | 776 | /*********************************************************/ |
MarchioKevin | 22:4632f58461e0 | 777 | /* Main Function */ |
MarchioKevin | 22:4632f58461e0 | 778 | /*********************************************************/ |
calmantara186 | 16:90119f03c5d1 | 779 | |
gustavaditya | 31:d5cbda07fd95 | 780 | int main (void) |
gustavaditya | 31:d5cbda07fd95 | 781 | { |
gustavaditya | 31:d5cbda07fd95 | 782 | // Set baud rate - 115200 |
fanny868 | 0:9072e932503c | 783 | joystick.setup(); |
rahmadirizki18 | 23:023b522977b2 | 784 | pc.baud(115200); |
rahmadirizki18 | 6:68293bed71ea | 785 | wait_ms(1000); |
gustavaditya | 40:5b937cac959a | 786 | |
gustavaditya | 40:5b937cac959a | 787 | // initializing encoder |
gustavaditya | 41:336a19289c2d | 788 | pneumatik =1; |
gustavaditya | 41:336a19289c2d | 789 | |
rahmadirizki18 | 5:3aa203218306 | 790 | wait_ms(500); |
gustavaditya | 40:5b937cac959a | 791 | |
gustavaditya | 40:5b937cac959a | 792 | //initializing PING |
gustavaditya | 40:5b937cac959a | 793 | pingAtas.Send(); |
gustavaditya | 40:5b937cac959a | 794 | |
rahmadirizki18 | 23:023b522977b2 | 795 | pc.printf("ready...."); |
gustavaditya | 35:69a47b4cb3fc | 796 | startMillis(); |
fanny868 | 0:9072e932503c | 797 | while(1) |
gustavaditya | 40:5b937cac959a | 798 | { |
gustavaditya | 40:5b937cac959a | 799 | // interupsi pembacaan PING setiap 30 ms |
Najib_irvani | 46:85169ae8659b | 800 | if(millis() - previousMillis4 >= 10){ //30 |
Najib_irvani | 46:85169ae8659b | 801 | jarak_ping = (float)pingAtas.Read_cm(); |
gustavaditya | 40:5b937cac959a | 802 | |
gustavaditya | 40:5b937cac959a | 803 | pingAtas.Send(); |
gustavaditya | 40:5b937cac959a | 804 | previousMillis4 = millis(); |
gustavaditya | 40:5b937cac959a | 805 | } |
gustavaditya | 40:5b937cac959a | 806 | |
fanny868 | 0:9072e932503c | 807 | // Interrupt Serial |
calmantara186 | 16:90119f03c5d1 | 808 | joystick.idle(); |
gustavaditya | 31:d5cbda07fd95 | 809 | if(joystick.readable()) |
gustavaditya | 31:d5cbda07fd95 | 810 | { |
fanny868 | 0:9072e932503c | 811 | // Panggil fungsi pembacaan joystik |
fanny868 | 0:9072e932503c | 812 | joystick.baca_data(); |
fanny868 | 0:9072e932503c | 813 | // Panggil fungsi pengolahan data joystik |
fanny868 | 0:9072e932503c | 814 | joystick.olah_data(); |
gustavaditya | 31:d5cbda07fd95 | 815 | // Masuk ke case joystick |
gustavaditya | 31:d5cbda07fd95 | 816 | case_joy = case_joystick(); |
Najib_irvani | 44:452c214d9cf5 | 817 | //pc.printf("%d\n",case_joy); |
rahmadirizki18 | 3:1287fccc11be | 818 | aktuator(); |
gustavaditya | 31:d5cbda07fd95 | 819 | launcher(); |
gustavaditya | 40:5b937cac959a | 820 | reloader(); |
Najib_irvani | 50:8bc9dbca2ffa | 821 | if ((millis()-previousMillis3 >= 230)&&(flag_Pneu)){ |
be_bryan | 26:256160a1a82d | 822 | pneumatik = 1; |
gustavaditya | 31:d5cbda07fd95 | 823 | flag_Pneu = false; |
be_bryan | 26:256160a1a82d | 824 | } |
be_bryan | 26:256160a1a82d | 825 | } |
gustavaditya | 31:d5cbda07fd95 | 826 | else |
gustavaditya | 31:d5cbda07fd95 | 827 | { |
gustavaditya | 31:d5cbda07fd95 | 828 | joystick.idle(); |
MarchioKevin | 21:da2f3d04468f | 829 | } |
franshendri | 42:6caf8bd5abbc | 830 | |
Najib_irvani | 44:452c214d9cf5 | 831 | if(millis() - previousMillis5 >= 400) |
Najib_irvani | 44:452c214d9cf5 | 832 | { |
Najib_irvani | 43:3807a95aa284 | 833 | display.write(0,((int) rpm2) / 10); |
Najib_irvani | 43:3807a95aa284 | 834 | display.write(1,((int)rpm2) % 10); |
franshendri | 42:6caf8bd5abbc | 835 | display.write(2, (int)target_rpm2 / 10); |
franshendri | 42:6caf8bd5abbc | 836 | display.write(3, (int)target_rpm2 % 10); |
franshendri | 42:6caf8bd5abbc | 837 | display.setColon(true); |
franshendri | 42:6caf8bd5abbc | 838 | |
franshendri | 42:6caf8bd5abbc | 839 | previousMillis5 = millis(); |
franshendri | 42:6caf8bd5abbc | 840 | } |
fanny868 | 0:9072e932503c | 841 | } |
be_bryan | 28:2d0746dc2d7d | 842 | } |