Tugas Magang-1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ferozfernando
Date:
Wed Mar 20 16:44:22 2019 +0000
Commit message:
Tugas Magang KRTMI-1

Changed in this revision

ForwardRotation.cpp Show annotated file Show diff for this revision Revisions of this file
Maju.cpp Show annotated file Show diff for this revision Revisions of this file
Motor.h Show annotated file Show diff for this revision Revisions of this file
Mundur.cpp Show annotated file Show diff for this revision Revisions of this file
PivotKanan.cpp Show annotated file Show diff for this revision Revisions of this file
PivotKiri.cpp Show annotated file Show diff for this revision Revisions of this file
TranslasiKanan.cpp Show annotated file Show diff for this revision Revisions of this file
TranslasiKiri.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ForwardRotation.cpp	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,51 @@
+#include <iostream>
+#include "Motor.h"
+#include "mbed.h"
+#include "math.h"
+
+bool loop = true;
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.002);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > (float)0.0);
+    _rev = (speed < (float)0.0);
+    _pwm = fabs(speed);
+}
+
+void Motor::period(float period){
+    _pwm.period(period);
+}
+
+// Ilustrasi Kondisi Motor :
+/* 
+          +__________-     -- > Motor 3
+
+
+    -                      +
+     \                    /
+      \                  /   --- > Kiri : Motor 1, Kanan : Motor 2
+       \                /
+        +              -
+*/
+
+
+int main () {
+    Motor Motor1 (PC_7, PA_9, PA_8);   // Deklarasi objek motor
+    Motor Motor2 (PA_7, PA_6, PA_5);
+    Motor Motor3 (PB_3, PA_10, PA_2);
+// Cara untuk menemukan perbandingan kecepatan sudut yang diperlukan tidak dapat saya temukan
+// Kecepatan sudut setiap roda seharusnya berubah ubah seiring waktu
+// Orientasi sebagai acuan arah juga berubah ubah seiring terjadinya rotasi
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Maju.cpp	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,53 @@
+#include <iostream>
+#include "mbed.h"
+#include "Motor.h"
+
+bool loop = true;
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.002);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > (float)0.0);
+    _rev = (speed < (float)0.0);
+    _pwm = fabs(speed);
+}
+
+void Motor::period(float period){
+    _pwm.period(period);
+}
+
+// Ilustrasi Kondisi Motor :
+/* 
+          -__________+     -- > Motor 3
+
+
+    -                      +
+     \                    /
+      \                  /   --- > Kiri : Motor 1, Kanan : Motor 2
+       \                /
+        +              -
+*/
+
+
+int main () {
+    Motor Motor1 (PC_7, PA_9, PA_8);   // Deklarasi objek motor dan letak pin
+    Motor Motor2 (PA_7, PA_6, PA_5);
+    Motor Motor3 (PB_3, PA_10, PA_2);
+    
+    while (loop == true) {
+        Motor1.speed (-0.5);
+        Motor2.speed (0.5);
+        }
+    
+    return 0;
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.h	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,80 @@
+/* mbed simple H-bridge motor controller
+ * Copyright (c) 2007-2010, sford
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MBED_MOTOR_H
+#define MBED_MOTOR_H
+
+#include "mbed.h"
+
+#define BRAKE_HIGH 1
+#define BRAKE_LOW  0
+
+/** Interface to control a standard DC motor 
+ * with an H-bridge using a PwmOut and 2 DigitalOuts
+ */
+class Motor {
+public:
+
+    /** Create a motor control interface    
+     *
+     * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
+     * @param fwd A DigitalOut, set high when the motor should go forward
+     * @param rev A DigitalOut, set high when the motor should go backwards
+     */
+    Motor(PinName pwm, PinName fwd, PinName rev);
+    
+    /** Set the speed of the motor
+     * 
+     * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
+     */
+    void speed(float speed);
+    
+    /** Set the period of the pwm duty cycle.
+     *
+     * Wrapper for PwmOut::period()
+     *
+     * @param seconds - Pwm duty cycle in seconds.
+     */
+    void period(float period);
+    
+    /** Brake the H-bridge to GND or VCC.
+     * 
+     * Defaults to breaking to VCC.
+     *
+     * Brake to GND => inA = inB = 0
+     * Brake to VCC => inA = inB = 1
+     */
+    void brake(int highLow = BRAKE_HIGH);
+    
+    /**
+    *Brake lebih baik
+    **/
+    void forcebrake();
+
+protected:
+    PwmOut _pwm;
+    DigitalOut _fwd;
+    DigitalOut _rev;
+
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mundur.cpp	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,52 @@
+#include <iostream>
+#include "Motor.h"
+#include "mbed.h"
+
+bool loop = true;
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.002);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > (float)0.0);
+    _rev = (speed < (float)0.0);
+    _pwm = fabs(speed);
+}
+
+void Motor::period(float period){
+    _pwm.period(period);
+}
+
+// Ilustrasi Kondisi Motor :
+/* 
+          -__________+     -- > Motor 3
+
+
+    -                      +
+     \                    /
+      \                  /   --- > Kiri : Motor 1, Kanan : Motor 2
+       \                /
+        +              -
+*/
+
+
+int main () {
+    Motor Motor1 (PC_7, PA_9, PA_8);   // Deklarasi objek motor
+    Motor Motor2 (PA_7, PA_6, PA_5);
+    Motor Motor3 (PB_3, PA_10, PA_2);
+        
+    while (loop == true) {
+    Motor1.speed(-0.5);
+    Motor2.speed(0.5);
+    }    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PivotKanan.cpp	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,53 @@
+#include <iostream>
+#include "Motor.h"
+#include "mbed.h"
+
+bool loop = true;
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.002);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > (float)0.0);
+    _rev = (speed < (float)0.0);
+    _pwm = fabs(speed);
+}
+
+void Motor::period(float period){
+    _pwm.period(period);
+}
+
+// Ilustrasi Kondisi Motor :
+/* 
+          +__________-     -- > Motor 3
+
+
+    -                      +
+     \                    /
+      \                  /   --- > Kiri : Motor 1, Kanan : Motor 2
+       \                /
+        +              -
+*/
+
+
+int main () {
+    Motor Motor1 (PC_7, PA_9, PA_8);   // Deklarasi objek motor
+    Motor Motor2 (PA_7, PA_6, PA_5);
+    Motor Motor3 (PB_3, PA_10, PA_2);
+        
+    while (loop == true) {
+    Motor1.speed(-0.5);
+    Motor2.speed(-0.5);
+    Motor3.speed(-0.5);
+    }    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PivotKiri.cpp	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,53 @@
+#include <iostream>
+#include "Motor.h"
+#include "mbed.h"
+
+bool loop = true;
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.002);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > (float)0.0);
+    _rev = (speed < (float)0.0);
+    _pwm = fabs(speed);
+}
+
+void Motor::period(float period){
+    _pwm.period(period);
+}
+
+// Ilustrasi Kondisi Motor :
+/* 
+          +__________-     -- > Motor 3
+
+
+    -                      +
+     \                    /
+      \                  /   --- > Kiri : Motor 1, Kanan : Motor 2
+       \                /
+        +              -
+*/
+
+
+int main () {
+    Motor Motor1 (PC_7, PA_9, PA_8);   // Deklarasi objek motor
+    Motor Motor2 (PA_7, PA_6, PA_5);
+    Motor Motor3 (PB_3, PA_10, PA_2);
+        
+    while (loop == true) {
+    Motor1.speed(0.5);
+    Motor2.speed(0.5);
+    Motor3.speed(0.5);
+    }    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TranslasiKanan.cpp	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,53 @@
+#include <iostream>
+#include "Motor.h"
+#include "mbed.h"
+
+bool loop = true;
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.002);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > (float)0.0);
+    _rev = (speed < (float)0.0);
+    _pwm = fabs(speed);
+}
+
+void Motor::period(float period){
+    _pwm.period(period);
+}
+
+// Ilustrasi Kondisi Motor :
+/* 
+          +__________-     -- > Motor 3
+
+
+    -                      +
+     \                    /
+      \                  /   --- > Kiri : Motor 1, Kanan : Motor 2
+       \                /
+        +              -
+*/
+
+
+int main () {
+    Motor Motor1 (PC_7, PA_9, PA_8);   // Deklarasi objek motor
+    Motor Motor2 (PA_7, PA_6, PA_5);
+    Motor Motor3 (PB_3, PA_10, PA_2);
+        
+    while (loop == true) {
+    Motor1.speed(0.5);
+    Motor2.speed(0.5);
+    Motor3.speed(-0.5);
+    }    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TranslasiKiri.cpp	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,53 @@
+#include <iostream>
+#include "Motor.h"
+#include "mbed.h"
+
+bool loop = true;
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.002);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > (float)0.0);
+    _rev = (speed < (float)0.0);
+    _pwm = fabs(speed);
+}
+
+void Motor::period(float period){
+    _pwm.period(period);
+}
+
+// Ilustrasi Kondisi Motor :
+/* 
+          +__________-     -- > Motor 3
+
+
+    -                      +
+     \                    /
+      \                  /   --- > Kiri : Motor 1, Kanan : Motor 2
+       \                /
+        +              -
+*/
+
+
+int main () {
+    Motor Motor1 (PC_7, PA_9, PA_8);   // Deklarasi objek motor
+    Motor Motor2 (PA_7, PA_6, PA_5);
+    Motor Motor3 (PB_3, PA_10, PA_2);
+        
+    while (loop == true) {
+    Motor1.speed(-0.5);
+    Motor2.speed(-0.5);
+    Motor3.speed(0.5);
+    }    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Mar 20 16:44:22 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file