Welcome to ROSMASTER R2 repository
5.5 Control PWM servo
5. Control PWM servo
5. Control PWM servo 5.1. Experimental objectives 5.2. Experiment preparation 5.3. Experimental effect 5.4. Program source code
5.1. Experimental objectives
Control the rotation of the PWM servo on the robot.
5.2. Experiment preparation
The position in the red box in the picture below is the interface of the PWM servo, including one servo voltage switching interface and four servo interfaces. The jumper cap can be inserted into the servo voltage switching interface to select 5V or 6.8V voltage. If the jumper cap is not inserted, the PWM servo cannot be controlled. The black interface of the servo interface is GND, the red interface is the positive pole of the 5V power supply, and the yellow interface is the signal.

The servo interface must be inserted according to the color, and cannot be inserted backwards.

Rosmaster_Lib library functions that PWM servo gimbal needs to use:
set_pwm_servo ( servo_id , angle )
Parameter explanation: servo control, servo_id: corresponding ID number: S1 = 1, S2 = 2, S3 = 3, S4 = 4, angle: corresponding to the angle value of the servo
servo_id=[1, 4],angle=[0, 180]
Return value: None.
xxxxxxxxxxset_pwm_servo_all ( angle_s1 , angle_s2 , angle_s3 , angle_s4 )
Parameter explanation: control the angle of four PWM channels at the same time, angle_sX=[0, 180]
Return value: None.
5.3. Experimental effect
Check out the course accompanying video.
5.4. Program source code
Power on the Rosmaster robot, and open the browser of the Jetson Nano or remote computer to enter the Jupyter lab editor.
Reference code path: Rosmaster/Samples/5.pwm_servo.ipynb