ESC calibration using custom code

Hello everyone,

I have some questions regarding the calibration of my 30A ESCs. Since I am developing my own code, I need to calibrate them completely manually by writing down the appropriate code. You can check out the code I have written below:

import sys
import time

import navio.pwm
import navio.util

navio.util.check_apm()

PWM_OUTPUT = 13
SERVO_MIN = 0.90 #ms
SERVO_MAX = 2.49 #ms
SERVO_INITIAL = SERVO_MIN

with navio.pwm.PWM(PWM_OUTPUT) as pwm:
    pwm.set_period(50)
    pwm.enable()

    user_input = input("Type 0 to enter calibration mode and send max throttle: ")
    user_input = int(user_input)
    if user_input == 0:

        print("Sending maximum throttle")
        for i in range(100):
            pwm.set_duty_cycle(SERVO_MAX)
            time.sleep(0.1)

        # print("Waiting just a little bit...")
        time.sleep(0.5)

    else:
        raise Exception("Wrong input. Abandoning everything")

    for i in range(100):
        pwm.set_duty_cycle(SERVO_MIN)
        time.sleep(0.1)

    print("ESC calibration completed!")
    time.sleep(1)

    for i in range(500):
        print("PWM Period: %.3f" % (SERVO_INITIAL))
        pwm.set_duty_cycle(SERVO_INITIAL)
        SERVO_INITIAL = SERVO_INITIAL + 0.005
        if SERVO_INITIAL > SERVO_MAX:
            SERVO_INITIAL = SERVO_MAX

        time.sleep(0.03)


    while True:
        pwm.set_duty_cycle(SERVO_MIN)
        time.sleep(0.03)

I am powering the Navio2 board, sending the maximum PWM signal, then I connect my ESC, send the minimum PWM signal and afterwards I perform a testing by spinning the motor with increasing speed. The motor spins as it should be and when I send the minimum PWM signal, I hear the 3 beeps indicating a 3 cells Li-Po battery (which is correct) and then the long beep indicating that the minimum pulse width has been set.

However, there are some issues that concern me. When I plug the battery to the ESC, while sending the maximum PWM signal, I don’t hear the musical tone that I think I should but instead there are single beep tones every 3 and a little bit seconds. Moreover, when I don’t send any PWM signal for more than 1 second (approximately) ESC starts beeping constantly but it remains calibrated. Same things happen when calibrating it with an Arduino board.

Looking forward for any replies. It would be really helpful and appreciated.

Kind regards,
Teo

Hi Teo,

Thanks for your question!

It’s quite an advanced configuration as we usually suggest doing the calibration provided by ArduPilot. From my side, I can only suggest checking the ArduPilot source code for ESC calibration as you might find something useful for you there. But, hopefully, someone from experienced users can shed some light on this.

Hi Liudmila,

thank you for the answer. Will check the ArduPilot source code but since it is too large and complicated any other ideas and/or suggestions would be greatly appreciated.

Thank you once again!