Gestion pont-H pour moteur CC

Committer:
Jean92
Date:
Sat Sep 12 12:41:43 2015 +0000
Revision:
0:af7b948d1f33
Child:
1:4dc14e8e5ff7
1st commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jean92 0:af7b948d1f33 1 /**
Jean92 0:af7b948d1f33 2 * @file yMOTOR.cpp
Jean92 0:af7b948d1f33 3 * @brief Class 'yMOTOR'
Jean92 0:af7b948d1f33 4 * @version V0.1
Jean92 0:af7b948d1f33 5 * @date 12-Sept-2015
Jean92 0:af7b948d1f33 6 * @note by Jean92 \n
Jean92 0:af7b948d1f33 7 * Controlleur pour Pont-H (MC33886)" \n
Jean92 0:af7b948d1f33 8 *
Jean92 0:af7b948d1f33 9 */
Jean92 0:af7b948d1f33 10 #include "mbed.h"
Jean92 0:af7b948d1f33 11 #include "yMOTOR.h"
Jean92 0:af7b948d1f33 12
Jean92 0:af7b948d1f33 13 /** Constructeur de la class yMOTOR */
Jean92 0:af7b948d1f33 14 yMOTOR::yMOTOR(PinName pwm, PinName av, PinName ar):
Jean92 0:af7b948d1f33 15 _pwm(pwm), _av(av), _ar(ar) {
Jean92 0:af7b948d1f33 16 // init PWM
Jean92 0:af7b948d1f33 17 _pwm.period(yPeriod_def);
Jean92 0:af7b948d1f33 18 _pwm = 0.0;
Jean92 0:af7b948d1f33 19
Jean92 0:af7b948d1f33 20 // moteur a l'arret
Jean92 0:af7b948d1f33 21 _ar = 0;
Jean92 0:af7b948d1f33 22 _av = 0;
Jean92 0:af7b948d1f33 23
Jean92 0:af7b948d1f33 24 // memory of speed
Jean92 0:af7b948d1f33 25 this->m_speed = 0.0;
Jean92 0:af7b948d1f33 26 }
Jean92 0:af7b948d1f33 27
Jean92 0:af7b948d1f33 28 /** Traiter le changement de vitesse */
Jean92 0:af7b948d1f33 29 void yMOTOR::Speed(float speed) {
Jean92 0:af7b948d1f33 30 if (abs(speed) < yDB_def) { // stop motor
Jean92 0:af7b948d1f33 31 _ar = 0;
Jean92 0:af7b948d1f33 32 _av = 0;
Jean92 0:af7b948d1f33 33 _pwm = 0.0;
Jean92 0:af7b948d1f33 34 this->m_speed = 0.0;
Jean92 0:af7b948d1f33 35 }
Jean92 0:af7b948d1f33 36 else {
Jean92 0:af7b948d1f33 37 _av = (speed > yDB_def);
Jean92 0:af7b948d1f33 38 _ar = (speed < -yDB_def);
Jean92 0:af7b948d1f33 39 _pwm = abs(speed);
Jean92 0:af7b948d1f33 40 this->m_speed = speed;
Jean92 0:af7b948d1f33 41 }
Jean92 0:af7b948d1f33 42 }
Jean92 0:af7b948d1f33 43
Jean92 0:af7b948d1f33 44 /** Changer la periode de PWM */
Jean92 0:af7b948d1f33 45 void yMOTOR::Period(float seconds) {
Jean92 0:af7b948d1f33 46 _pwm.period(seconds);
Jean92 0:af7b948d1f33 47 }
Jean92 0:af7b948d1f33 48
Jean92 0:af7b948d1f33 49 /** Marche/Arret request */
Jean92 0:af7b948d1f33 50 void yMOTOR::MarArr(int mararr) {
Jean92 0:af7b948d1f33 51 if (mararr == yMARCHE) {
Jean92 0:af7b948d1f33 52 Speed(this->m_speed);
Jean92 0:af7b948d1f33 53 }
Jean92 0:af7b948d1f33 54 else if (mararr == yARRET) {
Jean92 0:af7b948d1f33 55 _ar = 0;
Jean92 0:af7b948d1f33 56 _av = 0;
Jean92 0:af7b948d1f33 57 this->m_speed = 0.0;
Jean92 0:af7b948d1f33 58 }
Jean92 0:af7b948d1f33 59 }
Jean92 0:af7b948d1f33 60
Jean92 0:af7b948d1f33 61 /** Etat marche (running state) */
Jean92 0:af7b948d1f33 62 bool yMOTOR::Run() {
Jean92 0:af7b948d1f33 63 return (abs(this->m_speed) > yDB_def);
Jean92 0:af7b948d1f33 64 }
Jean92 0:af7b948d1f33 65
Jean92 0:af7b948d1f33 66 /** Vitesse effective */
Jean92 0:af7b948d1f33 67 float yMOTOR::Velocity() {
Jean92 0:af7b948d1f33 68 return this->m_speed;
Jean92 0:af7b948d1f33 69 }
Jean92 0:af7b948d1f33 70
Jean92 0:af7b948d1f33 71 /** Destructeur */
Jean92 0:af7b948d1f33 72 yMOTOR::~yMOTOR()
Jean92 0:af7b948d1f33 73 { // ne rien mettre ici
Jean92 0:af7b948d1f33 74 }
Jean92 0:af7b948d1f33 75
Jean92 0:af7b948d1f33 76 /**
Jean92 0:af7b948d1f33 77 * @note \n
Jean92 0:af7b948d1f33 78 * That's all folks!
Jean92 0:af7b948d1f33 79 */
Jean92 0:af7b948d1f33 80