# Joints Calibration

## Leg Calibration Using Jigs

Five leg calibration jigs are included in the robot kit, enabling calibration of all joints of a single leg one leg at a time:

- **ANKLE**: for Ankle ball screws (×2)
- **HIP XY**: for Hip XY ball screws (×2)
- **HIP Z**: for Hip Z ball screw (×1)

### Jig Design

Each calibration jig is composed of a plastic part which can be inserted around the screw of the ball screw actuators. 
To install a jig, switch off the robot and insert it to brace the corresponding ball screw and then rotate the actuator such that the jig will become locked between the nut and the ball screw rod end.

### Jig Orientation

Proper jig orientation at the joint is crucial. Position the jig so that its upper side is flat against the nut in between the nut's screws. 

### Finding the Zero Position

Rotate the jig manually to move the ball screw. Ensure you rotate in the correct direction until the jig **firmly contacts both sides** of the ball screw. That contact point is the **0 position** of the corresponding joint.

### Software Calibration Procedure

Once the jig is set at zero, follow the steps below **without moving the joint or actuator**:

1. Execute `pal module stop controller_manager`
2. Execute `ros2 run zero_set_calibration  kangaroo_legs_zero_reset.sh --left (--right)` 
3. Press the **emergency stop**
4. Release the emergency stop and press the back button as usual
5. Execute `pal module_manager restart`
6. Check in **WebGUI** that the **absolute position** for this specific joint is exactly **zero**

### Leg Length Zero Setting

The Leg Length joint does not use a jig. Instead, push the foot downward (fully-extended) **until it reaches the mechanical limit**: that position is defined as zero for the leg length actuator.

### Important Notes

```{note}
- Repeat the same process for **all ball screws in a leg**. Ensure all 5 jigs are mounted before setting the zero position of the leg.
  - Alternatively, you can mount the jigs on the ball screws of Hip XY, Hip Z, and Ankle XY **separately** and set the zeros per transmission using the `-a` argument and specifying the corresponding actuators.
- Once completed, replicate the exact procedure for the **other leg**, working on one leg at a time.
```

#### Kangaroo zero setting script

```bash
$ ros2 run zero_set_calibration  kangaroo_zero_reset.sh -h

Reset the Kangaroo legs zero offsets inside the boards

Optional arguments:
  -h, --help      show this help message and exit
  -l, --left      reset left leg
  -r, --right     reset right leg
  -p, --pelvis    reset pelvis motors
  -a, --actuator NAME [NAME...]
                  reset specific actuator(s) by name, repeatable
                  valid names: leg_right_1..5, leg_right_length,
                               leg_left_1..5, leg_left_length, pelvis_1, pelvis_2
  -c, --continue  continue on error, aborts by default
```

You should see an output similar to the following:

```bash
$ ros2 run  zero_set_calibration kangaroo_zero_reset.sh -a leg_right_length_actuator
1782990662.529550 [83]       ros2: wlan0: optional interface was not found.
1782990663.295758 [83]       ros2: wlan0: optional interface was not found.
Right ankle FT sensor: no-ft-sensor
Left ankle FT sensor:  no-ft-sensor
Actuator leg_right_length_actuator -> motor ID 6
This will reset the offsets inside the boards.
Are you sure you want to proceed? [y/N] y
Resetting specific actuators offsets...
Resetting motor ID 6
Motor ID 6 reset successfully
```

---

## Spherical Bearings Replacement

The following procedure describes how to access and replace the spherical bearings in a Kangaroo leg.

### Step 1: Remove Lateral Cover

Remove the **3×M3 screws** securing the lateral cover and detach it to expose the internal components.

### Step 2: Remove Front Cover

Remove the **7×M3 screws** securing the front cover and detach it. The screws are distributed across both the front face and the lateral face visible after the previous step.

### Step 3: Remove Knee Block Fasteners

Remove **6×M3 screws** and **2×M4 screws with washers** that secure the spherical bearing block to the leg structure.

### Step 4: Separate Bearing Block

Separate the block containing the **spherical bearings and housing** from the rest of the leg.

### Step 5: Replace Spherical Bearings

Remove the **6×M3 screws** securing the bearing covers on the block. This allows detachment of the bearing covers and liberation of the spherical bearings. Replace the bearings and reassemble by following the steps in reverse order.
