Welcome to Muto S2 Robot repository
5.Robot move left and right
5.Robot move left and right
5.Robot move left and right1.Experimental purpose2.Experimental preparation3.Experimental process4.Experiment summary
1.Experimental purpose
This course mainly learns how to control the left and right translation function of the robot.
2.Experimental preparation
The functions of the Muto hexapod robot Python library involved in this course are:
left(step): left translation, step is the step width, the larger the effective value, the larger the width of each step. The value range of step is [10, 25].
right(step): Right translation, step is the step width, the larger the effective value, the larger the width of each step. The value range of step is [10, 25].
3.Experimental process
Open the jupyterLab client and find the code path:
muto/Samples/Control/5.left_right.ipynb
By default g_ENABLE_CHINESE=False, if you need to display Chinese, please set g_ENABLE_CHINESE=True.
x# 中文开关,默认为英文 Chinese switch. The default value is Englishg_ENABLE_CHINESE = FalseName_widgets = {'Stop': ("Stop", "停止"),'Left': ("Left", "左平移"),'Right': ("Right", "右平移"),'End': ("End", "结束")}
Click to run all cells, and then scroll to the bottom to see the generated controls.

Click different buttons to correspond to different functions.

Every time a button is clicked, the corresponding function will be executed. Key event processing:
xxxxxxxxxx# 按键按下事件处理 Key press event processingdef on_button_clicked(b):ALL_Uncheck()b.icon = 'check'with output:print("Button clicked:", b.description)if b.description == Name_widgets['Stop'][g_ENABLE_CHINESE]:g_bot.stop()b.icon = 'uncheck'elif b.description == Name_widgets['Left'][g_ENABLE_CHINESE]:g_bot.left(g_step)elif b.description == Name_widgets['Right'][g_ENABLE_CHINESE]:g_bot.right(g_step)
The variable g_step is controlled by the Step slider. When the value of the slider changes, it will detect which button has been pressed, and the value of g_step will be updated immediately to the robot.
xxxxxxxxxxdef on_slider_step(value):global g_stepg_step = valueif button_move_left.icon == 'check':g_bot.left(g_step)elif button_move_right.icon == 'check':g_bot.right(g_step)print("step:", value)
The robot's movement speed is controlled by the Speed slider.
When the slider value changes, the robot's movement speed is immediately updated.
xxxxxxxxxxdef on_slider_speed(value):global g_botg_bot.speed(value)print("speed:", value)
4.Experiment summary
This time, the JupyterLab control is used to control the speed and left and right translation of the six-legged robot. For example, set Step to 20, Speed to 2, and then click the Left button, the six-legged robot will translate to the left. At this time, the Left button will be ticked, and the command to be pressed will be prompted below the control. At this time, if you change the value of the Step or Speed slider, you can see the robot's step width and speed change.
When you need to stop, please click the Stop button to stop.

Press the End button to exit the program.