Code for the car to drive in a figure eight motion

Dependencies:   mbed-rtos mbed MODSERIAL mbed-dsp telemetry

Committer:
ericoneill
Date:
Fri Mar 20 00:11:29 2015 +0000
Revision:
9:d3909d9325e4
Parent:
7:62ebacf26446
Child:
11:f8aa39c19477
UPDATE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ericoneill 5:764c2ffb523a 1 #ifndef ENCODER_H
ericoneill 5:764c2ffb523a 2 #define ENCODER_H
ericoneill 5:764c2ffb523a 3
ericoneill 5:764c2ffb523a 4 class Statechart{
ericoneill 9:d3909d9325e4 5 //Intervals used during encoder data collection to measure velocity
ericoneill 9:d3909d9325e4 6 int interval1;
ericoneill 9:d3909d9325e4 7 int interval2;
ericoneill 9:d3909d9325e4 8 int interval3;
ericoneill 9:d3909d9325e4 9 int avg_interval;
ericoneill 9:d3909d9325e4 10 int lastchange1;
ericoneill 9:d3909d9325e4 11 int lastchange2;
ericoneill 9:d3909d9325e4 12 int lastchange3;
ericoneill 9:d3909d9325e4 13 int lastchange4;
ericoneill 9:d3909d9325e4 14
ericoneill 9:d3909d9325e4 15 //Variables used to for velocity control
ericoneill 9:d3909d9325e4 16 float avg_speed;
ericoneill 9:d3909d9325e4 17 float stall_check;
ericoneill 9:d3909d9325e4 18 float tuning_val;
ericoneill 9:d3909d9325e4 19
ericoneill 9:d3909d9325e4 20 // Servo parameters
ericoneill 9:d3909d9325e4 21 float lastTurnTime;
ericoneill 9:d3909d9325e4 22 bool servoLeft;
ericoneill 9:d3909d9325e4 23
ericoneill 9:d3909d9325e4 24 //Parameters specifying sample sizes and delays for small and large average speed samples
ericoneill 9:d3909d9325e4 25 float num_samples_small;
ericoneill 9:d3909d9325e4 26 float delay_small;
ericoneill 9:d3909d9325e4 27 float num_samples_large;
ericoneill 9:d3909d9325e4 28 float delay_large;
ericoneill 9:d3909d9325e4 29
ericoneill 9:d3909d9325e4 30 // Large and small arrays used to get average velocity values
ericoneill 9:d3909d9325e4 31 float large_avg_speed_list [100];
ericoneill 9:d3909d9325e4 32 float small_avg_speed_list [10];
ericoneill 5:764c2ffb523a 33 public:
ericoneill 9:d3909d9325e4 34 Rectangle();
ericoneill 5:764c2ffb523a 35 void velocity_control(float duty_cyc, float tuning_const);
ericoneill 5:764c2ffb523a 36 void fallInterrupt();
ericoneill 5:764c2ffb523a 37 void riseInterrupt();
ericoneill 5:764c2ffb523a 38 private:
ericoneill 9:d3909d9325e4 39 // Internal functions
ericoneill 5:764c2ffb523a 40 float get_speed();
ericoneill 5:764c2ffb523a 41 float get_avg_speed(float num_samples, float delay);
ericoneill 5:764c2ffb523a 42
ericoneill 5:764c2ffb523a 43
ericoneill 5:764c2ffb523a 44
ericoneill 9:d3909d9325e4 45 };
ericoneill 9:d3909d9325e4 46
ericoneill 9:d3909d9325e4 47 Encoder::Encoder(){
ericoneill 9:d3909d9325e4 48
ericoneill 9:d3909d9325e4 49 //Initialize Intervals used during encoder data collection to measure velocity
ericoneill 9:d3909d9325e4 50 interval1=0;
ericoneill 9:d3909d9325e4 51 interval2=0;
ericoneill 9:d3909d9325e4 52 interval3=0;
ericoneill 9:d3909d9325e4 53 avg_interval=0;
ericoneill 9:d3909d9325e4 54 lastchange1 = 0;
ericoneill 9:d3909d9325e4 55 lastchange2 = 0;
ericoneill 9:d3909d9325e4 56 lastchange3 = 0;
ericoneill 9:d3909d9325e4 57 lastchange4 = 0;
ericoneill 9:d3909d9325e4 58
ericoneill 9:d3909d9325e4 59 //Initialize Variables used to for velocity control
ericoneill 9:d3909d9325e4 60 avg_speed = 0;
ericoneill 9:d3909d9325e4 61 stall_check = 0;
ericoneill 9:d3909d9325e4 62 tuning_val = 1;
ericoneill 9:d3909d9325e4 63
ericoneill 9:d3909d9325e4 64 // Servo parameters
ericoneill 9:d3909d9325e4 65 lastTurnTime = 0.0f;
ericoneill 9:d3909d9325e4 66 servoLeft = true;
ericoneill 9:d3909d9325e4 67
ericoneill 9:d3909d9325e4 68 //Parameters specifying sample sizes and delays for small and large average speed samples
ericoneill 9:d3909d9325e4 69 num_samples_small = 10.0f;
ericoneill 9:d3909d9325e4 70 delay_small = 0.05f;
ericoneill 9:d3909d9325e4 71 num_samples_large = 100.0f;
ericoneill 9:d3909d9325e4 72 delay_large = 0.1f;
ericoneill 9:d3909d9325e4 73
ericoneill 9:d3909d9325e4 74 }
ericoneill 9:d3909d9325e4 75 #endif