Calibration with Arduino IDE
Calibration is vital for robot to work properly.
The pre-assembled robot should have the legs properly installed, but no fine-tuning calibration.
Make sure you have uploaded the OpenCat Main function firmware before calibrating.
Entering calibration mode requires the following preparations: ‌
1. All servo circuits are connected to the motherboard
2. The battery is fully charged
3. Connect the USB adapter and communicate normally
If you are building the robot with an unassembled kit, do not install the head and leg components until calibrated. You will also need to install the battery and long press the button on the battery to power the robot.
The calibration has 4 steps:
  1. 1.
    Write constants to Nyboard (only for 1.0 firmware)
2. Power on the robot with battery, let servos rotate freely to zero angle/calibration state
3. Attach body parts to the servos
4. Fine-tune the offsets in serial monitor
The logic behind calibration can be found on the OpenCat forum. The principles are the same for Nybble and Bittle.

1. Write constants

This step is only for 1.0 firmware.

1.1. There are 3 types of constants to be saved to NyBoard

  1. 1.
    Assembly-related definitions, like joint mapping, rotation direction, and sensor pins. They are pretty fixed and are mostly defined in OpenCat.h. They are even kept consistent with my future robots;
  2. 2.
    Calibration-related parameters, like MPU6050 offsets and joint corrections. They are measured in real-time and are saved in the onboard EEPROM. They only need to be set up once;
  3. 3.
    Skill-related data, like postures, gaits, and pre-programmed behaviors. They are mostly defined in InstinctNybble.h / InstinctBittle.h. You can add more customized skills too.

1.2. Upload and run WriteInstinct.ino

The role of WriteInstinct.ino is to write constants to either onboard or I2C EEPROM, and save calibration values. It will be overwritten by the main sketch OpenCat.ino afterward.
You need to change the * on#define NyBoard_V*_* in OpenCat.h to match your NyBoard’s version. The version number can be found on the mainboard near the company logo.
Before uploading the sketch, make sure to close all opened windows of the serial monitor. Otherwise, the serial port may be occupied and the sketch will not be uploaded.
You also need to dial the slide switch on NyBoard to Arduino rather than RPi!
After you upload WriteInstinct.ino via Arduino IDE, open the serial monitor.
Make sure to set the serial monitor as 115200 baud rate and no line ending.
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 a fresh start, type ‘Y’ to the question.
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 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.

1.3. Upload OpenCat.ino

You also need to upload OpenCat.ino to save the last constants and activate the demo functionalities.

2 Enter calibration mode

Check the position and direction of all servos, you must plug the servos and external batteries into the NyBoard to calibrate correctly. Before we install the leg assembly, the output shaft of the servo should be at zero (go to neutral and stop).
Type ‘c’ in the serial monitor to enter calibration mode. 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 a calibration table like the following:
The first row is the joint indexes, the second row is their calibration offsets:
Index
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Offset
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
Initial values are “-1” or “0”, and should be changed by later calibration.
The servos are using a potentiometer in the feedback loop for position control. When holding at a static position, they tend to vibrate around the target angle. A Parkinson’s-like vibration will develop after a short period of use. It won’t affect much during continuous motion. Better servos without these troubles could cost 10 times more, so replacing a failed unit is a more cost-effective solution.

3 The rationale for calibration

3.1 Understand the zero state and the coordinate system

After typing ‘c’ in the serial monitor, with all servos rotated to their zero angles, now attached the head, tail, and legs prepared in the previous section to the body. They are generally perpendicular to their linked body frames. The calibration pose is shown below:
If you are building the robot from a kit, install the servo-related components according to the picture above, and try to ensure that they are perpendicular to each other (the upper leg is perpendicular to the torso, and the lower leg is perpendicular to the upper leg). Please refer to the related chapter in the user manual for the details:
Note: Insert the servo-related components directly into the servo output shaft, do not turn the output shaft during this process.
Rotating the limbs counter-clockwise from their zero states will be positive (same as in polar coordinates). Viewed from the left side of the robot's body, the counter-clockwise rotation of the joint is defined as the positive direction.
The only exception is the tilt angle for the head of Nybble. It’s more natural to say head up, while it’s the result of rotating clockwise.
But from the right side of the robot's body, the positive and negative of the rotation direction are just opposite.

3.2 Discrete angular intervals

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 divide 360 degrees into 25 sectors, each taking 14.4 degrees(offset of -7.2~7.2 degrees). That means we cannot always get a perfect perpendicular installation.

4 Fine-tune the calibration using the serial monitor

4.1 Joint Control Commands

The command for fine-tuning calibration (refer to the serial protocol) is formatted as cIndex Offset. Notice that there’s a space between cIndex and Offset. The index number of the robot's joints is shown in the pictures below:
Nybble
Bittle
For example :
  • c8 6 means giving the 8th servo an offset of 6 degrees.
  • c0 -4 means giving the 0th servo(the head) an offset of -4 degrees.
The resolution of the correction amount is 1 degree, do not use decimals.
If you find the absolute value of offset is larger than 9, that means you are not attaching the limb closest to its zero states. That will result in a decreased reachable range of the servo on either side. Take off the limb and rotate it by one tooth. It will result in an opposite but smaller offset.
For example, if you have to use -9 as the calibration value, take the limb off, rotate by one tooth then attach it back. The new calibration value should be around 5, i.e., The sum of their absolute values is 14. Avoid rotating the servo shaft during this adjustment.
Find the best offset that can bring the limb to the zero states. It's a process of trial and error.
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.

4.2 Use ‘L’ shaped joint tuner

When watching something, the observation will change from different perspectives. That’s why we always want to read directly above a referencing ruler when measuring length.
It’s especially important that you keep a parallel perspective when calibrating Bittle. 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 the 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 the shoulder servos (index 8~11) first, then the knee servos(index 12~15). When calibrating the knee, use the matching triangle windows on both the tuner and shank to ensure parallel alignment.

Nybble

Bittle

Align the upper leg first
Pay attention to the reference edges for the lower leg

4.3 Testing and validation

After calibration, type ‘d’ or ‘kbalance’ to validate the calibration. It will result in Bittle / Nybble symmetrically moving its limbs between rest and stand state.
You may need to do a few rounds of calibrations to achieve optimal states.
Take Bittle for example, as follows:

4.4 Center of mass

Try to understand how the robot keeps balance even during walking. If you are adding new components to the robot, 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. Because the battery is heavier in the front, you can also insert it in a reversed direction to shift the center of mass more towards the back.
You may need to recalibrate if there's a change to the center of mass.
Please do not force the robot to add heavy objects, which may cause the servos to sweep or get stuck.