Code for the car to drive in a figure eight motion
Dependencies: mbed-rtos mbed MODSERIAL mbed-dsp telemetry
encoder.h@23:d8cacd996cce, 2015-03-20 (annotated)
- Committer:
- cheryl_he
- Date:
- Fri Mar 20 09:49:57 2015 +0000
- Revision:
- 23:d8cacd996cce
- Parent:
- 13:97708869a4ba
telemetry stuff is compiling, needs to be debugged
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ericoneill | 5:764c2ffb523a | 1 | #ifndef ENCODER_H |
ericoneill | 5:764c2ffb523a | 2 | #define ENCODER_H |
ericoneill | 5:764c2ffb523a | 3 | |
ericoneill | 13:97708869a4ba | 4 | #include "mbed.h" |
ericoneill | 13:97708869a4ba | 5 | |
ericoneill | 13:97708869a4ba | 6 | |
ericoneill | 11:f8aa39c19477 | 7 | class Encoder{ |
ericoneill | 13:97708869a4ba | 8 | Timer t; |
ericoneill | 13:97708869a4ba | 9 | |
ericoneill | 9:d3909d9325e4 | 10 | //Intervals used during encoder data collection to measure velocity |
ericoneill | 9:d3909d9325e4 | 11 | int interval1; |
ericoneill | 9:d3909d9325e4 | 12 | int interval2; |
ericoneill | 9:d3909d9325e4 | 13 | int interval3; |
ericoneill | 9:d3909d9325e4 | 14 | int avg_interval; |
ericoneill | 9:d3909d9325e4 | 15 | int lastchange1; |
ericoneill | 9:d3909d9325e4 | 16 | int lastchange2; |
ericoneill | 9:d3909d9325e4 | 17 | int lastchange3; |
ericoneill | 9:d3909d9325e4 | 18 | int lastchange4; |
ericoneill | 9:d3909d9325e4 | 19 | |
ericoneill | 9:d3909d9325e4 | 20 | //Variables used to for velocity control |
ericoneill | 9:d3909d9325e4 | 21 | float avg_speed; |
ericoneill | 9:d3909d9325e4 | 22 | float stall_check; |
ericoneill | 9:d3909d9325e4 | 23 | float tuning_val; |
ericoneill | 9:d3909d9325e4 | 24 | |
ericoneill | 9:d3909d9325e4 | 25 | // Servo parameters |
ericoneill | 9:d3909d9325e4 | 26 | float lastTurnTime; |
ericoneill | 9:d3909d9325e4 | 27 | bool servoLeft; |
ericoneill | 9:d3909d9325e4 | 28 | |
ericoneill | 9:d3909d9325e4 | 29 | //Parameters specifying sample sizes and delays for small and large average speed samples |
ericoneill | 9:d3909d9325e4 | 30 | float num_samples_small; |
ericoneill | 9:d3909d9325e4 | 31 | float delay_small; |
ericoneill | 9:d3909d9325e4 | 32 | float num_samples_large; |
ericoneill | 9:d3909d9325e4 | 33 | float delay_large; |
ericoneill | 9:d3909d9325e4 | 34 | |
ericoneill | 9:d3909d9325e4 | 35 | // Large and small arrays used to get average velocity values |
ericoneill | 9:d3909d9325e4 | 36 | float large_avg_speed_list [100]; |
ericoneill | 9:d3909d9325e4 | 37 | float small_avg_speed_list [10]; |
ericoneill | 5:764c2ffb523a | 38 | public: |
ericoneill | 13:97708869a4ba | 39 | Encoder(Timer t); |
ericoneill | 13:97708869a4ba | 40 | float velocity_control(float duty_cyc, float tuning_const); |
ericoneill | 5:764c2ffb523a | 41 | void fallInterrupt(); |
ericoneill | 5:764c2ffb523a | 42 | void riseInterrupt(); |
ericoneill | 5:764c2ffb523a | 43 | private: |
ericoneill | 9:d3909d9325e4 | 44 | // Internal functions |
ericoneill | 5:764c2ffb523a | 45 | float get_speed(); |
ericoneill | 5:764c2ffb523a | 46 | float get_avg_speed(float num_samples, float delay); |
ericoneill | 9:d3909d9325e4 | 47 | }; |
ericoneill | 9:d3909d9325e4 | 48 | |
ericoneill | 11:f8aa39c19477 | 49 | |
ericoneill | 9:d3909d9325e4 | 50 | #endif |