Code for controlling mbed hardware (LED's, motors), as well as code for the Raspberry Pi to run a Support Vector Machine that identifies objects using the Pi camera

Dependencies:   mbed Motordriver mbed-rtos PololuLedStrip

Committer:
arogliero3
Date:
Thu Dec 05 20:34:10 2019 -0500
Revision:
0:e0dbd261724a
Adding code to mbed repo

Who changed what in which revision?

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