Christian Burri / Mbed 2 deprecated autonomous Robot Android

Dependencies:   mbed

Fork of autonomous Robot Android by Christian Burri

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MaxonESCON.cpp Source File

MaxonESCON.cpp

00001 #include "MaxonESCON.h"
00002 
00003 using namespace std;
00004 
00005 MaxonESCON::MaxonESCON(
00006     PinName enb,
00007     PinName isenb,
00008     PinName pwm,
00009     PinName actualSpeed,
00010     Hallsensor *hall
00011 )
00012     :
00013     _enb(enb),
00014     _isenb(isenb),
00015     _pwm(pwm),
00016     _actualSpeed(actualSpeed),
00017     _hall(hall)
00018 {
00019 
00020     _pwm = 0;
00021 
00022     // Initial condition of output enables
00023     _enb = 0;
00024 
00025     // Set initial condition of PWM 2kHz
00026     period(0.0005);
00027 
00028     // Set the pulses to zero
00029     _pulses = 0;
00030 
00031     // Set the Pull Up Resistor
00032     _isenb.mode(PullUp);
00033 }
00034 
00035 void MaxonESCON::setVelocity(float speed)
00036 {
00037     speed = speed / ESCON_SET_FACTOR * 60.0f;
00038     if(speed > 1 ) {
00039         _pwm = 0.89f;
00040     } else if(speed < -1) {
00041         _pwm = 0.11f;
00042     } else {
00043         _pwm = 0.4f*speed + (0.5f * (SET_SPEED_PATCH));
00044     }
00045 }
00046 
00047 float MaxonESCON::getActualSpeed(void)
00048 {
00049     return (_actualSpeed.read()* 2.0f - 1.0f *(GET_SPEED_PATCH)) * ESCON_GET_FACTOR / 60.0f;
00050 }
00051 
00052 void MaxonESCON::period(float period)
00053 {
00054     _pwm.period(period);
00055 }
00056 
00057 void MaxonESCON::enable(bool enb)
00058 {
00059     if(enb == true) {
00060         _enb = 1;
00061     } else {
00062         _enb = 0;
00063     }
00064 }
00065 
00066 bool MaxonESCON::isEnabled()
00067 {
00068     if(_isenb.read() == 1) {
00069         return true;
00070     } else {
00071         return false;
00072     }
00073 }
00074 
00075 int MaxonESCON::getPulses(void)
00076 {
00077     _pulses = _hall->getPulses();
00078     return _pulses;
00079 }
00080 
00081 int MaxonESCON::setPulses(int setPos)
00082 {
00083     _hall->reset();
00084     _pulses = _hall->getPulses();
00085     return _pulses;
00086 }