# Motors callibration

Hi, I built a small api using your servo example. Trying to create my own flightcontroller.

``````import time
import math
import sys

sys.path.append("libs")
sys.path.append("../Navio/Python")
from Navio import GPIO

class Motor:
FRONT_LEFT = 3
FRONT_RIGHT = 4
BACK_LEFT = 5
BACK_RIGHT = 6

def __init__(self, pin_n):
#drive Output Enable in PCA low
pin = GPIO.Pin(27)
pin.write(0)

frequency = 50

self.NAVIO_RCOUTPUT = pin_n
SERVO_MIN_ms = 1.250 # mS
SERVO_MAX_ms = 1.750 # mS

#convert mS to 0-4096 scale:
self.SERVO_MIN = math.trunc((SERVO_MIN_ms * 4096.0) / (1000.0 / frequency) - 1)
self.SERVO_MAX = math.trunc((SERVO_MAX_ms * 4096.0) / (1000.0 / frequency) - 1)

self.pwm = PWM(0x40, debug=False)

# Set frequency to 60 Hz
self.pwm.setPWMFreq(frequency)

def setSpeed(self, speed):

speed = speed if speed > self.SERVO_MIN else self.SERVO_MIN
speed = speed if speed < self.SERVO_MAX else self.SERVO_MAX
print "Max: {}, Min: {} speed: {}".format(self.SERVO_MAX, self.SERVO_MIN, speed)
self.pwm.setPWM(self.NAVIO_RCOUTPUT, 0, speed)
``````

Now here is a small test

from motors import Motor
import getch

``````# FRONT_RIGHT min 305
# FRONT_LEFT min 308
# BACK_LEFT min  332
# BACK_RIGHT min 322
m1 = Motor(Motor.FRONT_LEFT)
m2 = Motor(Motor.FRONT_RIGHT)
m3 = Motor(Motor.BACK_LEFT)
m4 = Motor(Motor.BACK_RIGHT)
speed = 270
while True:
c = getch.getch()

if c == 'w':
speed = speed + 1
if c == 's':
speed = speed - 1

m1.setSpeed(speed)
m2.setSpeed(speed)
m3.setSpeed(speed)
m4.setSpeed(speed)
``````

I’ve found out that every motor starts in different points. You can see commented values.
Is it a regular thing? Any suggestions how to fix it, or calibrate in a right way?

I’m using SunnySky motors 980kv, and Afro30A ESC’s

You will need to calibrate your ESCs to make them start at the same PWM level.

Hi Igor,

DO you have any code examples or links to to do it with python/c++ ?

I had something similar, My ESC’s were flashed with fixed range on the pwm values as I’m controlling them directly (range is 1060-1460-1860 as they are reversible 2 started at 1520, 2 started at 1530 only tested to the nearest 10), but 2 motors were 10us above the others for startup speed,
That didnt turn out to be an issue tho as the PID handles it fine later on. I just put it down to small differences in the motors capabilities (or maybe inaccuracies creeping in with the PWM communication between the navio and the ESC)