Gestion pont-H pour moteur CC

Committer:
Jean92
Date:
Sat Sep 12 19:17:55 2015 +0000
Revision:
1:4dc14e8e5ff7
Parent:
0:af7b948d1f33
Child:
2:980b46615b6e
Librairie de gestion d'un pont-H pour moteur (v0.2)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jean92 1:4dc14e8e5ff7 1 /* mbed yMOTOR Library
Jean92 1:4dc14e8e5ff7 2 * Copyright (c) 2015 Jean92, https://developer.mbed.org/users/Jean92/
Jean92 1:4dc14e8e5ff7 3 */
Jean92 1:4dc14e8e5ff7 4 /**
Jean92 0:af7b948d1f33 5 * @file yMOTOR.cpp
Jean92 0:af7b948d1f33 6 * @brief Class 'yMOTOR'
Jean92 1:4dc14e8e5ff7 7 * @version V0.2
Jean92 1:4dc14e8e5ff7 8 * @date Sept-2015
Jean92 0:af7b948d1f33 9 * @note by Jean92 \n
Jean92 0:af7b948d1f33 10 * Controlleur pour Pont-H (MC33886)" \n
Jean92 0:af7b948d1f33 11 *
Jean92 0:af7b948d1f33 12 */
Jean92 0:af7b948d1f33 13 #include "mbed.h"
Jean92 0:af7b948d1f33 14 #include "yMOTOR.h"
Jean92 0:af7b948d1f33 15
Jean92 0:af7b948d1f33 16 /** Constructeur de la class yMOTOR */
Jean92 0:af7b948d1f33 17 yMOTOR::yMOTOR(PinName pwm, PinName av, PinName ar):
Jean92 0:af7b948d1f33 18 _pwm(pwm), _av(av), _ar(ar) {
Jean92 0:af7b948d1f33 19 // init PWM
Jean92 0:af7b948d1f33 20 _pwm.period(yPeriod_def);
Jean92 0:af7b948d1f33 21 _pwm = 0.0;
Jean92 0:af7b948d1f33 22
Jean92 0:af7b948d1f33 23 // moteur a l'arret
Jean92 0:af7b948d1f33 24 _ar = 0;
Jean92 0:af7b948d1f33 25 _av = 0;
Jean92 0:af7b948d1f33 26
Jean92 0:af7b948d1f33 27 // memory of speed
Jean92 0:af7b948d1f33 28 this->m_speed = 0.0;
Jean92 0:af7b948d1f33 29 }
Jean92 0:af7b948d1f33 30
Jean92 0:af7b948d1f33 31 /** Traiter le changement de vitesse */
Jean92 0:af7b948d1f33 32 void yMOTOR::Speed(float speed) {
Jean92 0:af7b948d1f33 33 if (abs(speed) < yDB_def) { // stop motor
Jean92 0:af7b948d1f33 34 _ar = 0;
Jean92 0:af7b948d1f33 35 _av = 0;
Jean92 0:af7b948d1f33 36 _pwm = 0.0;
Jean92 0:af7b948d1f33 37 this->m_speed = 0.0;
Jean92 0:af7b948d1f33 38 }
Jean92 0:af7b948d1f33 39 else {
Jean92 0:af7b948d1f33 40 _av = (speed > yDB_def);
Jean92 0:af7b948d1f33 41 _ar = (speed < -yDB_def);
Jean92 0:af7b948d1f33 42 _pwm = abs(speed);
Jean92 0:af7b948d1f33 43 this->m_speed = speed;
Jean92 0:af7b948d1f33 44 }
Jean92 0:af7b948d1f33 45 }
Jean92 0:af7b948d1f33 46
Jean92 0:af7b948d1f33 47 /** Changer la periode de PWM */
Jean92 0:af7b948d1f33 48 void yMOTOR::Period(float seconds) {
Jean92 0:af7b948d1f33 49 _pwm.period(seconds);
Jean92 0:af7b948d1f33 50 }
Jean92 0:af7b948d1f33 51
Jean92 0:af7b948d1f33 52 /** Marche/Arret request */
Jean92 0:af7b948d1f33 53 void yMOTOR::MarArr(int mararr) {
Jean92 0:af7b948d1f33 54 if (mararr == yMARCHE) {
Jean92 0:af7b948d1f33 55 Speed(this->m_speed);
Jean92 0:af7b948d1f33 56 }
Jean92 0:af7b948d1f33 57 else if (mararr == yARRET) {
Jean92 0:af7b948d1f33 58 _ar = 0;
Jean92 0:af7b948d1f33 59 _av = 0;
Jean92 0:af7b948d1f33 60 this->m_speed = 0.0;
Jean92 0:af7b948d1f33 61 }
Jean92 0:af7b948d1f33 62 }
Jean92 0:af7b948d1f33 63
Jean92 0:af7b948d1f33 64 /** Etat marche (running state) */
Jean92 0:af7b948d1f33 65 bool yMOTOR::Run() {
Jean92 0:af7b948d1f33 66 return (abs(this->m_speed) > yDB_def);
Jean92 0:af7b948d1f33 67 }
Jean92 0:af7b948d1f33 68
Jean92 0:af7b948d1f33 69 /** Vitesse effective */
Jean92 0:af7b948d1f33 70 float yMOTOR::Velocity() {
Jean92 0:af7b948d1f33 71 return this->m_speed;
Jean92 0:af7b948d1f33 72 }
Jean92 0:af7b948d1f33 73
Jean92 0:af7b948d1f33 74 /** Destructeur */
Jean92 0:af7b948d1f33 75 yMOTOR::~yMOTOR()
Jean92 0:af7b948d1f33 76 { // ne rien mettre ici
Jean92 0:af7b948d1f33 77 }
Jean92 1:4dc14e8e5ff7 78 /* mbed yMOTOR Library
Jean92 1:4dc14e8e5ff7 79 * Copyright (c) 2015 Jean92, https://developer.mbed.org/users/Jean92/
Jean92 1:4dc14e8e5ff7 80 *
Jean92 1:4dc14e8e5ff7 81 * Permission is hereby granted, free of charge, to any person obtaining a copy
Jean92 1:4dc14e8e5ff7 82 * of this software and associated documentation files (the "Software"), to deal
Jean92 1:4dc14e8e5ff7 83 * in the Software without restriction, including without limitation the rights
Jean92 1:4dc14e8e5ff7 84 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Jean92 1:4dc14e8e5ff7 85 * copies of the Software, and to permit persons to whom the Software is
Jean92 1:4dc14e8e5ff7 86 * furnished to do so, subject to the following conditions:
Jean92 1:4dc14e8e5ff7 87 *
Jean92 1:4dc14e8e5ff7 88 * The above copyright notice and this permission notice shall be included in
Jean92 1:4dc14e8e5ff7 89 * all copies or substantial portions of the Software.
Jean92 1:4dc14e8e5ff7 90 *
Jean92 1:4dc14e8e5ff7 91 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Jean92 1:4dc14e8e5ff7 92 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Jean92 1:4dc14e8e5ff7 93 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Jean92 1:4dc14e8e5ff7 94 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Jean92 1:4dc14e8e5ff7 95 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Jean92 1:4dc14e8e5ff7 96 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Jean92 1:4dc14e8e5ff7 97 * THE SOFTWARE.
Jean92 1:4dc14e8e5ff7 98 */
Jean92 1:4dc14e8e5ff7 99 // MIT Licence
Jean92 1:4dc14e8e5ff7 100
Jean92 0:af7b948d1f33 101 /**
Jean92 0:af7b948d1f33 102 * @note \n
Jean92 0:af7b948d1f33 103 * That's all folks!
Jean92 0:af7b948d1f33 104 */
Jean92 0:af7b948d1f33 105