Eimantas Bernotavicius / Mbed 2 deprecated Buggy_Project

Dependencies:   QEI mbed

encoderBase.cpp

Committer:
Weranest
Date:
2018-02-16
Revision:
2:7f4be54c7257
Parent:
1:12f18cede014
Child:
3:c9df852ad9ac

File content as of revision 2:7f4be54c7257:

#include "mbed.h"
#include "QEI.h"
#include "pins.cpp"
#define ENCODER_PULSE 256 //per manual
#define GEAR_RATIO 
#define SAMPLE_TIME 1.0f //user defined
#define WHEEL_DISTANCE //need to measure that

//these lines setup the encoders for both wheels
QEI encoderRight(channelARight, channelBRight, channelIRight, ENCODER_PULSE);
QEI encoderLeft(channelALeft, channelBLeft, channelILeft, ENCODER_PULSE);

//main wheel class, the subclasses should follow later
class Wheel{
    int currentPulses, previousPulses;
    public:
        float velocity(){
            return encoderVelocity*GEAR_RATIO;
        }
    private:
        float sampleTime= SAMPLE_TIME;
        int gearRatio = GEAR_RATIO;
        float encoderVelocity(encoderPulse){
            wait(sampleTIme);
            previousEncoderPulses=currentEncoderPulses;
            currentEncoderPulses=encoderPulse;
        }

} wheelRight, wheelLeft;

class WheelLeft

//call this for speed, linear and angular
class Buggy{
    public:
        float speedLinear(){
            return (wheelRight.velocity()+wheelLeft.velocity())/2;
            }
        float speedAngular(){
            return (wheelRight.velocity()-wheelLeft.velocity())/WHEEL_DISTANCE;
            }
    }buggy;
    
int speedMeasure(int encoderSide){
        wheelRight.currentPulses(&encoderRight.getPulses());
        wheelLeft.currentPulses(&encoderLeft.getPulses());
    }//set this as an interupt routine on the timer based on SAMPLE_TIME