Code for the car to drive in a figure eight motion
Dependencies: mbed-rtos mbed MODSERIAL mbed-dsp telemetry
encoder.h
- Committer:
- ericoneill
- Date:
- 2015-03-19
- Revision:
- 7:62ebacf26446
- Parent:
- 5:764c2ffb523a
- Child:
- 9:d3909d9325e4
File content as of revision 7:62ebacf26446:
#ifndef ENCODER_H #define ENCODER_H class Statechart{ public: void velocity_control(float duty_cyc, float tuning_const); void fallInterrupt(); void riseInterrupt(); private: //Observed average speeds for each duty cycle const float TUNING_CONSTANT_20 = 3.00; const float TUNING_CONSTANT_30 = 4.30; const float TUNING_CONSTANT_50 = 6.880; const float PI = 3.14159; const float WHEEL_CIRCUMFERENCE = .05*PI; //Velocity Control Tuning Constants const float TUNE_THRESH = 0.5f; const float TUNE_AMT = 0.1f; //Intervals used during encoder data collection to measure velocity int interval1=0; int interval2=0; int interval3=0; int avg_interval=0; int lastchange1 = 0; int lastchange2 = 0; int lastchange3 = 0; int lastchange4 = 0; //Variables used to for velocity control float avg_speed = 0; float stall_check = 0; float tuning_val = 1; // Servo parameters float lastTurnTime = 0.0f; bool servoLeft = true; //Parameters specifying sample sizes and delays for small and large average speed samples float num_samples_small = 10.0f; float delay_small = 0.05f; float num_samples_large = 100.0f; float delay_large = 0.1f; // Large and small arrays used to get average velocity values float large_avg_speed_list [100]; float small_avg_speed_list [10]; float get_speed(); float get_avg_speed(float num_samples, float delay); }