Gestion pont-H pour moteur CC

yMOTOR.cpp

Committer:
Jean92
Date:
2015-09-12
Revision:
1:4dc14e8e5ff7
Parent:
0:af7b948d1f33
Child:
2:980b46615b6e

File content as of revision 1:4dc14e8e5ff7:

/* mbed yMOTOR Library
 * Copyright (c) 2015 Jean92, https://developer.mbed.org/users/Jean92/
 */
 /**
 * @file    yMOTOR.cpp
 * @brief   Class 'yMOTOR'
 * @version V0.2
 * @date    Sept-2015
 * @note    by Jean92 \n
 *          Controlleur pour Pont-H (MC33886)" \n
 *
 */
#include "mbed.h"
#include "yMOTOR.h"

/** Constructeur de la class yMOTOR */
yMOTOR::yMOTOR(PinName pwm, PinName av, PinName ar):
                _pwm(pwm), _av(av), _ar(ar) {
     // init PWM
    _pwm.period(yPeriod_def);
    _pwm = 0.0;
    
    // moteur a l'arret
    _ar = 0;
    _av = 0;

    // memory of speed
    this->m_speed = 0.0;
}

/** Traiter le changement de vitesse */
void yMOTOR::Speed(float speed) {
    if (abs(speed) < yDB_def) {     // stop motor
        _ar = 0;
        _av = 0;
        _pwm = 0.0;
        this->m_speed = 0.0;
    }
    else {
        _av = (speed > yDB_def);
        _ar = (speed < -yDB_def);
        _pwm = abs(speed);
        this->m_speed = speed;
    } 
} 

/** Changer la periode de PWM */
void yMOTOR::Period(float seconds) {
    _pwm.period(seconds);
}

/** Marche/Arret request */
void yMOTOR::MarArr(int mararr) {
    if (mararr == yMARCHE) {
        Speed(this->m_speed);
    }
    else if (mararr == yARRET) {
        _ar = 0;
        _av = 0;
        this->m_speed = 0.0;
    }
}

/** Etat marche (running state) */
bool yMOTOR::Run() {
    return (abs(this->m_speed) > yDB_def);
}

/** Vitesse effective */
float yMOTOR::Velocity() {
    return this->m_speed;   
}

/** Destructeur */
yMOTOR::~yMOTOR()
{ // ne rien mettre ici
}
/* mbed yMOTOR Library
 * Copyright (c) 2015 Jean92, https://developer.mbed.org/users/Jean92/
 *
 * 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.
 */
 // MIT Licence
 
/**
 * @note \n
 *         That's all folks!
 */