Class library for a L298 H-Bridge
Dependents: inverted_pendulum_system
Fork of L298HBridge by
Revision 3:dabd8b6b2bff, committed 2017-08-25
- Comitter:
- dudu941014
- Date:
- Fri Aug 25 21:00:45 2017 +0000
- Parent:
- 2:1c000b6cf863
- Commit message:
- this code is for the inverted pendulum balancer. it is based the two loop PID controllers. One PID controller is for angle, and another one is for velocity
Changed in this revision
L298HBridge.cpp | Show annotated file Show diff for this revision Revisions of this file |
L298HBridge.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1c000b6cf863 -r dabd8b6b2bff L298HBridge.cpp --- a/L298HBridge.cpp Fri Jan 20 09:10:05 2017 +0000 +++ b/L298HBridge.cpp Fri Aug 25 21:00:45 2017 +0000 @@ -1,29 +1,56 @@ +////////////////////////////////////////////////////////////////////////////////// +// Company: edinburgh of university +// Engineer: ZEjun DU +// +// Create Date: 2017/08/20 13:06:52 +// Design Name: Inverted Pendulum Balancer +// Module Name: motor driver +// Tool Versions: “Keil 5” or “Mbed Complie Online” +// Description: this part is basic function of movement to control the motor according to PWM!!!!!!! +// +// +////////////////////////////////////////////////////////////////////////////////// + #include "L298HBridge.h" #include "mbed.h" - +//////////////////////////////////////////////////////////// +//this part is a independent function which control the movement based on L298n +//////////////////////////////////////////////////////////// L298HBridge::L298HBridge(PinName ENPin, PinName FWDPin, PinName REVPin) : _ENPin(ENPin), _FWDPin(FWDPin), _REVPin(REVPin) { - _ENPin = 0; //PWM = 0% - _FWDPin = 0; - _REVPin = 0; - _ENPin.period(0.020); //set PWM period to 20mS as default. + _ENPin = 0; //PWM = 0% + _FWDPin = 0; //PWM = 0% + _REVPin = 0; //PWM = 0% + _ENPin.period(0.0002); //set PWM period to 2mS as default. } - + +//////////////////////////////////////////////////////////// +//this part is to move forward +//////////////////////////////////////////////////////////// void L298HBridge::Fwd() { - _FWDPin = 1; - _REVPin = 0; + _FWDPin = 1;//enable foward pin + _REVPin = 0;//disable reverse pin } +//////////////////////////////////////////////////////////// +//this part is to move reserve +//////////////////////////////////////////////////////////// void L298HBridge::Rev() { - _FWDPin = 0; - _REVPin = 1; + _FWDPin = 0;//disable foward pin + _REVPin = 1;//enable reverse pin } +//////////////////////////////////////////////////////////// +//this part is to stop the movement of the balancer +//////////////////////////////////////////////////////////// void L298HBridge::Stop() { - _FWDPin = 0; - _REVPin = 0; + _FWDPin = 0;//disable foward pin + _REVPin = 0;//disable reverse pin } - + +//////////////////////////////////////////////////////////// +//this part is to control the force of the motor according to PWM +//////////////////////////////////////////////////////////// void L298HBridge::Speed(float DutyPercent) { - _ENPin = DutyPercent /100; + _ENPin = DutyPercent /1000;//set PWM pin } \ No newline at end of file
diff -r 1c000b6cf863 -r dabd8b6b2bff L298HBridge.h --- a/L298HBridge.h Fri Jan 20 09:10:05 2017 +0000 +++ b/L298HBridge.h Fri Aug 25 21:00:45 2017 +0000 @@ -1,27 +1,16 @@ -/* L298HBridge Library v1.0 - * Copyright (c) 2017 Riaan Ehlers - * riaan.ehlers@nmmu.ac.za - * - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - +////////////////////////////////////////////////////////////////////////////////// +// Company: edinburgh of university +// Engineer: ZEjun DU +// +// Create Date: 2017/08/20 13:06:52 +// Design Name: Inverted Pendulum Balancer +// Module Name: motor driver +// Tool Versions: “Keil 5” or “Mbed Complie Online” +// Description: this part is to control the motor according to PWM +// +// +////////////////////////////////////////////////////////////////////////////////// + #ifndef L298HBridge_H #define L298HBridge_H