# How to Code a Spider Robot (four-legged)

Four-legged spider robot

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 spider robot of your own? 
This #How to shows you how to build a spider robot that can walk and rotatewith mBot Mega. Let's start with a four-legged spider robot!

Let's start!

# The first thing to know#

The first thing to know#
Servo

In short, we can send a signal to the servo to tell it how much your  spider robot 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.

Set rules for Servo

Now, let's see how two servos are mounted on one leg of a spider robot.

Each leg of the spider 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.

Use mBot mega to code a spider robot

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).

Four-legged robot

Now, we have a spider 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 spider 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 #

# Coding Time #
Coding tutorials for spider robotCoding tutorials for spider robot

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.

Coding tutorials for spider robot

Think about how to make it go to the right.

Coding tutorials for spider robotCoding tutorials for spider robot

Think about how to make it rotate counterclockwise. 

Spider robot transformed from mBot megaSpider robot transformed from mBot mega
# Bring Me Home ^_^ #
3.jpg__PID:933f2b29-ff12-4a22-ab73-faaef283c72d

Makeblock mBot Mega: Smart Remote Control Robot Car for Kids to Learn through Play

$128.79
$129.99

# Bring Me Home ^_^ #