Eimantas Bernotavicius / Mbed 2 deprecated Buggy_Project

Dependencies:   QEI mbed

Committer:
Weranest
Date:
Thu Feb 15 13:19:37 2018 +0000
Revision:
0:62e51b80d738
Child:
1:12f18cede014
Test commit please ignore

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Weranest 0:62e51b80d738 1 #include "mbed.h"
Weranest 0:62e51b80d738 2 #include "QEI.h"
Weranest 0:62e51b80d738 3 #include "pins.cpp"
Weranest 0:62e51b80d738 4 #define ENCODER_PULSE 256 //per manual
Weranest 0:62e51b80d738 5 #define GEAR_RATIO
Weranest 0:62e51b80d738 6 #define SAMPLE_TIME //user defined
Weranest 0:62e51b80d738 7 #define WHEEL_DISTANCE //need to measure that
Weranest 0:62e51b80d738 8
Weranest 0:62e51b80d738 9 //these lines setup the encoders for both wheels
Weranest 0:62e51b80d738 10 QEI encoderRight(channelARight, channelBRight, channelIRight, ENCODER_PULSE);
Weranest 0:62e51b80d738 11 QEI encoderLeft(channelALeft, channelBLeft, channelILeft, ENCODER_PULSE);
Weranest 0:62e51b80d738 12
Weranest 0:62e51b80d738 13 //main wheel class, the subclasses should follow later
Weranest 0:62e51b80d738 14 class Wheel{
Weranest 0:62e51b80d738 15 int currentPulses, previousPulses;
Weranest 0:62e51b80d738 16 public:
Weranest 0:62e51b80d738 17 float wheelVelocity(float, int){
Weranest 0:62e51b80d738 18 }
Weranest 0:62e51b80d738 19 private:
Weranest 0:62e51b80d738 20 float sampleTime= SAMPLE_TIME
Weranest 0:62e51b80d738 21 int gearRatio = GEAR_RATIO;
Weranest 0:62e51b80d738 22 float encoderVelocity(){
Weranest 0:62e51b80d738 23 return (currentEncoderTicks-previousEncoderTicks)/sampleTime;
Weranest 0:62e51b80d738 24 }
Weranest 0:62e51b80d738 25 int encoderTicks(){
Weranest 0:62e51b80d738 26 previousEncoderTicks=currentEncoderTicks;
Weranest 0:62e51b80d738 27 currentEncoderTicks=
Weranest 0:62e51b80d738 28 }
Weranest 0:62e51b80d738 29 } wheelRight, wheelLeft;
Weranest 0:62e51b80d738 30
Weranest 0:62e51b80d738 31 class WheelLeft
Weranest 0:62e51b80d738 32
Weranest 0:62e51b80d738 33 //call this for speed, linear and angular
Weranest 0:62e51b80d738 34 class Buggy{
Weranest 0:62e51b80d738 35 public:
Weranest 0:62e51b80d738 36 float speedLinear(float wheelVelocityRight, float wheelVelocityLeft){
Weranest 0:62e51b80d738 37 return (wheelVelocityRight+wheelVelocityLeft)/2;
Weranest 0:62e51b80d738 38 }
Weranest 0:62e51b80d738 39 float speedAngular(float wheelVelocityRight, float wheelVelocityLeft){
Weranest 0:62e51b80d738 40 return (wheelVelocityRight-wheelVelocityLeft)/WHEEL_DISTANCE;
Weranest 0:62e51b80d738 41 }
Weranest 0:62e51b80d738 42 }
Weranest 0:62e51b80d738 43
Weranest 0:62e51b80d738 44
Weranest 0:62e51b80d738 45
Weranest 0:62e51b80d738 46
Weranest 0:62e51b80d738 47
Weranest 0:62e51b80d738 48
Weranest 0:62e51b80d738 49
Weranest 0:62e51b80d738 50
Weranest 0:62e51b80d738 51
Weranest 0:62e51b80d738 52
Weranest 0:62e51b80d738 53
Weranest 0:62e51b80d738 54
Weranest 0:62e51b80d738 55
Weranest 0:62e51b80d738 56
Weranest 0:62e51b80d738 57
Weranest 0:62e51b80d738 58
Weranest 0:62e51b80d738 59
Weranest 0:62e51b80d738 60
Weranest 0:62e51b80d738 61
Weranest 0:62e51b80d738 62
Weranest 0:62e51b80d738 63
Weranest 0:62e51b80d738 64
Weranest 0:62e51b80d738 65
Weranest 0:62e51b80d738 66
Weranest 0:62e51b80d738 67
Weranest 0:62e51b80d738 68
Weranest 0:62e51b80d738 69
Weranest 0:62e51b80d738 70
Weranest 0:62e51b80d738 71
Weranest 0:62e51b80d738 72
Weranest 0:62e51b80d738 73
Weranest 0:62e51b80d738 74
Weranest 0:62e51b80d738 75
Weranest 0:62e51b80d738 76
Weranest 0:62e51b80d738 77 class Buggy{
Weranest 0:62e51b80d738 78 float speed =
Weranest 0:62e51b80d738 79 float angular =
Weranest 0:62e51b80d738 80 }buggy;