Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 16:be88d07a24fe
- Parent:
- 14:a243e6a78b2c
- Child:
- 19:14b4b90bdf46
diff -r a243e6a78b2c -r be88d07a24fe main.cpp --- a/main.cpp Tue Mar 17 15:13:37 2015 +0000 +++ b/main.cpp Thu Mar 19 16:59:37 2015 +0000 @@ -26,6 +26,34 @@ float desired_duty_r; //USED FOR PD_CONTROL() SET IN set_dir() float desired_duty_l; +float pres_duty_r, pres_duty_l; +float a_ratio; +float desired_ratio; +float perc_r; +float perc_l; +float perc_tot; +float threshold; +float limit; +float inc_value; + +//HALL EFFECT INITIALISATIONS +Timer h_r, h_l; +float hall_rt1, hall_lt1, hall_rt2, hall_lt2 = 0; //hall right time & left time +float hall_rdt, hall_ldt; +int h_f_r, h_f_l; //hallflagright and left + +void init_PD () +{ + //all these values have to be global; this function gets called each time there's a new direction/desired speed + a_ratio = hall_ldt/hall_rdt; //actual_ratio + desired_ratio = desired_duty_l/desired_duty_r; //desired_duty comes from set_direction() + perc_r = (1-((desired_duty_r-0.1)/desired_duty_r));//absolute vlaue of +-0.1 duty means a differnt percentage error for each duty value + perc_l = (1-((desired_duty_l-0.1)/desired_duty_l)); + perc_tot = perc_r + perc_l; + threshold = desired_ratio*perc_tot; //dynamic threshold that will change according to duties + limit = 0.2*((desired_duty_l + desired_duty_r)/2); //twenty percent of the average duty + inc_value = 0.05*((desired_duty_l + desired_duty_r)/2); //probably need to change 5% from testing +} void set_direction( int direction, float duty_l, float duty_r) { desired_duty_r = duty_r; //USED FOR PD_CONTROL() @@ -81,11 +109,8 @@ init_PD (); } -//HALL EFFECT INITIALISATIONS -Timer h_r, h_l; -float hall_rt1, hall_lt1, hall_rt2, hall_lt2 = 0; //hall right time & left time -float hall_rdt, hall_ldt; -int h_f_r, h_f_l; //hallflagright and left + + void hallr() //this just reading the various times. { if (h_f_r==2) { @@ -106,7 +131,7 @@ h_f_r = 1; hall_rdt = hall_rt2-hall_rt1; } - blue.printf("Hall_R dt : %f\n", hall_rdt); + //blue.printf("Hall_R dt : %f\n", hall_rdt); } void halll() @@ -134,28 +159,9 @@ blue.printf("Hall_L dt : %f\n", hall_ldt); } -float pres_duty_r, pres_duty_l; -float a_ratio; -float desired_ratio; -float perc_r; -float perc_l; -float perc_tot; -float threshold; -float limit; -float inc_value; + -void init_PD () -{ - //all these values have to be global; this function gets called each time there's a new direction/desired speed - a_ratio = hall_ldt/hall_rdt; //actual_ratio - desired_ratio = desired_duty_l/desired_duty_r; //desired_duty comes from set_direction() - perc_r = (1-((desired_duty_r-0.1)/desired_duty_r));//absolute vlaue of +-0.1 duty means a differnt percentage error for each duty value - perc_l = (1-((desired_duty_l-0.1)/desired_duty_l)); - perc_tot = perc_r + perc_l; - threshold = desired_ratio*perc_tot; //dynamic threshold that will change according to duties - limit = 0.2*((desired_duty_l + desired_duty_r)/2); //twenty percent of the average duty - inc_value = 0.05*((desired_duty_l + desired_duty_r)/2); //probably need to change 5% from testing -} + void PD_control () { @@ -208,7 +214,7 @@ motor_lf=0; motor_lb=0; wait(1); - set_direction(0x11, 0.2,0.2); + set_direction(0x11, 0.5,0.5); while(1) { } }