Go to the source code of this file.
Functions | |
| void | duty_cycle_filter (void) |
| U8 | mc_control_current (U8 cur_cmd) |
| use to control current , current regulation loop need parameter : Kp_cur, Ki_cur ,Kd_cur and K_cur_scal in config_motor.h need to call in Te ms | |
| U8 | mc_control_speed (U8 speed_cmd) |
| use to control speed , speed regulation loop need parameter : Kp_speed, Ki_speed ,Kd_speed and K_speed_scal in config_motor.h need to call in Te ms | |
| U8 | mc_get_duty_cycle () |
| set type of regulation | |
| void | mc_regulation_loop () |
| launch speed control or no regulation | |
| void | mc_set_current_loop () |
| set type of regulation | |
| void | mc_set_open_loop () |
| set type of regulation | |
| void | mc_set_speed_loop () |
| set type of regulation | |
| void duty_cycle_filter | ( | void | ) |
Definition at line 227 of file mc_control.c.
References duty_cycle, duty_cycle_filter_presc, duty_cycle_reference, and K_DUTY.
Referenced by main().
00228 { 00229 duty_cycle_filter_presc++; 00230 if (duty_cycle_filter_presc == 30) 00231 { 00232 duty_cycle_filter_presc = 0; 00233 if (duty_cycle < duty_cycle_reference) 00234 { 00235 duty_cycle = duty_cycle + K_DUTY; 00236 } 00237 else 00238 { 00239 if (duty_cycle > duty_cycle_reference) 00240 { 00241 duty_cycle = duty_cycle - K_DUTY; 00242 } 00243 } 00244 } 00245 }
use to control current , current regulation loop need parameter : Kp_cur, Ki_cur ,Kd_cur and K_cur_scal in config_motor.h need to call in Te ms
Definition at line 142 of file mc_control.c.
References cur_error, cur_integ, cur_integral, cur_proportional, K_cur_scal, Ki_cur, Kp_cur, and mci_get_measured_current().
Referenced by mc_regulation_loop().
00143 { 00144 U8 Duty = 0; 00145 S32 increment = 0; 00146 00147 // Error calculation 00148 cur_error = cur_cmd - (mci_get_measured_current());// value -255 <=> 255 00149 00150 // proportional term calculation 00151 cur_proportional = Kp_cur*cur_error; 00152 00153 // integral term calculation 00154 cur_integral = cur_integral + cur_error; 00155 00156 if(cur_integral > 255) cur_integral = 255; 00157 if(cur_integral < -255) cur_integral = -255; 00158 00159 cur_integ = Ki_cur*cur_integral; 00160 00161 // derivative term calculation 00162 /*cur_derivative = cur_error - last_cur_error; 00163 00164 if(cur_derivative > 255) cur_derivative = 255; 00165 if(cur_derivative < -255) cur_derivative = -255; 00166 00167 cur_der = Kd_cur*cur_derivative; 00168 00169 last_cur_error = cur_error;*/ 00170 00171 // Duty Cycle calculation 00172 increment = cur_proportional + cur_integ; 00173 //increment += cur_der; 00174 increment = increment >> K_cur_scal; 00175 00176 // Variable saturation 00177 if(increment >= (S16)(255)) Duty = 255; 00178 else 00179 { 00180 if(increment <= (S16)(0)) Duty = 0; 00181 else Duty = (U8)(increment); 00182 } 00183 00184 // return Duty Cycle 00185 return Duty; 00186 }
use to control speed , speed regulation loop need parameter : Kp_speed, Ki_speed ,Kd_speed and K_speed_scal in config_motor.h need to call in Te ms
Definition at line 82 of file mc_control.c.
References K_speed_scal, Ki_speed, Kp_speed, mci_get_measured_speed(), speed_error, speed_integ, speed_integral, and speed_proportional.
Referenced by mc_regulation_loop().
00083 { 00084 U8 Duty = 0; 00085 S32 increment = 0; 00086 00087 // Error calculation 00088 speed_error = speed_cmd - mci_get_measured_speed();// value -255 <=> 255 00089 00090 // proportional term calculation 00091 speed_proportional = Kp_speed*speed_error; 00092 00093 // integral term calculation 00094 /* speed_integral = speed_integral + speed_error; 00095 00096 if(speed_integral > 255) speed_integral = 255; 00097 if(speed_integral < -255) speed_integral = -255; 00098 00099 speed_integ = Ki_speed*speed_integral; 00100 */ 00101 speed_integral = Ki_speed*(speed_integral + speed_error); 00102 00103 if(speed_integral > 255) speed_integral = 255; 00104 if(speed_integral < -255) speed_integral = -255; 00105 00106 // derivative term calculation 00107 /*speed_derivative = speed_error - last_speed_error; 00108 00109 if(speed_derivative > 255) speed_derivative = 255; 00110 if(speed_derivative < -255) speed_derivative = -255; 00111 00112 speed_der = Kd_speed*speed_derivative; 00113 00114 last_speed_error = speed_error;*/ 00115 00116 // Duty Cycle calculation 00117 increment = speed_proportional + speed_integ; 00118 //increment += speed_der; 00119 increment = increment >> K_speed_scal; 00120 00121 // Variable saturation 00122 if(increment >= (S16)(255)) Duty = 255; 00123 else 00124 { 00125 if(increment <= (S16)(0)) Duty = 0; 00126 else Duty = (U8)(increment); 00127 } 00128 00129 // return Duty Cycle 00130 return Duty; 00131 }
| U8 mc_get_duty_cycle | ( | ) |
set type of regulation
Definition at line 222 of file mc_control.c.
References duty_cycle.
Referenced by main().
00223 { 00224 return duty_cycle; 00225 }
| void mc_regulation_loop | ( | ) |
launch speed control or no regulation
Definition at line 196 of file mc_control.c.
References CURRENT_LOOP, duty_cycle_reference, mc_control_current(), mc_control_speed(), mc_get_potentiometer_value(), mci_get_ref_speed(), OPEN_LOOP, regulation_type, and SPEED_LOOP.
Referenced by main(), mci_retry_run(), and mci_run().
00197 { 00198 switch(regulation_type) 00199 { 00200 case OPEN_LOOP : duty_cycle_reference = mci_get_ref_speed();break; 00201 case SPEED_LOOP : duty_cycle_reference = mc_control_speed(2*mci_get_ref_speed());break; 00202 case CURRENT_LOOP : duty_cycle_reference = mc_control_current(mc_get_potentiometer_value());break; 00203 default : break; 00204 } 00205 }
| void mc_set_current_loop | ( | ) |
set type of regulation
Definition at line 218 of file mc_control.c.
References CURRENT_LOOP, and regulation_type.
00218 {regulation_type = CURRENT_LOOP;}
| void mc_set_open_loop | ( | ) |
set type of regulation
Definition at line 210 of file mc_control.c.
References OPEN_LOOP, and regulation_type.
00210 {regulation_type = OPEN_LOOP;}
| void mc_set_speed_loop | ( | ) |
set type of regulation
Definition at line 214 of file mc_control.c.
References regulation_type, and SPEED_LOOP.
00214 {regulation_type = SPEED_LOOP;}
1.5.7.1