frscl / Motor

Fork of Motor by Simon Ford

Committer:
miczyg
Date:
Thu May 07 11:05:06 2015 +0000
Revision:
5:71d7e9c17980
Parent:
4:5370aae8ee3b
Child:
6:a321d28cce9a
gotowiec prawie

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:a470311addc4 1 /* mbed simple H-bridge motor controller
miczyg 4:5370aae8ee3b 2 * Copyright (c) 2007-2010, sford, http://mbed.org
miczyg 4:5370aae8ee3b 3 *
miczyg 4:5370aae8ee3b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
miczyg 4:5370aae8ee3b 5 * of this software and associated documentation files (the "Software"), to deal
miczyg 4:5370aae8ee3b 6 * in the Software without restriction, including without limitation the rights
miczyg 4:5370aae8ee3b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
miczyg 4:5370aae8ee3b 8 * copies of the Software, and to permit persons to whom the Software is
miczyg 4:5370aae8ee3b 9 * furnished to do so, subject to the following conditions:
miczyg 4:5370aae8ee3b 10 *
miczyg 4:5370aae8ee3b 11 * The above copyright notice and this permission notice shall be included in
miczyg 4:5370aae8ee3b 12 * all copies or substantial portions of the Software.
miczyg 4:5370aae8ee3b 13 *
miczyg 4:5370aae8ee3b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
miczyg 4:5370aae8ee3b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
miczyg 4:5370aae8ee3b 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
miczyg 4:5370aae8ee3b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
miczyg 4:5370aae8ee3b 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
miczyg 4:5370aae8ee3b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
miczyg 4:5370aae8ee3b 20 * THE SOFTWARE.
miczyg 4:5370aae8ee3b 21 */
simon 0:a470311addc4 22
simon 0:a470311addc4 23 #ifndef MBED_MOTOR_H
simon 0:a470311addc4 24 #define MBED_MOTOR_H
simon 0:a470311addc4 25
simon 0:a470311addc4 26 #include "mbed.h"
miczyg 3:9572ea41a1b4 27 #include "PID.h"
miczyg 4:5370aae8ee3b 28 #include "QEI.h"
simon 0:a470311addc4 29
miczyg 4:5370aae8ee3b 30 /*nastawy regulatora PID*/
miczyg 4:5370aae8ee3b 31 const float K = 1;
miczyg 4:5370aae8ee3b 32 const float Ti = 0;
miczyg 4:5370aae8ee3b 33 const float Td = 0;
miczyg 4:5370aae8ee3b 34 const float itv = 0.001;
miczyg 5:71d7e9c17980 35 #define AUTO 1
miczyg 4:5370aae8ee3b 36
miczyg 4:5370aae8ee3b 37 /*QEI pins*/
miczyg 4:5370aae8ee3b 38 #define CH_A PTA2
miczyg 4:5370aae8ee3b 39 #define CH_B PTA3
miczyg 4:5370aae8ee3b 40 const int pPerRev = 10;
miczyg 5:71d7e9c17980 41 const int max_pulse_rate = 300; //do policzenia!!!!!!!!!!!!!!!!!!!
miczyg 4:5370aae8ee3b 42
miczyg 4:5370aae8ee3b 43 /** Interface to control a standard DC motor
miczyg 4:5370aae8ee3b 44 *
miczyg 4:5370aae8ee3b 45 * with an H-bridge using a PwmOut and 2 DigitalOuts
miczyg 4:5370aae8ee3b 46 */
simon 0:a470311addc4 47 class Motor {
simon 0:a470311addc4 48 public:
simon 1:e341f695742a 49
miczyg 4:5370aae8ee3b 50 /** Create a motor control interface
miczyg 4:5370aae8ee3b 51 *
miczyg 4:5370aae8ee3b 52 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
miczyg 4:5370aae8ee3b 53 * @param fwd A DigitalOut, set high when the motor should go forward
miczyg 4:5370aae8ee3b 54 * @param rev A DigitalOut, set high when the motor should go backwards
miczyg 4:5370aae8ee3b 55 */
simon 0:a470311addc4 56 Motor(PinName pwm, PinName fwd, PinName rev);
miczyg 4:5370aae8ee3b 57
simon 1:e341f695742a 58 /** Set the speed of the motor
miczyg 4:5370aae8ee3b 59 *
miczyg 4:5370aae8ee3b 60 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
miczyg 4:5370aae8ee3b 61 */
simon 1:e341f695742a 62 void speed(float speed);
simon 0:a470311addc4 63
simon 0:a470311addc4 64 protected:
simon 0:a470311addc4 65 PwmOut _pwm;
simon 0:a470311addc4 66 DigitalOut _fwd;
simon 0:a470311addc4 67 DigitalOut _rev;
miczyg 4:5370aae8ee3b 68 private:
miczyg 4:5370aae8ee3b 69 PID speedControl;
miczyg 4:5370aae8ee3b 70 QEI encoder;
simon 0:a470311addc4 71
miczyg 4:5370aae8ee3b 72 float set_speed;
miczyg 4:5370aae8ee3b 73 int pulses;
miczyg 4:5370aae8ee3b 74 float curr_speed;
miczyg 4:5370aae8ee3b 75 float prev_pulses;
simon 0:a470311addc4 76 };
simon 0:a470311addc4 77
simon 0:a470311addc4 78 #endif