Tugas Magang-1

Dependencies:   mbed

Committer:
ferozfernando
Date:
Wed Mar 20 16:44:22 2019 +0000
Revision:
0:8e7dd2d20e4a
Tugas Magang KRTMI-1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ferozfernando 0:8e7dd2d20e4a 1 #include <iostream>
ferozfernando 0:8e7dd2d20e4a 2 #include "Motor.h"
ferozfernando 0:8e7dd2d20e4a 3 #include "mbed.h"
ferozfernando 0:8e7dd2d20e4a 4 #include "math.h"
ferozfernando 0:8e7dd2d20e4a 5
ferozfernando 0:8e7dd2d20e4a 6 bool loop = true;
ferozfernando 0:8e7dd2d20e4a 7
ferozfernando 0:8e7dd2d20e4a 8 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
ferozfernando 0:8e7dd2d20e4a 9 _pwm(pwm), _fwd(fwd), _rev(rev) {
ferozfernando 0:8e7dd2d20e4a 10
ferozfernando 0:8e7dd2d20e4a 11 // Set initial condition of PWM
ferozfernando 0:8e7dd2d20e4a 12 _pwm.period(0.002);
ferozfernando 0:8e7dd2d20e4a 13 _pwm = 0;
ferozfernando 0:8e7dd2d20e4a 14
ferozfernando 0:8e7dd2d20e4a 15 // Initial condition of output enables
ferozfernando 0:8e7dd2d20e4a 16 _fwd = 0;
ferozfernando 0:8e7dd2d20e4a 17 _rev = 0;
ferozfernando 0:8e7dd2d20e4a 18 }
ferozfernando 0:8e7dd2d20e4a 19
ferozfernando 0:8e7dd2d20e4a 20 void Motor::speed(float speed) {
ferozfernando 0:8e7dd2d20e4a 21 _fwd = (speed > (float)0.0);
ferozfernando 0:8e7dd2d20e4a 22 _rev = (speed < (float)0.0);
ferozfernando 0:8e7dd2d20e4a 23 _pwm = fabs(speed);
ferozfernando 0:8e7dd2d20e4a 24 }
ferozfernando 0:8e7dd2d20e4a 25
ferozfernando 0:8e7dd2d20e4a 26 void Motor::period(float period){
ferozfernando 0:8e7dd2d20e4a 27 _pwm.period(period);
ferozfernando 0:8e7dd2d20e4a 28 }
ferozfernando 0:8e7dd2d20e4a 29
ferozfernando 0:8e7dd2d20e4a 30 // Ilustrasi Kondisi Motor :
ferozfernando 0:8e7dd2d20e4a 31 /*
ferozfernando 0:8e7dd2d20e4a 32 +__________- -- > Motor 3
ferozfernando 0:8e7dd2d20e4a 33
ferozfernando 0:8e7dd2d20e4a 34
ferozfernando 0:8e7dd2d20e4a 35 - +
ferozfernando 0:8e7dd2d20e4a 36 \ /
ferozfernando 0:8e7dd2d20e4a 37 \ / --- > Kiri : Motor 1, Kanan : Motor 2
ferozfernando 0:8e7dd2d20e4a 38 \ /
ferozfernando 0:8e7dd2d20e4a 39 + -
ferozfernando 0:8e7dd2d20e4a 40 */
ferozfernando 0:8e7dd2d20e4a 41
ferozfernando 0:8e7dd2d20e4a 42
ferozfernando 0:8e7dd2d20e4a 43 int main () {
ferozfernando 0:8e7dd2d20e4a 44 Motor Motor1 (PC_7, PA_9, PA_8); // Deklarasi objek motor
ferozfernando 0:8e7dd2d20e4a 45 Motor Motor2 (PA_7, PA_6, PA_5);
ferozfernando 0:8e7dd2d20e4a 46 Motor Motor3 (PB_3, PA_10, PA_2);
ferozfernando 0:8e7dd2d20e4a 47 // Cara untuk menemukan perbandingan kecepatan sudut yang diperlukan tidak dapat saya temukan
ferozfernando 0:8e7dd2d20e4a 48 // Kecepatan sudut setiap roda seharusnya berubah ubah seiring waktu
ferozfernando 0:8e7dd2d20e4a 49 // Orientasi sebagai acuan arah juga berubah ubah seiring terjadinya rotasi
ferozfernando 0:8e7dd2d20e4a 50 return 0;
ferozfernando 0:8e7dd2d20e4a 51 }