Jetson 03 Pan-Tilt Control and LED Light Control
Pan-tilt Control & LED Light Control
Pan-tilt Control
Basics
A product with a pan-tilt contains two servos, a pan servo and a tilt servo. The pan servo controls the rotation of the horizontal plane of the pan-tilt, and the rotation range is ±180° (total range 360°); The tilt servo controls the rotation of the vertical plane of the pan-tilt, and the rotation range is -45°~90° (total range 135°).
For products that do not come with a pan-tilt, you can also expand the pan-tilt on the RaspRover yourself.
# Import the library used to control the chassis from base_ctrl import BaseController base = BaseController('/dev/ttyTHS0', 115200)
In the code block above we import and instantiate the library for chassis control, and then control the pan-tilt movement by changing the angle of the pan-tilt pan servo and tilt servo.
Change the value in the following code, in the following code:
- input_x is the rotation angle of the pan-tilt pan servo, and the rotation range of the pan servo plane PAN axis is ±180° (total range 360°);
- input_y is the rotation angle of the pan-tilt tilt servo, and the vertical plane of the tilt servo TILT axis rotation range is -45°~90° (total range 135°);
- input_speed is the speed at which the pan-tilt rotates, and when the speed value is 0, the rotation speed is the fastest;
- input_acc is the acceleration at the beginning and end of the pan-tilt rotation, the lower the value, the smoother the start and stop. When the acceleration value is 0, it rotates according to the maximum acceleration.
Running the following code, you can see that the pan-tilt will move 45° to the right and up and then stop.
input_x = 45 input_y = 45 input_speed = 0 input_acc = 0 base.gimbal_ctrl(input_x, input_y, input_speed, input_acc)
In addition to controlling the pan-tilt movement by changing the rotation angle of the two servos in the pan-tilt, you can also directly control the pan-tilt continuous movement.
Change the value in the following code, in the following code:
- input_x is the rotation mode of the pan-tilt pan servo. When the value is -1, it means that the pan-tilt is continuously rotated to the left (clockwise); When the value is 1, it means that the pan-tilt is continuously rotated to the right (counterclockwise); When the value is 0, it means that the rotation is stopped.
- input_y is the rotation mode of the pan-tilt tilt servo. When the value is -1, it means that the pan-tilt tilt servo continuously rotates downward (head down); When the value is 1, it means that the pan-tilt tilt servo continuously rotates upwards (heads up); When the value is 0, it means that the rotation is stopped.
- input_speed is the speed at which the pan-tilt is rotated.
Only when the value of input_x and input_y is 2, the pan-tilt will automatically return to the median position.
Run the following code and the pan-tilt will move to the left until it stops when the movement reaches 180°.
input_x = -1 input_y = 0 input_speed = 0 base.gimbal_base_ctrl(input_x, input_y, input_speed)
Run the following code, the pan-tilt will move upwards and stop when the movement reaches 90°.
input_x = 0 input_y = 1 input_speed = 0 base.gimbal_base_ctrl(input_x, input_y, input_speed)
Finally, run the following code to return the pan-tilt to the middle position.
input_x = 2 input_y = 2 input_speed = 0 base.gimbal_base_ctrl(input_x, input_y, input_speed)
LED Lighting Control
Basic Introduction
WAVE ROVER and UGV series products, the driver board integrates two 12V switch control interfaces (the actual maximum voltage will change with the battery voltage), respectively, the IO4 and IO5 pins of ESP32 are controlled through the MOS tube, each corresponding to two interfaces, a total of 4 12V switch control interfaces, according to the default assembly method, IO4 controls the chassis headlights (WAVE ROVER does not have chassis headlights), IO5 controls the headlights, you can control the switch of these two interfaces and control the voltage by sending corresponding commands to the lower computer (but due to the MOS tube control itself has a certain delay, the PWM of the IO output of ESP32 is not linear with the voltage output of the actual interface).
For products that are not equipped with LED lights, you can expand the 12.6V withstand voltage LED lights on these two 12V switch control interfaces (under normal circumstances, the 12V withstand voltage can also be used, because in order to safety and protect the battery, the UPS of the product will not charge the battery above 12V), you can also expand other peripherals on the remaining switch control interfaces - such as the 12V water bomb gun gearbox, which is directly connected to the IO5 control interface, and can realize the function of automatic aiming and shooting.
If you need to run a program within a code block, you can select the code block you want to run and press Ctrl+Enter to run the program, or if you are using JupyterLab on your phone or tablet, you can press the triangle play button above to run the code block.
In the above code block we import and instantiate the library used to control the chassis, and then control the switch of the IO4 interface, the variable IO4_PWM is the PWM of the IO4 pin output of ESP32, the variable range is 0-255, when the value of this variable is 0, the interface switch of the IO4 control is turned off; When this variable is 255, the output voltage of the IO4 controlled interface switch is close to the BAT voltage of the UPS (the voltage of the current three lithium batteries in the UPS in series).
Run the following code block to turn on the interface switch for IO4 control (light up the chassis headlights). Note: The WAVE ROVE does not have chassis headlights, so there is no change to run the following code block, you need to run the next code block that turns on the headlights to turn on the headlights, the headlights are located on the camera pan-tilt, if the product is not equipped with a camera pan-tilt, there are no headlights.
IO4_PWM = 255 IO5_PWM = 0 base.lights_ctrl(IO4_PWM, IO5_PWM)
Run the following code block to turn on the interface switch of IO5 control (light up the pan-tilt headlight). Note: If the product is not equipped with a camera pan-tilt, there is no headlamp.
IO4_PWM = 255 IO5_PWM = 255 base.lights_ctrl(IO4_PWM, IO5_PWM)
If your product has LEDs that should all be lit up by now, you can run the following code block to reduce the brightness of the LEDs:
IO4_PWM = 64 IO5_PWM = 64 base.lights_ctrl(IO4_PWM, IO5_PWM)
Finally, run the following code block to turn off the LED lights.
base.lights_ctrl(0, 0)
Here runs a code block integrated with pan-tilt functionality.
import time base.gimbal_ctrl(0, 0, 0, 0) base.lights_ctrl(255, 255) time.sleep(0.3) base.gimbal_ctrl(45, 0, 0, 0) base.lights_ctrl(0, 0) time.sleep(0.3) base.gimbal_ctrl(-45, 0, 0, 0) base.lights_ctrl(255, 255) time.sleep(0.3) base.gimbal_ctrl(0, 90, 0, 0) base.lights_ctrl(0, 0) time.sleep(0.3) base.gimbal_ctrl(0, 0, 0, 0)