test

Fork of MotorDriver by Bryce Williams

Committer:
tgw
Date:
Sat Nov 25 02:02:40 2017 +0000
Revision:
1:19476b49822b
Parent:
0:871adb9cf798
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
electromotivated 0:871adb9cf798 1 /*
electromotivated 0:871adb9cf798 2 Bryce Williams
electromotivated 0:871adb9cf798 3 09/14/2014
electromotivated 0:871adb9cf798 4
electromotivated 0:871adb9cf798 5 General/Basic Motor Driver Class providing Motor Control using a COTS Motor Driver
electromotivated 0:871adb9cf798 6
electromotivated 0:871adb9cf798 7 Class based off of Christopher Hasler's Motordriver library found at
electromotivated 0:871adb9cf798 8 https://developer.mbed.org/cookbook/Motor
electromotivated 0:871adb9cf798 9
electromotivated 0:871adb9cf798 10
electromotivated 0:871adb9cf798 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
electromotivated 0:871adb9cf798 12 * of this software and associated documentation files (the "Software"), to deal
electromotivated 0:871adb9cf798 13 * in the Software without restriction, including without limitation the rights
electromotivated 0:871adb9cf798 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
electromotivated 0:871adb9cf798 15 * copies of the Software, and to permit persons to whom the Software is
electromotivated 0:871adb9cf798 16 * furnished to do so, subject to the following conditions:
electromotivated 0:871adb9cf798 17 *
electromotivated 0:871adb9cf798 18 * The above copyright notice and this permission notice shall be included in
electromotivated 0:871adb9cf798 19 * all copies or substantial portions of the Software.
electromotivated 0:871adb9cf798 20 *
electromotivated 0:871adb9cf798 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
electromotivated 0:871adb9cf798 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
electromotivated 0:871adb9cf798 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
electromotivated 0:871adb9cf798 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
electromotivated 0:871adb9cf798 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
electromotivated 0:871adb9cf798 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
electromotivated 0:871adb9cf798 27 * THE SOFTWARE.
electromotivated 0:871adb9cf798 28 */
electromotivated 0:871adb9cf798 29
electromotivated 0:871adb9cf798 30 #ifndef MOTORDRIVER_H
electromotivated 0:871adb9cf798 31 #define MOTORDRIVER_H
electromotivated 0:871adb9cf798 32
electromotivated 0:871adb9cf798 33 #include "mbed.h"
electromotivated 0:871adb9cf798 34
tgw 1:19476b49822b 35 typedef enum {ERROR_M=0, DRIVING_CW=1, DRIVING_CCW=2, BRAKING=3, COASTING=4}Code_t;
electromotivated 0:871adb9cf798 36 typedef struct{
electromotivated 0:871adb9cf798 37 Code_t code;
electromotivated 0:871adb9cf798 38 float value;
electromotivated 0:871adb9cf798 39 }State_t;
electromotivated 0:871adb9cf798 40
electromotivated 0:871adb9cf798 41 class MotorDriver{
electromotivated 0:871adb9cf798 42 public:
electromotivated 0:871adb9cf798 43 /*
electromotivated 0:871adb9cf798 44 Constructor of MotorDriver Objects
electromotivated 0:871adb9cf798 45 @param in_1 Direction Input 1
electromotivated 0:871adb9cf798 46 @param in_2 Direction Input 2
electromotivated 0:871adb9cf798 47 @param pwm PWM speed control input
electromotivated 0:871adb9cf798 48 @param pwmFreq PWM frequency, some motors may whine at lower freqs
electromotivated 0:871adb9cf798 49 @param isBrakable Boolean value indicating whether or not the
electromotivated 0:871adb9cf798 50 motor driver is brakeable(see your datasheet)
electromotivated 0:871adb9cf798 51 */
electromotivated 0:871adb9cf798 52 MotorDriver(DigitalOut in1, DigitalOut in2, PwmOut pwm, float pwmFreq, bool isBrakeable = false);
electromotivated 0:871adb9cf798 53
electromotivated 0:871adb9cf798 54 /*
electromotivated 0:871adb9cf798 55 Sets speed of motor normalized between -1.0 to 1.0
electromotivated 0:871adb9cf798 56 @param speed Value -1.0 to 1.0 (>0 CW at speed as percentage)
electromotivated 0:871adb9cf798 57 (<0 CCW at speed as percentage)
electromotivated 0:871adb9cf798 58 (=0 speed is zero)
electromotivated 0:871adb9cf798 59 @return state of the motor
electromotivated 0:871adb9cf798 60 NOTE: This method will NOT allow user to instantaneously swithch
electromotivated 0:871adb9cf798 61 from CW to CCW or vise versa. Doing so will cause the motor to
electromotivated 0:871adb9cf798 62 be put in to a BRAKE condition, while the motor_state.code will
electromotivated 0:871adb9cf798 63 be updated to ERROR. User should avoid trying to do this, call
electromotivated 0:871adb9cf798 64 first setSpeed(0) or brake().
electromotivated 0:871adb9cf798 65 */
electromotivated 0:871adb9cf798 66 State_t setSpeed(float speed);
electromotivated 0:871adb9cf798 67
electromotivated 0:871adb9cf798 68 /*
electromotivated 0:871adb9cf798 69 Same as setSpeed(float speed), however does not impose the safety disallowing
electromotivated 0:871adb9cf798 70 instantaneous reversal of motor direction. It is up to the user to ensure they
electromotivated 0:871adb9cf798 71 do not blow up their motor.
electromotivated 0:871adb9cf798 72 */
electromotivated 0:871adb9cf798 73 State_t forceSetSpeed(float speed);
electromotivated 0:871adb9cf798 74
electromotivated 0:871adb9cf798 75 /*
electromotivated 0:871adb9cf798 76 Put motor into braked config
electromotivated 0:871adb9cf798 77 @param intensity How hard to brake (0.0 to 1.0)
electromotivated 0:871adb9cf798 78 @return state of the motors
electromotivated 0:871adb9cf798 79 */
electromotivated 0:871adb9cf798 80 State_t brake(float intensity);
electromotivated 0:871adb9cf798 81
electromotivated 0:871adb9cf798 82 /*
electromotivated 0:871adb9cf798 83 Put motor into stop/coast config
electromotivated 0:871adb9cf798 84 */
electromotivated 0:871adb9cf798 85 State_t coast();
electromotivated 0:871adb9cf798 86
electromotivated 0:871adb9cf798 87
electromotivated 0:871adb9cf798 88 /*
electromotivated 0:871adb9cf798 89 Get state of the motor
electromotivated 0:871adb9cf798 90 @return state of the motor
electromotivated 0:871adb9cf798 91 */
electromotivated 0:871adb9cf798 92 State_t getState();
electromotivated 0:871adb9cf798 93
electromotivated 0:871adb9cf798 94 protected: // Protected so objects that inherit can access
electromotivated 0:871adb9cf798 95 State_t motor_state;
electromotivated 0:871adb9cf798 96 DigitalOut _in1;
electromotivated 0:871adb9cf798 97 DigitalOut _in2;
electromotivated 0:871adb9cf798 98 PwmOut _pwm;
electromotivated 0:871adb9cf798 99 bool isBrakeable;
electromotivated 0:871adb9cf798 100 void determineState(); // Determine motor state based on in1, in2, and pwm
electromotivated 0:871adb9cf798 101 };
electromotivated 0:871adb9cf798 102
electromotivated 0:871adb9cf798 103 #endif