Manual
50
Compile the code, upload the code to SunFounder Servo Control Board, and then remove
the USB cable.
Switch on SunFounder Servo Control Board. The robot will dance for a while.
When the robot stops, switch on SunFounder Mobile Robot Remote Controller. Now, you can
use it to make the robot dancing.
6. Code Explanation
Overview
For the quadruped, you can not only learn things about robotics and electrics, but also the
code that animates the robot. In this section, the core code of the sketch, manipulator
model of each leg, and proof of the model as well as the corresponding code for the proof
will be presented in detail. When you've thoroughly understood these, you can write your
own code for the robot! For example, you may write a sketch to make the robot swing the
legs when walking, or sway a bit, walk in a bigger pace, dance more steps, etc. Sound
amazing? Let's get started!
Core Code
This chapter focuses on how to transform the coordinates of the end of each leg into the
rotational angle of each servo. First check the functions void cartesian_to_polar (volatile float
&alpha, volatile float &beta, volatile float &gamma, volatile float x, volatile float y, and
volatile float z). These are the core of the code for the quadruped robot, which is to transform
the coordinates of the legs into the servo rotational angles.
Parameters: alpha, beta, gamma, the address that stores the output angle.
Parameters: x, y, z, the coordinates of the position of the leg end.
The source code of cartesian_to_polar:
/*
- trans site from cartesian to polar
SunFounder