Gestion pont-H pour moteur CC

Committer:
Jean92
Date:
Tue Sep 15 19:25:32 2015 +0000
Revision:
4:3dce01a56e06
Parent:
3:5181bcf1f0a6
v0.7

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 4:3dce01a56e06 7 * @version V0.7
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 2:980b46615b6e 19 // herite de PWM et DO
Jean92 4:3dce01a56e06 20 // init PWM, init deadband
Jean92 4:3dce01a56e06 21 this->m_DB = yDB_def;
Jean92 0:af7b948d1f33 22 _pwm.period(yPeriod_def);
Jean92 0:af7b948d1f33 23 _pwm = 0.0;
Jean92 0:af7b948d1f33 24
Jean92 0:af7b948d1f33 25 // moteur a l'arret
Jean92 0:af7b948d1f33 26 _ar = 0;
Jean92 0:af7b948d1f33 27 _av = 0;
Jean92 2:980b46615b6e 28 this->m_run = 0;
Jean92 0:af7b948d1f33 29
Jean92 0:af7b948d1f33 30 // memory of speed
Jean92 0:af7b948d1f33 31 this->m_speed = 0.0;
Jean92 0:af7b948d1f33 32 }
Jean92 0:af7b948d1f33 33
Jean92 0:af7b948d1f33 34 /** Traiter le changement de vitesse */
Jean92 0:af7b948d1f33 35 void yMOTOR::Speed(float speed) {
Jean92 2:980b46615b6e 36 if (this->m_run) { // moteur running?
Jean92 4:3dce01a56e06 37 if (abs(speed) < this->m_DB) { // oui, consigne suffisante?
Jean92 2:980b46615b6e 38 _ar = 0; // non, les 2 cdes à zéro
Jean92 2:980b46615b6e 39 _av = 0;
Jean92 2:980b46615b6e 40 _pwm = 0.0; // reset PWM
Jean92 2:980b46615b6e 41 this->m_speed = 0.0; // memoriser vitesse nulle
Jean92 2:980b46615b6e 42 }
Jean92 4:3dce01a56e06 43 else { // oui, en dehors de la bande morte
Jean92 4:3dce01a56e06 44 _av = (speed > this->m_DB); // en avant
Jean92 4:3dce01a56e06 45 _ar = (speed < -this->m_DB); // ou en arriere
Jean92 4:3dce01a56e06 46 _pwm = abs(speed); // a la vitesse demandée
Jean92 4:3dce01a56e06 47 this->m_speed = speed; // memoire vitesse
Jean92 2:980b46615b6e 48 }
Jean92 0:af7b948d1f33 49 }
Jean92 0:af7b948d1f33 50 }
Jean92 0:af7b948d1f33 51
Jean92 0:af7b948d1f33 52 /** Changer la periode de PWM */
Jean92 0:af7b948d1f33 53 void yMOTOR::Period(float seconds) {
Jean92 0:af7b948d1f33 54 _pwm.period(seconds);
Jean92 0:af7b948d1f33 55 }
Jean92 0:af7b948d1f33 56
Jean92 4:3dce01a56e06 57 /** Change DeadBand */
Jean92 4:3dce01a56e06 58 void yMOTOR::DeadBand(float db) {
Jean92 4:3dce01a56e06 59 this->m_DB = db;
Jean92 4:3dce01a56e06 60 }
Jean92 4:3dce01a56e06 61
Jean92 0:af7b948d1f33 62 /** Marche/Arret request */
Jean92 0:af7b948d1f33 63 void yMOTOR::MarArr(int mararr) {
Jean92 0:af7b948d1f33 64 if (mararr == yMARCHE) {
Jean92 4:3dce01a56e06 65 this->m_run = 1; // memoriser l'état
Jean92 2:980b46615b6e 66 Speed(this->m_speed); // appliquer la vitesse demandée
Jean92 0:af7b948d1f33 67 }
Jean92 0:af7b948d1f33 68 else if (mararr == yARRET) {
Jean92 2:980b46615b6e 69 _ar = 0; // mettre les 2 cdes a zero
Jean92 2:980b46615b6e 70 _av = 0; // ==> arret rotation
Jean92 2:980b46615b6e 71 this->m_run = 0; // memoriser l'état
Jean92 2:980b46615b6e 72 // sans changer memoire vitesse
Jean92 0:af7b948d1f33 73 }
Jean92 0:af7b948d1f33 74 }
Jean92 0:af7b948d1f33 75
Jean92 0:af7b948d1f33 76 /** Etat marche (running state) */
Jean92 0:af7b948d1f33 77 bool yMOTOR::Run() {
Jean92 2:980b46615b6e 78 //return (abs(this->m_speed) > yDB_def);
Jean92 2:980b46615b6e 79 //return (_av != _ar); //Marche si av et ar non nul
Jean92 2:980b46615b6e 80 return this->m_run; // repondre de mémoire!
Jean92 0:af7b948d1f33 81 }
Jean92 0:af7b948d1f33 82
Jean92 0:af7b948d1f33 83 /** Vitesse effective */
Jean92 0:af7b948d1f33 84 float yMOTOR::Velocity() {
Jean92 0:af7b948d1f33 85 return this->m_speed;
Jean92 0:af7b948d1f33 86 }
Jean92 0:af7b948d1f33 87
Jean92 0:af7b948d1f33 88 /** Destructeur */
Jean92 0:af7b948d1f33 89 yMOTOR::~yMOTOR()
Jean92 0:af7b948d1f33 90 { // ne rien mettre ici
Jean92 0:af7b948d1f33 91 }
Jean92 1:4dc14e8e5ff7 92 /* mbed yMOTOR Library
Jean92 1:4dc14e8e5ff7 93 * Copyright (c) 2015 Jean92, https://developer.mbed.org/users/Jean92/
Jean92 1:4dc14e8e5ff7 94 *
Jean92 1:4dc14e8e5ff7 95 * Permission is hereby granted, free of charge, to any person obtaining a copy
Jean92 1:4dc14e8e5ff7 96 * of this software and associated documentation files (the "Software"), to deal
Jean92 1:4dc14e8e5ff7 97 * in the Software without restriction, including without limitation the rights
Jean92 1:4dc14e8e5ff7 98 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Jean92 1:4dc14e8e5ff7 99 * copies of the Software, and to permit persons to whom the Software is
Jean92 1:4dc14e8e5ff7 100 * furnished to do so, subject to the following conditions:
Jean92 1:4dc14e8e5ff7 101 *
Jean92 1:4dc14e8e5ff7 102 * The above copyright notice and this permission notice shall be included in
Jean92 1:4dc14e8e5ff7 103 * all copies or substantial portions of the Software.
Jean92 1:4dc14e8e5ff7 104 *
Jean92 1:4dc14e8e5ff7 105 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Jean92 1:4dc14e8e5ff7 106 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Jean92 1:4dc14e8e5ff7 107 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Jean92 1:4dc14e8e5ff7 108 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Jean92 1:4dc14e8e5ff7 109 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Jean92 1:4dc14e8e5ff7 110 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Jean92 1:4dc14e8e5ff7 111 * THE SOFTWARE.
Jean92 1:4dc14e8e5ff7 112 */
Jean92 1:4dc14e8e5ff7 113 // MIT Licence
Jean92 1:4dc14e8e5ff7 114
Jean92 0:af7b948d1f33 115 /**
Jean92 0:af7b948d1f33 116 * @note \n
Jean92 0:af7b948d1f33 117 * That's all folks!
Jean92 0:af7b948d1f33 118 */
Jean92 0:af7b948d1f33 119