Welcome to 2DOF PTZ repository
2.2DOF Face Tracking
Gimbal Face Tracking
Gimbal Face Tracking1. Experiment description2. Lab Objectives3. Experimental operations4. Experimental effect5. Experimental summary
1. Experiment description
This experiment belongs to the expansion class experiment, need to match the 2D servo gimbal, and 24-way servo driver board to use. These additional modules are not part of the K210 module kit, so this experiment is for reference only, if there is no corresponding equipment can not directly use the code of this routine.
Firmware required for 24-way servo driver board: K210-track.hex
Gimbal servos are connected to the 24-way servo driver board, x-axis servos are connected to the servo control board S1 pin, y-axis servos are connected to the servo control board S2 pin.

Where the servo line (yellow for the signal line, red for VCC, black for GND) connected to the corresponding colour pins of the control board
24-way servo driver board, please connect the 7.4V lithium battery pack, otherwise it will be low voltage buzzer alarm.
The wiring diagram of K210 vision module and 24-channel servo driver board is shown below.

Connect the K210's serial cable to the serial interface of the 24-way servo driver board (5V--5V, GND--GND, TX--RX3, RX--TX3)

2. Lab Objectives
This lesson focuses on learning K210 vision module with 2D gimbal to do visual tracking function.
The reference code path for this experiment is: CanMV\06-export\tracking_face.py
3. Experimental operations
- 24-way servo driver board burn firmware: K210-track.hex
- Download the cart driver library and PID control library in the CanMV\06-export\library directory to the root directory of the memory card in advance.
- Open CanMV IDE to open the tracking_face.py code and download it to the K210 module.
- Connect the K210 module to the 24-channel servo driver board through the 4PIN cable.
- Put the gimbal in the white or black background, and then turn on the power of the 24-channel servo driver board.
- When the human face enters the collection range of the K210 module's camera, the K210 module will frame out the human face and the PTZ will track the movement of the human face.
4. Experimental effect
Wait for the system initialisation to complete, the K210 module camera will detect whether there is a human face in the screen in real time, if there is a human face in the screen, modify the gimbal angle to make the face look as good as possible.
If there is a face in the screen, modify the angle of the gimbal to keep the face in the middle of the screen as much as possible, and the camera will track the face.
If the tracking response is too fast or too slow, you can modify the PID parameters in the programme appropriately.

5. Experimental summary
The gimbal tracking face play is developed based on the face detection function, which detects the position coordinates of the face from the camera of the K210 module and through the PID algorithm
Calculate the position where the gimbal needs to move so that the gimbal can track the face in front of the camera. Due to the frame rate and recognition limitations, the face movement cannot be too fast, otherwise the gimbal
Due to the frame rate and recognition limitations, the face cannot move too fast, otherwise the gimbal may not be able to keep up with the response.