Eimantas Bernotavicius / Mbed 2 deprecated Buggy_Project

Dependencies:   QEI mbed

Committer:
Weranest
Date:
Thu Feb 22 17:01:00 2018 +0000
Revision:
4:48d390356fba
Parent:
3:c9df852ad9ac
Tech Demo version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Weranest 2:7f4be54c7257 1 #include "mbed.h"
Weranest 0:62e51b80d738 2 #include "QEI.h"
Weranest 3:c9df852ad9ac 3 #include "pins.h"
Weranest 4:48d390356fba 4 #include "constants.cpp"
Weranest 3:c9df852ad9ac 5
Weranest 0:62e51b80d738 6
Weranest 0:62e51b80d738 7 //these lines setup the encoders for both wheels
Weranest 0:62e51b80d738 8
Weranest 0:62e51b80d738 9 //main wheel class, the subclasses should follow later
Weranest 0:62e51b80d738 10 class Wheel{
Weranest 0:62e51b80d738 11 int currentPulses, previousPulses;
Weranest 0:62e51b80d738 12 public:
Weranest 3:c9df852ad9ac 13 float velocity(int wheelPulses){
Weranest 3:c9df852ad9ac 14 return encoderVelocity(wheelPulses)*GEAR_RATIO;
Weranest 0:62e51b80d738 15 }
Weranest 0:62e51b80d738 16 private:
Weranest 3:c9df852ad9ac 17 float encoderVelocity(int encoderPulse){
Weranest 3:c9df852ad9ac 18 wait(SAMPLE_TIME);
Weranest 3:c9df852ad9ac 19 previousPulses=currentPulses;
Weranest 3:c9df852ad9ac 20 currentPulses=encoderPulse;
Weranest 3:c9df852ad9ac 21 return (currentPulses-previousPulses)/SAMPLE_TIME;
Weranest 0:62e51b80d738 22 }
Weranest 1:12f18cede014 23
Weranest 0:62e51b80d738 24 } wheelRight, wheelLeft;
Weranest 0:62e51b80d738 25
Weranest 0:62e51b80d738 26 //call this for speed, linear and angular
Weranest 0:62e51b80d738 27 class Buggy{
Weranest 0:62e51b80d738 28 public:
Weranest 3:c9df852ad9ac 29 float speedLinear(int pulseRight, int pulseLeft){
Weranest 3:c9df852ad9ac 30 return (wheelRight.velocity(pulseRight)+wheelLeft.velocity(pulseLeft))/2;
Weranest 0:62e51b80d738 31 }
Weranest 3:c9df852ad9ac 32 float speedAngular(int pulseRight, int pulseLeft){
Weranest 3:c9df852ad9ac 33 return (wheelRight.velocity(pulseRight)-wheelLeft.velocity(pulseLeft))/WHEEL_DISTANCE;
Weranest 0:62e51b80d738 34 }
Weranest 2:7f4be54c7257 35 }buggy;
Weranest 4:48d390356fba 36 //temp functions to get the encoder speed
Weranest 4:48d390356fba 37 int encoderVelocityLeft(){
Weranest 4:48d390356fba 38 return wheelLeft.velocity(encoderLeft.getPulses());
Weranest 4:48d390356fba 39 }
Weranest 4:48d390356fba 40 int encoderVelocityRight(){
Weranest 4:48d390356fba 41 return wheelRight.velocity(encoderRight.getPulses());
Weranest 4:48d390356fba 42 }