Just wanted to shared my app code to improve control at low speed and provide full stop with hall sensors only (encoder would allow to use position_pid instead).
I use "mcpwm_foc_set_openloop_phase" with a current proportional to the difference between the actual position (from hall sensors) and the last angle when motor was rotating.
otherwise "mc_interface_set_duty" with current compensation : duty is increased when current increases, so as to keep speed more constant whatever the torque required. Compensation must be limitted to avoid unstable operation.
I use it in a little vehicle used on steep slopes with frequent halts for agricultural work - no more need for mechanical brakes. Relatively energy efficient - at least no so bad as "stepper motor like" control
Hope this helps.
const volatile mc_configuration *mcconf = mc_interface_get_configuration();
float my_duty = 0.6 * pwr * mcconf->l_max_duty;
curr_now = mcpwm_foc_get_tot_current_filtered(); // VESC6 version need #include "mcpwm_foc.h"
if (fabsf(my_duty) < 0.002) {
if (is_set_duty) {
is_set_duty = 0;
my_angle = mcpwm_foc_get_phase_observer() - 90.0; // setting Iq in set_openloop_phase yields a 90degree shift vs phase_observer.
}
utils_norm_angle(&my_angle);
my_diff = utils_angle_difference(my_angle+90.0,get_phase_angle);
if (my_diff>55.0) my_angle-=0.05; // allows slight position shift when pushing really hard and reaching too high difference
if (my_diff>65.0) my_angle-=0.1;
if (my_diff<-55.0) my_angle+=0.05;
if (my_diff<-65.0) my_angle+=0.1;
avg_diff += (fabsf(my_diff)-avg_diff)*0.002; // smooth in time (loop in done fast at 4kHz)
float avg_diff2 = 0.008 * avg_diff * avg_diff; // max avg_diff = 60 degree -> max current
utils_truncate_number(&avg_diff2,0.0,40.0); // 40.0 is max current - hard coded.. better take it from config
mcpwm_foc_set_openloop_phase(2.0 + avg_diff2, my_angle); //float current, float angle)
}
else {
my_duty += (my_duty>0?1:-1) * curr_now * 0.001; // current compensation: increase duty when more current required
utils_truncate_number(&my_duty,-1.0,1.0); // 0.001 increase should be calculated from the motor resistance (something like 70%)
mc_interface_set_duty(my_duty); //
is_set_duty = 1;
}
pardon me sir I am very new to the electronics of flipsky 6.6. I have a motor that say it can not read the hall sensor and so the motor wll not spin, is there a feature in the vesc project platform where i can shut the hall sensor off and run a test?
Alan Harrison
@Alan, using Vesc-tool, in the motor settings, you can select FOC mode / sensorless. Alternately, you may try to run an Hall Sensor detection to see how they perform (or not) I think FESC6.6 has a switch to select 3V or 5V supply to the hall sensors.
Sir
May i know in which file and in which part of the code should i make changes? And in which part of the code should i pase it ?
Thankyou
Poornesh
Please find the code of my custom app. Quite direty coding, and obvisouly it has to be adapted to your application... But it may give you ideas..