ESC beeping, accel gyro caliberation lost

Hi, This might be a pixhawk problem , but I couldnot resist to post it here. when I connect batteries to my hexrotor, the esc starts beeping. After connecting and disconnecting battery multiple times, the beeping stops, but the QgroundControl shows that accelerometer and gyrometer need caliberation and also the pixhawk led turns red and keeps blinking. I could not figure it out, why this is happening. Also it even flew once perfectly after caliberating accelerometer and gyrometer but then after disconnecting and connecting battery again, the beeping of ESC came back. I am unable to figure out the problem and I would be grateful if you can give me some insights. Thanks again.

I use to have the same issue. A solution of this problem was turing off and on again the mc_att_control algorithm with the nuttx shell

Pardon me @Darkus3 , I am not sure how to do what you just advised. Please kindly elaborate , how may I proceed. Thank you again.
However , how does this solution relate to this problem, I am completely in the dark. Any help would be greatly appreciated.

You can interract directly with px4 system by connecting with serial link as descriebed here : https://dev.px4.io/en/debug/system_console.html

Then you can use " nsh> mc_att_control start/stop" in order to restart the algorithm.
I don’t really know how it should resolve the problem but I suppose that the beeps comes from the commander which detects that the alogirithm is not set correctly and then turns on red light and beeps esc.

@Darkus3 Thank you so much for the valuable insights. Pardon me for keep asking questions. In my case the pixhawk also needs re-caliberation of accel and gyro. Also, If I disconnect and connect the battery, then the mc_att_control should automatically restart?

Normally yes but if sensors are not set up correctly it will disarm the commander and then you have to restart the calibration process all over again…

I did the caliberation via QgroundControl and the caliberation worked. I even did fly it once and it was doing fine position control via RC and I let it hover till battery warning started. The I added new batteries and the beeping started again, which led to another error for caliberation of accel and gyro. I am just confused as to what causes the loss of caliberation? is it something related with the memory of the pixhawk? I mean the ESC beeps trigger this caliberation loss.
I will try to do what you have suggested, I hope it works.