In previous sections, we have prepared those body parts, but haven’t screwed them onto servos. If we don’t calibrate the servos before attaching them, they may rotate to any direction, get stuck, and cause damage to either the servos or body parts.
The calibration has four steps:
Write constants to the board
Power on the circuit, let servos rotate freely to zero angle/calibration state
Attach body parts to the servos
Fine tune the offsets in software.
The logic behind calibration can be found on OpenCat forum.
Assembly related definitions, like joint mapping, rotation direction, sensor pins. They are pretty fixed and are mostly defined in OpenCat.h. They are even kept consistent with my future robots;
Calibration related parameters, like MPU6050 offsets and joint corrections. They are measured in realtime and are saved in on-board EEPROM. They only need to be measured once;
Skill related data, like postures, gaits, and pre-programmed behaviors. They are mostly defined in Instinct.h. You can add more customized skills too.
The role for WriteInstinct.ino is to write constants to either onboard or I2C EEPROM, and save calibration values. It will be overwritten by the main sketch Nybble.ino afterward.
You need to change the * on
#define NyBoard_V*_* in Instinct.h to match your NyBoard’s version. The version number is to the left of the green battery terminal.
After finish uploading WriteInstinct.ino, open the serial monitor. You will see several questions:
Reset all joint calibration? (Y/n)
If you have never calibrated the joints, or if you want to recalibrate the servos with fresh start, type ‘Y’ to the question. The ‘Y’ is CASE SENSITIVE!
Do you need to update Instincts? (Y/n)
If you have modified the Instinct.h in any way, you should type ‘Y’. Though it’s not always necessary once you have a deeper understanding of the memory management.
Calibrate MPU? (Y/n)
If you have never calibrated the MPU6050, i.e. the gyro/accelerometer sensor, type ‘Y’.
Sometimes the program could hang at the connection stage. You can close the serial monitor and reopen it, or press the reset button on NyBoard, to restart the program.
The calibration state is defined as the middle point of servo’s reachable range. Calibration for servos can be done in either WriteInstinct.ino or Nybble.ino. I recommend you do it with WriteInstinct.ino in case there’s something wrong with the constants.
You MUST plug in all the servos and battery for proper calibration. Then in the serial monitor, type ‘c’ to enter calibration mode. The servos should rotate one by one with unnoticeable time intervals then stop. Depending on their initial shaft direction, some may travel larger angles until stopping at the middle point. There will be noise coming from the gear system of the servos. You will see the calibration table:
The first row is the joint indexes, the second row is their calibration offsets:
Initial values are “-1” or “0”, and should be changed by later calibration.
After entering ‘c’, with all servos rotated to their zero angle, now attached the head, tail, and legs prepared in previous section to the body. They are generally perpendicular to their linked body frames. Avoid rotating the servo shaft during the operation.
Rotating the limbs counter-clockwise from their zero state will be positive (same as in polar coordinates). The only exception is the tilt angle for head. It’s more natural to say head up, while it’s the result from rotating clockwise.
If we take a closer look at the servo shaft, we can see it has a certain number of teeth. That’s for attaching the servo arms, and to avoid sliding in the rotational direction. In our servo sample, the gears are dividing 360 degrees to 20 sectors, each taking 18 degrees. That means we cannot always get exact perpendicular installation. But try to get them as close as possible to their zero states. Use screw A to fix the limbs onto servos.
The command for calibration (refer to the serial communication protocol for NyBoard) is formatted as
cIndex Offset. Notice that there’s a space between Index and Offset.
c8 6 means giving the 8th servo an offset of 6 degrees. Find the best offset that can bring the limb to zero state.
For example, if you have to use -13 as the calibration value, take the limb off, rotate by one tooth then attach back. The new calibration value should be around 5, i.e., they sum up to 18. Avoid rotating the servo shaft during this adjustment.
After calibration, remember to type ‘s’ to save the offsets. Otherwise they will be forgotten when exiting the calibration state. You can even save every time after you’re done with one servo.
When watching something, the observation will change from different perspectives. That’s why when measuring length, we always want to read directly above the ruler.
It’s especially important that you keep parallel perspective when calibrating Nybble. Use the 'L' shaped joint tuner as a parallel reference to avoid reading errors. Align the tips on the tuner with the center of the screws in shoulder and knee joints, and the little hole on the tip of the foot. Look along the co-axis of the centers. For each leg, calibrate shoulder servos (indexed 8~11) first, then the knee servos(indexed 12~15). When calibrating the knee, use the matching triangle windows on both the tuner and shank to ensure parallel alignment.
After calibration, type ‘d’ or ‘kbalance’ to validate the calibration. It will result in Nybble symmetrically moving its limbs between rest and stand state.
Try to understand how Nybble keeps balance even during walking. If you are adding new components to Nybble, try your best to distribute its weight symmetrically about the spine. You may also need to slide the battery holder back and forth to find the best spot for balancing.