Control for RenBuggy
Dependencies: PID PinDetect mbed
RenBuggy_PID.h@0:f414c64e674f, 2014-03-04 (annotated)
- Committer:
- salatron
- Date:
- Tue Mar 04 13:31:17 2014 +0000
- Revision:
- 0:f414c64e674f
- Child:
- 1:8a2a7adb3c5d
Version1
; RenBuggy with PID controll
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
salatron | 0:f414c64e674f | 1 | /******************************************************************************* |
salatron | 0:f414c64e674f | 2 | * RenBED PID Motor Control for RenBuggy * |
salatron | 0:f414c64e674f | 3 | * Copyright (c) 2014 Sally Brown * |
salatron | 0:f414c64e674f | 4 | * * |
salatron | 0:f414c64e674f | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * |
salatron | 0:f414c64e674f | 6 | * of this software and associated documentation files (the "Software"), to deal* |
salatron | 0:f414c64e674f | 7 | * in the Software without restriction, including without limitation the rights * |
salatron | 0:f414c64e674f | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * |
salatron | 0:f414c64e674f | 9 | * copies of the Software, and to permit persons to whom the Software is * |
salatron | 0:f414c64e674f | 10 | * furnished to do so, subject to the following conditions: * |
salatron | 0:f414c64e674f | 11 | * * |
salatron | 0:f414c64e674f | 12 | * The above copyright notice and this permission notice shall be included in * |
salatron | 0:f414c64e674f | 13 | * all copies or substantial portions of the Software. * |
salatron | 0:f414c64e674f | 14 | * * |
salatron | 0:f414c64e674f | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * |
salatron | 0:f414c64e674f | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * |
salatron | 0:f414c64e674f | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * |
salatron | 0:f414c64e674f | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * |
salatron | 0:f414c64e674f | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* |
salatron | 0:f414c64e674f | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * |
salatron | 0:f414c64e674f | 21 | * THE SOFTWARE. * |
salatron | 0:f414c64e674f | 22 | * * |
salatron | 0:f414c64e674f | 23 | * PID_Controller.h * |
salatron | 0:f414c64e674f | 24 | * * |
salatron | 0:f414c64e674f | 25 | *******************************************************************************/ |
salatron | 0:f414c64e674f | 26 | |
salatron | 0:f414c64e674f | 27 | #ifndef _PIDCONTROLLER_H |
salatron | 0:f414c64e674f | 28 | #define _PIDCONTROLLER_H |
salatron | 0:f414c64e674f | 29 | |
salatron | 0:f414c64e674f | 30 | #include "mbed.h" |
salatron | 0:f414c64e674f | 31 | #include "PID.h" |
salatron | 0:f414c64e674f | 32 | #include "PinDetect.h" |
salatron | 0:f414c64e674f | 33 | |
salatron | 0:f414c64e674f | 34 | #define pi 3.1416 |
salatron | 0:f414c64e674f | 35 | #define RATE 0.001 |
salatron | 0:f414c64e674f | 36 | |
salatron | 0:f414c64e674f | 37 | class PID_Controller |
salatron | 0:f414c64e674f | 38 | { |
salatron | 0:f414c64e674f | 39 | public: |
salatron | 0:f414c64e674f | 40 | PID_Controller(PinName motorL, PinName motorR, PinName brakeL, PinName brakeR, PinName sensorL, PinName sensorR); |
salatron | 0:f414c64e674f | 41 | |
salatron | 0:f414c64e674f | 42 | void SetUpConstants(int numberStripes, float wheelCircumference); |
salatron | 0:f414c64e674f | 43 | |
salatron | 0:f414c64e674f | 44 | void Forwards(int countsForward); |
salatron | 0:f414c64e674f | 45 | void Left(int angleLeft, int radiusLeft); |
salatron | 0:f414c64e674f | 46 | void Right(int angleRight, int radiusRight); |
salatron | 0:f414c64e674f | 47 | |
salatron | 0:f414c64e674f | 48 | private: |
salatron | 0:f414c64e674f | 49 | |
salatron | 0:f414c64e674f | 50 | void doSomePID(); |
salatron | 0:f414c64e674f | 51 | void PIDLeft(); |
salatron | 0:f414c64e674f | 52 | void PIDRight(); |
salatron | 0:f414c64e674f | 53 | |
salatron | 0:f414c64e674f | 54 | void countL(); |
salatron | 0:f414c64e674f | 55 | void countR(); |
salatron | 0:f414c64e674f | 56 | |
salatron | 0:f414c64e674f | 57 | void setUpControllers(); |
salatron | 0:f414c64e674f | 58 | |
salatron | 0:f414c64e674f | 59 | PID m_controllerL; //Kc, Ti, Td, interval |
salatron | 0:f414c64e674f | 60 | PID m_controllerR; |
salatron | 0:f414c64e674f | 61 | |
salatron | 0:f414c64e674f | 62 | PwmOut m_motorL; |
salatron | 0:f414c64e674f | 63 | PwmOut m_motorR; |
salatron | 0:f414c64e674f | 64 | |
salatron | 0:f414c64e674f | 65 | DigitalOut m_brakeL; |
salatron | 0:f414c64e674f | 66 | DigitalOut m_brakeR; |
salatron | 0:f414c64e674f | 67 | |
salatron | 0:f414c64e674f | 68 | PinDetect m_senseL; //Left encoder. Pin detect type is the debouncing. |
salatron | 0:f414c64e674f | 69 | PinDetect m_senseR; |
salatron | 0:f414c64e674f | 70 | |
salatron | 0:f414c64e674f | 71 | Ticker m_rate; |
salatron | 0:f414c64e674f | 72 | |
salatron | 0:f414c64e674f | 73 | int m_numberStrips; |
salatron | 0:f414c64e674f | 74 | float m_wheelCircumference; |
salatron | 0:f414c64e674f | 75 | |
salatron | 0:f414c64e674f | 76 | int m_stripesL; |
salatron | 0:f414c64e674f | 77 | int m_stripesR; |
salatron | 0:f414c64e674f | 78 | |
salatron | 0:f414c64e674f | 79 | bool m_turnLeft; |
salatron | 0:f414c64e674f | 80 | bool m_turnRight; |
salatron | 0:f414c64e674f | 81 | |
salatron | 0:f414c64e674f | 82 | float m_fProportionLeft; |
salatron | 0:f414c64e674f | 83 | float m_fProportionRight; |
salatron | 0:f414c64e674f | 84 | |
salatron | 0:f414c64e674f | 85 | int m_iProportionLeft; |
salatron | 0:f414c64e674f | 86 | int m_iProportionRight; |
salatron | 0:f414c64e674f | 87 | }; |
salatron | 0:f414c64e674f | 88 | |
salatron | 0:f414c64e674f | 89 | #endif // _PIDCONTROLLER_H |