Free Shipping Over $119



4.7 Use of PTZ servos

Posted by Fiona Su on

1. Introduction to PTZ servo driving

The drive of the PTZ servo is built on the serial communication. In the introduction of the 【5.1 Using of GPIO 】, we learned that serial servo uses UART2 serial 2 TX, because the servo only receives data, so we only use Go to the UART_2_TX pin of the serial port, which is mounted on the /dev/ttyTHS1 device of the Jetbot Ubuntu 18.04 system.

!!!Note: If you are not using the Yahboom_jetbot_car_image provided by Yahboom, please confirm whether you have enabled the usage rights in accordance with 【2.4 Install Jetbot】--【1. Enable peripheral permissions we will use】

image.png 

About specific drive functions in the PTZ serial servo bus :

The PTZ serial bus servo drive has imported the following module package.

image.png

Different from the previous one, the serial port module and the string processing module are introduced, and the string processing module is used to process the command stacking process for controlling the serial port bus servo.

When the module is called to create an instance object, the initialization function is automatically run to initialize the driver.

After the initialization is completed, the "Serial Open!" string prompt will be printed on the console. When the program exits, the __del__() function will be automatically run to close the serial port and the "serial Close!" prompt will be printed.

image.png

 Control example method for a single servo:

Servo_serial_control(self, index, angle)

 Two motor control example methods:

Servo_serial_double_control(self, index_1, angle_1, index_2, angle_2)

 The code shown in the following figure exists in both methods:

About Serial bus servo protocol:

Path of package : [Jetbot-AI Car] --> [Annex] --> [Hardware]---> [Serial bus servo protocol file]

2. Use the servo drive the asynchronous write command to control the servo

We import the package that needs to be used, and then create an instance of the PTZ bus servo. The PTZ bus servo is initialized by default in the background.

image.png Next, we can start using the example method to control the steering wheel rotation.

image.png 

servo_serial_control(self, index, angle)

Indenx = 1, it means that the PTZ servo servo is controlled to move in the left and right direction (X-axis direction).

Indenx = 2, it means that the PTZ servo servo is controlled to move in the up and down direction (Y-axis direction).

As the pan/tilt rotation described in the previous section is limited to the safe range, the values we set are within this range for efficient operation:

The motor in the left and right direction, ie index = 1, moves in the range of 600 – 3600

The motor in the up and down direction, ie index = 2, moves in the range 1300 – 4095

The corresponding complete source code is located at:

/home/jetbot/Notebook/8.Using of PTZ servos bus/Asynchronous control servo.ipyn

3. Use the servo drive the synchronous write command to control the servo

Sometimes when we move the PTZ, both motors need real-time control.

In order to achieve higher real-time responsiveness of the servo and avoid data jam on the export bus, we added a synchronous write command to control the servo based on asynchronous communication.

One command can control two servos at the same time, so that when the PTZ servo is used for real-time motion, its sensitivity is greatly improved. 

The code is shown below:

image.png servo_serial_double_control (self, index_1, angle_1, index_2, angle_2)

Indenx = 1, it means that the PTZ servo servo is controlled to move in the left and right direction (X-axis direction).

Indenx = 2, it means that the PTZ servo servo is controlled to move in the up and down direction (Y-axis direction).

The other procedures used are consistent with the asynchronous write command control servos introduced above.

The corresponding complete source code is located at:

/home/jetbot/Notebook/8.Using of PTZ servos bus/Synchronous control servo.ipynb

Tutorial

Buy Yahboom Jetbot AI robot with HD Camera Coding with Python for Jetson Nano

0 comments

Leave a comment

Please note, comments must be approved before they are published