Shadow Chassis Robot Receiver Program

Dependencies:   SDFileSystem mbed-rtos mbed

Fork of ECE4180Lab4 by Frank Zhou

Committer:
jasonbx
Date:
Wed May 03 07:20:39 2017 +0000
Revision:
2:b28eb84aab4f
Parent:
1:464ef4e0b4c8
added songs;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jasonbx 1:464ef4e0b4c8 1 /*motor driver libary modified from the following libary,
jasonbx 1:464ef4e0b4c8 2 *
jasonbx 1:464ef4e0b4c8 3 * mbed simple H-bridge motor controller
jasonbx 1:464ef4e0b4c8 4 * Copyright (c) 2007-2010, sford
jasonbx 1:464ef4e0b4c8 5 *
jasonbx 1:464ef4e0b4c8 6 * by Christopher Hasler.
jasonbx 1:464ef4e0b4c8 7 *
jasonbx 1:464ef4e0b4c8 8 * from sford's libary,
jasonbx 1:464ef4e0b4c8 9 *
jasonbx 1:464ef4e0b4c8 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
jasonbx 1:464ef4e0b4c8 11 * of this software and associated documentation files (the "Software"), to deal
jasonbx 1:464ef4e0b4c8 12 * in the Software without restriction, including without limitation the rights
jasonbx 1:464ef4e0b4c8 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jasonbx 1:464ef4e0b4c8 14 * copies of the Software, and to permit persons to whom the Software is
jasonbx 1:464ef4e0b4c8 15 * furnished to do so, subject to the following conditions:
jasonbx 1:464ef4e0b4c8 16 *
jasonbx 1:464ef4e0b4c8 17 * The above copyright notice and this permission notice shall be included in
jasonbx 1:464ef4e0b4c8 18 * all copies or substantial portions of the Software.
jasonbx 1:464ef4e0b4c8 19 *
jasonbx 1:464ef4e0b4c8 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jasonbx 1:464ef4e0b4c8 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jasonbx 1:464ef4e0b4c8 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jasonbx 1:464ef4e0b4c8 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jasonbx 1:464ef4e0b4c8 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jasonbx 1:464ef4e0b4c8 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jasonbx 1:464ef4e0b4c8 26 * THE SOFTWARE.
jasonbx 1:464ef4e0b4c8 27 */
jasonbx 1:464ef4e0b4c8 28
jasonbx 1:464ef4e0b4c8 29 #ifndef MBED_MOTOR_H
jasonbx 1:464ef4e0b4c8 30 #define MBED_MOTOR_H
jasonbx 1:464ef4e0b4c8 31
jasonbx 1:464ef4e0b4c8 32 #include "mbed.h"
jasonbx 1:464ef4e0b4c8 33
jasonbx 1:464ef4e0b4c8 34 /** Interface to control a standard DC motor
jasonbx 1:464ef4e0b4c8 35 * with an H-bridge using a PwmOut and 2 DigitalOuts
jasonbx 1:464ef4e0b4c8 36 */
jasonbx 1:464ef4e0b4c8 37 class Motor {
jasonbx 1:464ef4e0b4c8 38 public:
jasonbx 1:464ef4e0b4c8 39
jasonbx 1:464ef4e0b4c8 40 /** Create a motor control interface
jasonbx 1:464ef4e0b4c8 41 *
jasonbx 1:464ef4e0b4c8 42 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
jasonbx 1:464ef4e0b4c8 43 * @param fwd A DigitalOut, set high when the motor should go forward
jasonbx 1:464ef4e0b4c8 44 * @param rev A DigitalOut, set high when the motor should go backwards
jasonbx 1:464ef4e0b4c8 45 * @param set if the motor driver is able to do braking 0 false 1 true.
jasonbx 1:464ef4e0b4c8 46 */
jasonbx 1:464ef4e0b4c8 47 Motor(PinName pwm, PinName fwd, PinName rev, int brakeable);
jasonbx 1:464ef4e0b4c8 48
jasonbx 1:464ef4e0b4c8 49 /** Set the speed of the motor
jasonbx 1:464ef4e0b4c8 50 *
jasonbx 1:464ef4e0b4c8 51 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0.
jasonbx 1:464ef4e0b4c8 52 * @return the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping.
jasonbx 1:464ef4e0b4c8 53 */
jasonbx 1:464ef4e0b4c8 54 float speed(float speed);
jasonbx 1:464ef4e0b4c8 55
jasonbx 1:464ef4e0b4c8 56 /** Set the the motor to coast
jasonbx 1:464ef4e0b4c8 57 *
jasonbx 1:464ef4e0b4c8 58 * @param void
jasonbx 1:464ef4e0b4c8 59 * @return motor coasts until another instruction is recived.
jasonbx 1:464ef4e0b4c8 60 */
jasonbx 1:464ef4e0b4c8 61
jasonbx 1:464ef4e0b4c8 62 void coast(void);
jasonbx 1:464ef4e0b4c8 63
jasonbx 1:464ef4e0b4c8 64 /** Set the motor to dynamicaly brake
jasonbx 1:464ef4e0b4c8 65 *
jasonbx 1:464ef4e0b4c8 66 * @param float 0 - 1.0 provides some control over how hard the motor brakes.
jasonbx 1:464ef4e0b4c8 67 * @return duty applied to motor driver. -1 is error, motor driver can't brake.
jasonbx 1:464ef4e0b4c8 68 */
jasonbx 1:464ef4e0b4c8 69
jasonbx 1:464ef4e0b4c8 70 float stop(float duty);
jasonbx 1:464ef4e0b4c8 71 /** return the current state of the motor
jasonbx 1:464ef4e0b4c8 72 *
jasonbx 1:464ef4e0b4c8 73 * @param void
jasonbx 1:464ef4e0b4c8 74 * @return state of motor, -1 to 1 is speed, -2 is braking, 2 is coasting. -3 is error.
jasonbx 1:464ef4e0b4c8 75 */
jasonbx 1:464ef4e0b4c8 76 float state(void);
jasonbx 1:464ef4e0b4c8 77
jasonbx 1:464ef4e0b4c8 78 protected:
jasonbx 1:464ef4e0b4c8 79 PwmOut _pwm;
jasonbx 1:464ef4e0b4c8 80 DigitalOut _fwd;
jasonbx 1:464ef4e0b4c8 81 DigitalOut _rev;
jasonbx 1:464ef4e0b4c8 82 int Brakeable; // cna the motor driver break
jasonbx 1:464ef4e0b4c8 83 int sign; //prevents throwing the motor from full foward to full reverse and stuff melting.
jasonbx 1:464ef4e0b4c8 84
jasonbx 1:464ef4e0b4c8 85 };
jasonbx 1:464ef4e0b4c8 86
jasonbx 1:464ef4e0b4c8 87
jasonbx 1:464ef4e0b4c8 88
jasonbx 1:464ef4e0b4c8 89
jasonbx 1:464ef4e0b4c8 90
jasonbx 1:464ef4e0b4c8 91 #endif