Gestion pont-H pour moteur CC

Committer:
Jean92
Date:
Sun Sep 13 15:55:29 2015 +0000
Revision:
3:5181bcf1f0a6
Parent:
2:980b46615b6e
Child:
4:3dce01a56e06
v0.5

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