Welcome to DOGZILLA-Lite repository
9. Teaching mode
Teaching mode
1. Purpose
Understanding the robot dog's self-stabilization mode
2. Experimental path source code
Enter the robot dog system, end the robot dog program, enter "ip (ip is the robot dog's ip): 8888" in the browser, and enter the password "yahboom" 
Then log in and go to cd ~/DOGZILLA_Lite_class/3.Dog Base Control/09.Puppy Teaching Mode and run teach_by_demon.ipynb .
3. Experimental Phenomenon
After running the program, press the buttons according to the prompts on the screen. The screen prompts are in English by default. If you want to change to Chinese, you need to change False to true, as shown in the figure:
the screen prompts will become Chinese.
Buttons on the left and right sides of the screen A: Record button B: Stop recording button C: Exit button D: Execute the recorded action group (up to 12 action groups can be stored)
4. Main source code analysis
try: while True: if button.press_c():#这个是A键 A Key lcd_rect(0,0,320,240,color=color_black,thickness=-1) dog.unload_allmotor() data[n] = dog.read_motor() print(data) lcd_draw_string(draw,110,100, show_body['ACTION'][g_ENABLE_CHINESE]+(str(n+1)), color=(255,255,255), scale=font2, mono_space=False) lcd_draw_string(draw,20,150,show_body['MAX'][g_ENABLE_CHINESE], color=(255,255,255), scale=font2, mono_space=False) display.ShowImage(splash) time.sleep(0.02) lcd_rect(0,0,320,240,color=color_black,thickness=-1) n = n + 1 print(n) if n > 12: break if button.press_d():#这个是B键 B Key lcd_rect(0,0,320,240,color=color_black,thickness=-1) dog.load_allmotor() lcd_draw_string(draw,40,100, show_body['READY'][g_ENABLE_CHINESE], color=(255,255,255), scale=font2, mono_space=False) display.ShowImage(splash) time.sleep(0.02) lcd_rect(0,0,320,240,color=color_black,thickness=-1) if button.press_a(): #这个是D键 D Key lcd_rect(0,0,320,240,color=color_black,thickness=-1) lcd_draw_string(draw,66,100, show_body['EXECUTING'][g_ENABLE_CHINESE], color=(255,255,255), scale=font2, mono_space=False) display.ShowImage(splash) time.sleep(0.02) lcd_rect(0,0,320,240,color=color_black,thickness=-1) for d in data: if d!=[]: dog.motor(servo,d) print(d) time.sleep(0.8) print('action done!') lcd_draw_string(draw,100,100, show_body['DONE'][g_ENABLE_CHINESE], color=(255,255,255), scale=font2, mono_space=False) display.ShowImage(splash) if button.press_b():#这个是C键 C Key dog.load_allmotor() dog.reset() breakexcept: dog.reset()The key description of the experimental phenomenon is the code above. By writing and analyzing the code, we can get the function that executes the action group: motor function. The function to unload the servo is: unload_allmotor (this is a function interface that does not pass parameters and unloads all servos at one time). The function to load the servo is: load_allmotor (this is a function interface that does not pass parameters and loads all servos at one time). The function to read the servo is: read_motor (this is a function that reads the current angles of all servos at one time).
Conclusion: The process of this mode is roughly as follows: Unload the servo -> read the servo angle and save it (up to 12 groups) -> load the servo -> execute the saved action group. Note: After unloading the servo, if you want the robot dog to stay standing, remember to have something to support its body.