# How to code a spider robot (four-legged)
Are you into the fantastic world in the movie Spider-Man: Across the Spider-Verse? Spider-man in the story is really cool.
Are you interested in building a robot of your own?
This #How to shows you how to build a four-legged spider robot that can walk and rotatewith mBot Mega.
# The first thing to know#
In short, we can send a signal to the servo to tell it how much it should rotate and then stay in that position. However, how does it know where to start turning and how to turn?
We need to make some rules.
Now, let's see how two servos are mounted on one leg of the robot.
Each leg of the robot has two servos.
The "up" servo controls the swing of the upper leg parallel to the ground. The "down" servo controls the swing of the lower leg perpendicular to the ground.
Finally, the robot we build looks like that in the above picture.
For illustration purposes, we name the 8 servos according to their positions (the abbreviations are the names of the servos in the servo variables set of the program).
Now, we have a four-legged robot, how do we get it moving?
Imagine how we humans move.
We raise our left leg, step forward, and land on our left foot. Then we raise our right leg, step forward, and land on our right foot.
A four-legged robot moves the same way except that it needs to move two legs at the same time.
Function Design Idea:
Start with the initial angles
Step 1: Lift the front-left and back-right feet
Step 2: Turn the front-left and back-right feet (stepping)
Step 3: Place front-left and back-right feet (landing)
Step 4: Reset the moved front-left and back-right legs to the initial angles
Step 5: Lift the front-right and back-left legs
Step 6: Turn the front-right and back-left legs (stepping)
Step 7: Place the front-right and back-left legs (landing)
Step 8: Reset the moved front-right and back-left legs to the initial angles
# Coding Time #
Think about how to make it go to the left.
We just need to modify the rotation direction of the two legs at Step 2.
Think about how to make it go to the right.
Think about how to make it rotate counterclockwise.