Code for the car to drive in a figure eight motion

Dependencies:   mbed-rtos mbed MODSERIAL mbed-dsp telemetry

Committer:
ericoneill
Date:
Thu Mar 19 05:21:34 2015 +0000
Revision:
7:62ebacf26446
Parent:
5:764c2ffb523a
Child:
9:d3909d9325e4
MORE ENCODER STUFF

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 5:764c2ffb523a 5
ericoneill 5:764c2ffb523a 6 public:
ericoneill 5:764c2ffb523a 7 void velocity_control(float duty_cyc, float tuning_const);
ericoneill 5:764c2ffb523a 8 void fallInterrupt();
ericoneill 5:764c2ffb523a 9 void riseInterrupt();
ericoneill 5:764c2ffb523a 10 private:
ericoneill 7:62ebacf26446 11 //Observed average speeds for each duty cycle
ericoneill 7:62ebacf26446 12 const float TUNING_CONSTANT_20 = 3.00;
ericoneill 7:62ebacf26446 13 const float TUNING_CONSTANT_30 = 4.30;
ericoneill 7:62ebacf26446 14 const float TUNING_CONSTANT_50 = 6.880;
ericoneill 7:62ebacf26446 15 const float PI = 3.14159;
ericoneill 7:62ebacf26446 16 const float WHEEL_CIRCUMFERENCE = .05*PI;
ericoneill 7:62ebacf26446 17
ericoneill 7:62ebacf26446 18 //Velocity Control Tuning Constants
ericoneill 7:62ebacf26446 19 const float TUNE_THRESH = 0.5f;
ericoneill 7:62ebacf26446 20 const float TUNE_AMT = 0.1f;
ericoneill 7:62ebacf26446 21
ericoneill 5:764c2ffb523a 22 //Intervals used during encoder data collection to measure velocity
ericoneill 5:764c2ffb523a 23 int interval1=0;
ericoneill 5:764c2ffb523a 24 int interval2=0;
ericoneill 5:764c2ffb523a 25 int interval3=0;
ericoneill 5:764c2ffb523a 26 int avg_interval=0;
ericoneill 5:764c2ffb523a 27 int lastchange1 = 0;
ericoneill 5:764c2ffb523a 28 int lastchange2 = 0;
ericoneill 5:764c2ffb523a 29 int lastchange3 = 0;
ericoneill 5:764c2ffb523a 30 int lastchange4 = 0;
ericoneill 5:764c2ffb523a 31
ericoneill 5:764c2ffb523a 32 //Variables used to for velocity control
ericoneill 5:764c2ffb523a 33 float avg_speed = 0;
ericoneill 5:764c2ffb523a 34 float stall_check = 0;
ericoneill 5:764c2ffb523a 35 float tuning_val = 1;
ericoneill 5:764c2ffb523a 36
ericoneill 7:62ebacf26446 37 // Servo parameters
ericoneill 7:62ebacf26446 38 float lastTurnTime = 0.0f;
ericoneill 7:62ebacf26446 39 bool servoLeft = true;
ericoneill 7:62ebacf26446 40
ericoneill 7:62ebacf26446 41 //Parameters specifying sample sizes and delays for small and large average speed samples
ericoneill 7:62ebacf26446 42 float num_samples_small = 10.0f;
ericoneill 7:62ebacf26446 43 float delay_small = 0.05f;
ericoneill 7:62ebacf26446 44 float num_samples_large = 100.0f;
ericoneill 7:62ebacf26446 45 float delay_large = 0.1f;
ericoneill 7:62ebacf26446 46
ericoneill 7:62ebacf26446 47 // Large and small arrays used to get average velocity values
ericoneill 7:62ebacf26446 48 float large_avg_speed_list [100];
ericoneill 7:62ebacf26446 49 float small_avg_speed_list [10];
ericoneill 5:764c2ffb523a 50 float get_speed();
ericoneill 5:764c2ffb523a 51 float get_avg_speed(float num_samples, float delay);
ericoneill 5:764c2ffb523a 52
ericoneill 5:764c2ffb523a 53
ericoneill 5:764c2ffb523a 54
ericoneill 5:764c2ffb523a 55 }