Is there any way to read the angular acceleration using magneticsensor

I am trying to calculate the angular acceleration using as5600, but i failed.

this is the ouput of the serial

long pre_acc_time_stamp = 0; 
float pre_vel = 0;           
long angle_pre_ts_acc = 0;
float vel_now = 0;
float _acc = 0;

float get_acc(BLDCMotor* motor)
{
        angle_pre_ts_acc = motor->sensor->get_angle_prev_ts();
        long Ts = angle_pre_ts_acc - pre_acc_time_stamp; 
#ifdef DEBUG_ACC
        Serial.print("TS=");
        Serial.print(Ts);
#endif
        if (Ts <= 0)
            Ts = 1e-3f;

#ifdef DEBUG_ACC
        Serial.print("PRE_ACC_TIME=");
        Serial.print(pre_acc_time_stamp);
#endif

        pre_acc_time_stamp = angle_pre_ts_acc; 
        vel_now = motor->shaft_velocity;

#ifdef DEBUG_ACC
        Serial.print("PRE_ACC_TIME=");
        Serial.print(pre_acc_time_stamp);
        Serial.print("\t");
        Serial.print("vel_now");
        Serial.print(vel_now);
        Serial.print("\t");
        Serial.print("pre_vel");
        Serial.print(pre_vel);
        Serial.print("\t");
#endif

        _acc = (vel_now - pre_vel) / (Ts * 1e-6);    
        pre_vel = vel_now;                             
        return _acc;
}

Hey,

In principle you can calculate the acceleration more or less as you are doing, as the second differential of the position or the first differential of the velocity. But there are significant issues with sampling, bandwidth and numerical accuracy, meaning its hard to get good results with the simple approach.

The AS5600 is a very noisy sensor to begin with, and differentiating the position twice will greatly amplify any errors in the original position and/or timestamp value.

You can use SimpleFOC’s LPF (low pass filter) class to smooth the results, this can help. I imagine it will help using the LPF on the velocity values before calculating the acceleration. If you don’t need high bandwidth, then using large delta-Ts will probably help.

Someone more up to date on their numerical methods might have some pointers for good algorithms to use.