User Manual

Table Of Contents
70
11 Calling the API to Control the Robot
For the reason that the movement and other functions of walking robots are much more complicated than
wheeled robots:
The wheeled robot only needs to control the high and low levels of a few GPIO ports to control the
movement of the robot.
The walking robot needs to control the angle change of a dozen servos, which involves the change of
the movement direction and the generation of gait, and it needs a lot of code to realize the movement of the
walking robot.
If the code related to the motion control of the walking robot is written into `server.py` or `webServer.py`,
the readability of the program will become poor, so we separate the communication from the underlying motion
control program.
The code responsible for controlling the movement of the robot is in `move.py` and `RPIservo.py` in the
`server` folder.
If you want to change the communication method of the robot, or want to write a program to control the
robot, and do not want to reconstruct the code of the underlying motion control and gait generation, you can
refer to the API introduced in this chapter to control the robot. The content introduced in this chapter is also the
method used by our `webServer.py` or `server.py` to control the robot movement.
First of all, your program needs to be placed in the same file directory as `move.py` and `RPIservo.py`,
and import `move.py` and `RPIservo.py`:
import move
import RPIservo
After importing, the related thread that controls the robot's gait will be automatically opened in the
background. If there is no command, the thread will be suspended. Put all servos in the initial position in
RPIservo.py, the default is `300`, the value will change after fine adjustment of the servo position:
init_pwm0 = 300
init_pwm1 = 300
init_pwm2 = 300
init_pwm3 = 300
init_pwm4 = 300
init_pwm5 = 300
init_pwm6 = 300