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 /* mbed simple H-bridge motor controller
ferozfernando 0:8e7dd2d20e4a 2 * Copyright (c) 2007-2010, sford
ferozfernando 0:8e7dd2d20e4a 3 *
ferozfernando 0:8e7dd2d20e4a 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
ferozfernando 0:8e7dd2d20e4a 5 * of this software and associated documentation files (the "Software"), to deal
ferozfernando 0:8e7dd2d20e4a 6 * in the Software without restriction, including without limitation the rights
ferozfernando 0:8e7dd2d20e4a 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ferozfernando 0:8e7dd2d20e4a 8 * copies of the Software, and to permit persons to whom the Software is
ferozfernando 0:8e7dd2d20e4a 9 * furnished to do so, subject to the following conditions:
ferozfernando 0:8e7dd2d20e4a 10 *
ferozfernando 0:8e7dd2d20e4a 11 * The above copyright notice and this permission notice shall be included in
ferozfernando 0:8e7dd2d20e4a 12 * all copies or substantial portions of the Software.
ferozfernando 0:8e7dd2d20e4a 13 *
ferozfernando 0:8e7dd2d20e4a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ferozfernando 0:8e7dd2d20e4a 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ferozfernando 0:8e7dd2d20e4a 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ferozfernando 0:8e7dd2d20e4a 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ferozfernando 0:8e7dd2d20e4a 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ferozfernando 0:8e7dd2d20e4a 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ferozfernando 0:8e7dd2d20e4a 20 * THE SOFTWARE.
ferozfernando 0:8e7dd2d20e4a 21 */
ferozfernando 0:8e7dd2d20e4a 22
ferozfernando 0:8e7dd2d20e4a 23 #ifndef MBED_MOTOR_H
ferozfernando 0:8e7dd2d20e4a 24 #define MBED_MOTOR_H
ferozfernando 0:8e7dd2d20e4a 25
ferozfernando 0:8e7dd2d20e4a 26 #include "mbed.h"
ferozfernando 0:8e7dd2d20e4a 27
ferozfernando 0:8e7dd2d20e4a 28 #define BRAKE_HIGH 1
ferozfernando 0:8e7dd2d20e4a 29 #define BRAKE_LOW 0
ferozfernando 0:8e7dd2d20e4a 30
ferozfernando 0:8e7dd2d20e4a 31 /** Interface to control a standard DC motor
ferozfernando 0:8e7dd2d20e4a 32 * with an H-bridge using a PwmOut and 2 DigitalOuts
ferozfernando 0:8e7dd2d20e4a 33 */
ferozfernando 0:8e7dd2d20e4a 34 class Motor {
ferozfernando 0:8e7dd2d20e4a 35 public:
ferozfernando 0:8e7dd2d20e4a 36
ferozfernando 0:8e7dd2d20e4a 37 /** Create a motor control interface
ferozfernando 0:8e7dd2d20e4a 38 *
ferozfernando 0:8e7dd2d20e4a 39 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
ferozfernando 0:8e7dd2d20e4a 40 * @param fwd A DigitalOut, set high when the motor should go forward
ferozfernando 0:8e7dd2d20e4a 41 * @param rev A DigitalOut, set high when the motor should go backwards
ferozfernando 0:8e7dd2d20e4a 42 */
ferozfernando 0:8e7dd2d20e4a 43 Motor(PinName pwm, PinName fwd, PinName rev);
ferozfernando 0:8e7dd2d20e4a 44
ferozfernando 0:8e7dd2d20e4a 45 /** Set the speed of the motor
ferozfernando 0:8e7dd2d20e4a 46 *
ferozfernando 0:8e7dd2d20e4a 47 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
ferozfernando 0:8e7dd2d20e4a 48 */
ferozfernando 0:8e7dd2d20e4a 49 void speed(float speed);
ferozfernando 0:8e7dd2d20e4a 50
ferozfernando 0:8e7dd2d20e4a 51 /** Set the period of the pwm duty cycle.
ferozfernando 0:8e7dd2d20e4a 52 *
ferozfernando 0:8e7dd2d20e4a 53 * Wrapper for PwmOut::period()
ferozfernando 0:8e7dd2d20e4a 54 *
ferozfernando 0:8e7dd2d20e4a 55 * @param seconds - Pwm duty cycle in seconds.
ferozfernando 0:8e7dd2d20e4a 56 */
ferozfernando 0:8e7dd2d20e4a 57 void period(float period);
ferozfernando 0:8e7dd2d20e4a 58
ferozfernando 0:8e7dd2d20e4a 59 /** Brake the H-bridge to GND or VCC.
ferozfernando 0:8e7dd2d20e4a 60 *
ferozfernando 0:8e7dd2d20e4a 61 * Defaults to breaking to VCC.
ferozfernando 0:8e7dd2d20e4a 62 *
ferozfernando 0:8e7dd2d20e4a 63 * Brake to GND => inA = inB = 0
ferozfernando 0:8e7dd2d20e4a 64 * Brake to VCC => inA = inB = 1
ferozfernando 0:8e7dd2d20e4a 65 */
ferozfernando 0:8e7dd2d20e4a 66 void brake(int highLow = BRAKE_HIGH);
ferozfernando 0:8e7dd2d20e4a 67
ferozfernando 0:8e7dd2d20e4a 68 /**
ferozfernando 0:8e7dd2d20e4a 69 *Brake lebih baik
ferozfernando 0:8e7dd2d20e4a 70 **/
ferozfernando 0:8e7dd2d20e4a 71 void forcebrake();
ferozfernando 0:8e7dd2d20e4a 72
ferozfernando 0:8e7dd2d20e4a 73 protected:
ferozfernando 0:8e7dd2d20e4a 74 PwmOut _pwm;
ferozfernando 0:8e7dd2d20e4a 75 DigitalOut _fwd;
ferozfernando 0:8e7dd2d20e4a 76 DigitalOut _rev;
ferozfernando 0:8e7dd2d20e4a 77
ferozfernando 0:8e7dd2d20e4a 78 };
ferozfernando 0:8e7dd2d20e4a 79
ferozfernando 0:8e7dd2d20e4a 80 #endif