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-20
- Revision:
- 9:d3909d9325e4
- Parent:
- 7:62ebacf26446
- Child:
- 11:f8aa39c19477
File content as of revision 9:d3909d9325e4:
#ifndef ENCODER_H #define ENCODER_H class Statechart{ //Intervals used during encoder data collection to measure velocity int interval1; int interval2; int interval3; int avg_interval; int lastchange1; int lastchange2; int lastchange3; int lastchange4; //Variables used to for velocity control float avg_speed; float stall_check; float tuning_val; // Servo parameters float lastTurnTime; bool servoLeft; //Parameters specifying sample sizes and delays for small and large average speed samples float num_samples_small; float delay_small; float num_samples_large; float delay_large; // Large and small arrays used to get average velocity values float large_avg_speed_list [100]; float small_avg_speed_list [10]; public: Rectangle(); void velocity_control(float duty_cyc, float tuning_const); void fallInterrupt(); void riseInterrupt(); private: // Internal functions float get_speed(); float get_avg_speed(float num_samples, float delay); }; Encoder::Encoder(){ //Initialize Intervals used during encoder data collection to measure velocity interval1=0; interval2=0; interval3=0; avg_interval=0; lastchange1 = 0; lastchange2 = 0; lastchange3 = 0; lastchange4 = 0; //Initialize Variables used to for velocity control avg_speed = 0; stall_check = 0; tuning_val = 1; // Servo parameters lastTurnTime = 0.0f; servoLeft = true; //Parameters specifying sample sizes and delays for small and large average speed samples num_samples_small = 10.0f; delay_small = 0.05f; num_samples_large = 100.0f; delay_large = 0.1f; } #endif