# Calibrating the servos.

A project log for DIY hobby servos quadruped robot

Cheap 3D printed 4 legged robot, that almost looks like boston dynamics spot but moves like a newborn.

First of all, you will need to plug all servos to their proper pin, in my case here they are (you can change this for your how setup):

```void connectServos() {
//FR
Servos.attach(40); //coxa
Servos.attach(38); //femur
Servos.attach(36); //tibia
//FL
Servos.attach(42); //coxa
Servos.attach(44); //femur
Servos.attach(46); //tibia
//BR
Servos.attach(34); //coxa
Servos.attach(32); //femur
Servos.attach(30); //tibia
//BL
Servos.attach(48); //coxa
Servos.attach(50); //femur
Servos.attach(52); //tibia
}```

As soon as the servos are corretly attached, what i made in order to put the servos on its correct position is just to dissasembly the legs, i mean, separate the servo output from the its horn, in order to let the servo move freely. This way you can power the servos, let them go to the zero position and the reassembly.

I wrote a small sketch in order to put the servos on their zero position, you can find it at servo_calibration.py file, this way you can attatch the servo very close to their zero position.

Then, a more precise calibration is needed, you will need to calibrate the offset of each servo, those offset are defined at angleToPulse.py file. This file only contains the line defining the pulse corresponding to each angle for every servo.

Being a line in the form: y = Ax + B. The offset of each servo is defined by B, which mean the pulse at the zero angle.

If you are using different servos, the slope of the line (A) will be different so you will need to identify it. What i did, is just to take 4-5 meassurement of pulse at different angles and put them on an excel where i calculate the adjucted line from those points.

```def convert(FR_angles, FL_angles, BR_angles, BL_angles):
pulse = np.empty()
#FR
pulse = int(-10.822 * np.rad2deg(-FR_angles)) + 950
pulse = int(-10.822 * np.rad2deg(FR_angles)) + 2280
pulse = int(10.822 * (np.rad2deg(FR_angles) + 90)) + 1000
#FL
pulse = int(10.822 * np.rad2deg(FL_angles)) + 1020
pulse = int(10.822 * np.rad2deg(FL_angles)) + 570
pulse = int(-10.822 * (np.rad2deg(FL_angles) + 90)) + 1150
#BR
pulse = int(10.822 * np.rad2deg(-BR_angles)) + 1060
pulse = int(-10.822 * np.rad2deg(BR_angles)) + 2335
pulse = int(10.822 * (np.rad2deg(BR_angles) + 90)) + 1200
#BL
pulse = int(-10.822 * np.rad2deg(BL_angles)) + 890
pulse = int(10.822 * np.rad2deg(BL_angles)) + 710
pulse = int(-10.822 * (np.rad2deg(BL_angles) + 90)) + 1050
return pulse```

## Discussions 