Welcome to Muto S2 Robot repository
2.Control PWM servo
2.Control PWM servo
2.Control PWM servo2.1 Experimental purpose2.2 Experimental preparation2.3 Experimental process2.4 Experiment summary
2.1 Experimental purpose
This course mainly learns how to control the functions of the robot servo gimbal.
Note: Since the RS version robot does not come with a servo gimbal by default, the RS version robot needs to bring its own PWM servo gimbal to proceed with this tutorial.
2.2 Experimental preparation
The functions of the Muto hexapod robot Python library involved in this course are:
Gimbal_1_2(S1, S2): Controls the servo gimbal. The parameters S1/S2 represent the angle value of the PWM servo S1/S2. The valid value range of S1 is [0, 180], and the valid value range of S2 is [0, 115].
When a certain value in S1/S2 is -1, it means that the PWM servo is not operated. If you only need to control the S1 servo and do not need to change the position of the S2 servo, just pass S2 to -1.
PWM servo gimbal wiring situation:
The lower servo is connected to S1
The upper servo is connected to S2
Black plugs into GND
Red plugs into 5V
Orange insert S1/S2


2.3 Experimental process
Open the jupyterLab client and find the code path:
muto/Samples/Control/2.pwm_servo.ipynb
By default g_ENABLE_CHINESE=False, if you need to display Chinese, please set g_ENABLE_CHINESE=True.
xxxxxxxxxx# 中文开关,默认为英文 Chinese switch. The default value is Englishg_ENABLE_CHINESE = FalseName_widgets = {'End': ("End", "结束")}
Click to run all cells, and then scroll to the bottom to see the generated controls.

You can control different functions by operating different controls separately.

Each time you slide the S1 slider, the angle of the robot's S1 servo will be immediately changed, thereby controlling the left and right rotation of the camera on the servo gimbal.
In the same way, every time you slide the S2 slider, the angle of the robot's S2 servo will be immediately changed, thereby controlling the up and down rotation of the camera on the servo platform.
xxxxxxxxxxdef pwm_servo(S1, S2):g_bot.Gimbal_1_2(S1, S2)return S1, S2
2.4 Experiment summary
This time, the JupyterLab control is used to control the hexapod's servo platform. You only need to drag the slider of S1/S2 to easily adjust the area where the camera on the servo platform collects images.

If you need to exit the program, please press the End button to exit the program. The program will automatically reset the servo gimbal to its initial position.
Note: Although the camera is mentioned in this routine, it does not drive the camera in the program. It is only used as a functional explanation. There will be routines related to the practical application of driving the servo + camera in subsequent courses.