Welcome to Muto RS Robot repository
4)Robot forward and backward
4.Robot forward and backward
4.Robot forward and backward1.Experimental purpose2.Experimental preparation3.Experimental process4.Experiment summary
1.Experimental purpose
This course mainly learns how to control the forward, backward and stop functions of the robot.
2.Experimental preparation
The functions of the Muto hexapod robot Python library involved in this course are:
forward(step): Go forward, step is the width of the step, the greater the effective value, the greater the width of each step. The value range of step is [10, 25].
back(step): Go back, step is the width of the step, the larger the effective value, the larger the width of each step. The value range of step is [10, 25].
stop(): Stop movement.
reset(): Reset the robot and the robot will stand in the initial posture.
speed(level): Controls the speed of robot movement. The value range of level is [1-5]. The larger the value, the faster the movement frequency.
3.Experimental process
Open the jupyterLab client and find the code path:
muto/Samples/Control/4.forward_back.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", "停止"),'Forward': ("Forward", "前进"),'Backward': ("Backward", "后退"),'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['Forward'][g_ENABLE_CHINESE]:g_bot.forward(g_step)elif b.description == Name_widgets['Backward'][g_ENABLE_CHINESE]:g_bot.back(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_forward.icon == 'check':g_bot.forward(g_step)elif button_backward.icon == 'check':g_bot.back(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, JupyterLab control is used to control the forward, backward and stop functions of the six-legged robot. For example, set Step to 20, Speed to 2, and then click the Forward button, the six-legged robot will move forward. At this time, the Forward button will be ticked, and the pressed command 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.

To exit the program, press the End button to exit the program.