
Go to the source code of this file.
Functions | |
| 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 | |
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 104 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().
00105 { 00106 U8 Duty = 0; 00107 S32 increment = 0; 00108 00109 // Error calculation 00110 cur_error = cur_cmd - (mci_get_measured_current());// value -255 <=> 255 00111 00112 // proportional term calculation 00113 cur_proportional = Kp_cur*cur_error; 00114 00115 // integral term calculation 00116 cur_integral = cur_integral + cur_error; 00117 00118 if(cur_integral > 255) cur_integral = 255; 00119 if(cur_integral < -255) cur_integral = -255; 00120 00121 cur_integ = Ki_cur*cur_integral; 00122 00123 // derivative term calculation 00124 /*cur_derivative = cur_error - last_cur_error; 00125 00126 if(cur_derivative > 255) cur_derivative = 255; 00127 if(cur_derivative < -255) cur_derivative = -255; 00128 00129 cur_der = Kd_cur*cur_derivative; 00130 00131 last_cur_error = cur_error;*/ 00132 00133 // Duty Cycle calculation 00134 increment = cur_proportional + cur_integ; 00135 //increment += cur_der; 00136 increment = increment >> K_cur_scal; 00137 00138 // Variable saturation 00139 if(increment >= (S16)(255)) Duty = 255; 00140 else 00141 { 00142 if(increment <= (S16)(0)) Duty = 0; 00143 else Duty = (U8)(increment); 00144 } 00145 00146 // return Duty Cycle 00147 return Duty; 00148 }

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 49 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().
00050 { 00051 U8 Duty = 0; 00052 S32 increment = 0; 00053 00054 // Error calculation 00055 speed_error = speed_cmd - mci_get_measured_speed();// value -255 <=> 255 00056 00057 // proportional term calculation 00058 speed_proportional = Kp_speed*speed_error; 00059 00060 // integral term calculation 00061 speed_integral = speed_integral + speed_error; 00062 00063 if(speed_integral > 255) speed_integral = 255; 00064 if(speed_integral < -255) speed_integral = -255; 00065 00066 speed_integ = Ki_speed*speed_integral; 00067 00068 // derivative term calculation 00069 /*speed_derivative = speed_error - last_speed_error; 00070 00071 if(speed_derivative > 255) speed_derivative = 255; 00072 if(speed_derivative < -255) speed_derivative = -255; 00073 00074 speed_der = Kd_speed*speed_derivative; 00075 00076 last_speed_error = speed_error;*/ 00077 00078 // Duty Cycle calculation 00079 increment = speed_proportional + speed_integ; 00080 //increment += speed_der; 00081 increment = increment >> K_speed_scal; 00082 00083 // Variable saturation 00084 if(increment >= (S16)(255)) Duty = 255; 00085 else 00086 { 00087 if(increment <= (S16)(0)) Duty = 0; 00088 else Duty = (U8)(increment); 00089 } 00090 00091 // return Duty Cycle 00092 return Duty; 00093 }

| U8 mc_get_Duty_Cycle | ( | ) |
set type of regulation
Definition at line 204 of file mc_control.c.
References duty_cycle.
Referenced by mci_retry_run(), and mci_run().
00205 { 00206 return duty_cycle; 00207 }
| void mc_regulation_loop | ( | ) |
launch speed control or no regulation
Definition at line 160 of file mc_control.c.
References Clear_EXT3, CURRENT_LOOP, duty_cycle, mc_control_current(), mc_control_speed(), mc_get_motor_speed(), mc_get_potentiometer_value(), OPEN_LOOP, regulation_type, Set_EXT3, and SPEED_LOOP.
Referenced by mci_retry_run(), and mci_run().
00161 { 00162 // measure 00163 Set_EXT3(); 00164 00165 switch(regulation_type) 00166 { 00167 case OPEN_LOOP : duty_cycle = mc_get_motor_speed();break; 00168 case SPEED_LOOP : duty_cycle = mc_control_speed(mc_get_motor_speed());break; 00169 case CURRENT_LOOP : duty_cycle = mc_control_current(mc_get_potentiometer_value());break; 00170 default : break; 00171 } 00172 00173 // measure 00174 Clear_EXT3(); 00175 }

| void mc_set_Current_Loop | ( | ) |
set type of regulation
Definition at line 196 of file mc_control.c.
References CURRENT_LOOP, and regulation_type.
00196 {regulation_type = CURRENT_LOOP;}
| void mc_set_Open_Loop | ( | ) |
set type of regulation
Definition at line 182 of file mc_control.c.
References OPEN_LOOP, and regulation_type.
00182 {regulation_type = OPEN_LOOP;}
| void mc_set_Speed_Loop | ( | ) |
set type of regulation
Definition at line 189 of file mc_control.c.
References regulation_type, and SPEED_LOOP.
00189 {regulation_type = SPEED_LOOP;}
1.5.7.1