f
t
i
=
f
t
i,pre
+
f
t
i,post
+
G +
f
t
i,leg
; (1)
f
t
i,pre
=
f
t
i1,i,s
+
f
t
i1,i,d
; (2)
f
t
i,post
=
f
t
i+1,i,s
+
f
t
i+1,i,d
; (3)
f
t
i1,i,s
=
s
x
t
i1
x
t
i
x
t
i1
x
t
i
( x
t
i1
x
t
i
L
i1,i
) (4)
f
t
i1,i,d
=
d
x
t
i1
x
t
i
x
t
i1
x
t
i
x
t
i1
x
t
i
x
t1
i1
x
t1
i
dt
(5)
Fig. 7. Two Leg States
v
t+1
i
= v
t
i
+
f
t+1
i
dt
m
; (6)
x
t+1
i
= x
t
i
+v
t+1
i
dt. (7)
Here, in Eq. (1), f
t
i
is the force on ith node at time t. f
t
i,pre
and f
t
i,post
are the pushing or pulling forces by connecting
spring-damper from the previous node and post node. Eq.
(2) and (3) shows that the forces from the link have two
components, one from spring, another from damper. In Eq.
(4)(5), the spring and damper forces is calculated from node
positions x and spring-damper coefcients
s
and
d
. G
is gravity. f
t
i,leg
is the pushing-forward force due to leg
rotation. This force is calculated with rigid body dynamics.
With the equation of forces determined by Eq. (1),(2),(3),(4)
and (5), the position of individual nodes can be updated
through Eq. (6) and (7).
Different schemes can be applied to solve these equations
numerically, I will leave this part to the following subsec-
tion.
C. Solve the Equations: Implicit Euler Method
There are two ways to solve the equations numerically,
one way is called explicit euler method, the other is called
implicit euler method. In the explicit euler method, forces
on each node are calculated at each discrete time step from
current calculated positions, then used to calculate the next
time steps velocities and positions, explicit euler method
is a forward integration method, it is simple to code and
calculate, but fatally unstable when the spring constants
are large. On the other hand, implicit euler method uses
positions from future(which is unknown) to solve for current
forces(a function of to be solved future positions), then
the forces would result in future velocities and positions.
This implicit method is a backward integration method and
results in a system of linear equations to be solved for
the unknowns(future positions). Depends on how large the
matrix is, mathematical tricks can be applied to do the
matrix inversion faster. In my problem, the matrix size
would be NN with N denoting the number of nodes the
millipede has. Since N is relatively small(around the order
of 10)for our simulation, I did matrix inversion directly. The
calculation is fast enough for real time simulation.
_
_
_
_
_
_
_
_
x
t+1
1
x
t+1
2
.
.
.
x
t+1
n
_
_
_
_
_
_
_
_
=
_
_
_
_
_
_
_
_
x
t
1
x
t
2
.
.
.
x
t
n
_
_
_
_
_
_
_
_
+
_
_
_
_
_
_
_
_
v
t
1
v
t
2
.
.
.
v
t
n
_
_
_
_
_
_
_
_
dt+
_
_
_
_
_
_
_
_
f
t+1
1
f
t+1
2
.
.
.
f
t+1
n
_
_
_
_
_
_
_
_
1
m
dt
2
(8)
The system of equations to be solved are derived from Eq.(6)
and (7), listed in Eq. (8). Denition of f
t+1
i
is derived from
Eq. (1),(2),(3),(4) and (5), listed in Eq. (9). By using f
t+1
i
rather than f
t
i
, the equation set becomes implicit and must
be solved together. In order to simply the problem to a linear
one, in Eq. (9), notice that the none linear part x
t
i1
x
t
i
,
which is the current length of spring-damper, is used to
represent the future spring-damper length x
t+1
i1
x
t+1
i
.
Eventually, Eq (9) can be simplied to Eq. (10), presenting
a linear relationship between forces and node positions.
Putting Eq. (10) back to Eq. (8) would generate a linear
equation set denoted by Eq. (12).
f
t+1
i
=
f
t+1
i,pre
+
f
t+1
i,post
=
s
x
t+1
i1
x
t+1
i
x
t
i1
x
t
i
( x
t
i1
x
t
i
L
i1,i
)
+
d
x
t+1
i1
x
t+1
i
x
t
i1
x
t
i
x
t
i1
x
t
i
x
t1
i1
x
t1
i
dt
+
s
x
t+1
i+1
x
t+1
i
x
t
i+1
x
t
i
( x
t
i+1
x
t
i
L
i,i+1
)
+
d
x
t+1
i+1
x
t+1
i
x
t
i+1
x
t
i
x
t
i+1
x
t
i
x
t1
i+1
x
t1
i
dt
(9)
f
t+1
i
= a
1
x
t+1
i1
+ a
2
x
t+1
i
+ a
3
x
t+1
i+1
(10)
With:
_
_
a
1
=
s
(1
Li1,i
x
t
i1
x
t
i
) +
d
dt
(1
x
t1
i1
x
t1
i
x
t
i1
x
t
i
)
a
2
= a
1
a
3
a
3
=
s
(1
Li,i+1
x
t
i+1
x
t
i
) +
d
dt
(1
x
t1
i+1
x
t1
i
x
t
i+1
x
t
i
)
(11)
A
t
x
t+1
= b
t
(12)
x
t+1
= A
t
1
b
t
(13)
Solving Eq. (12) would be difcult and requires special
treatment of the matrix when A
t
is very big, however, in
our case, A
t
is at the order of 10, so simply inverse the
matrix and multiply to b
t
would work fast enough to give
real time simulation. Solving the equations frame by frame
and display the millipede can give a vivid moving millipede
on screen in 3D environment. Before applying this implicit
method, explicit method is used and actually gives quite
unstable results. The new implicit method gives more stable
results compared to the explicit one.
IV. ANTENNAS: PERCEPTION SYSTEM
With the Bio-Mechanical Model, the millepede can move
around freely like a drunk toper. However, I want it to
be more intelligent. According to the pyramid of articial
life (from low-level motion to high-level intelligence), my
millipede can go to the perception level.
A creature with perception could usually do some info-
exchange with its living environment. By sensing and ex-
changing information it exhibits some basic behaviors which
is a sign of intelligence.
A. Road Detector: See
A lot of methods of modeling a visual system have been
studied[7]. One of the most popular solutions is ray tracing.
While doing ray tracing, the creatures virtual eyes keep
shooting imaginary ray beams to a range of directions that
belong to its visual scope. If a ray beam detects something
within the scope, it will send back a signal to the corre-
sponding eye. For instance, when a predators rays detect a
prey, they will inform the eye every bit of information they
get. By analyzing these information, the eyes build a data
structure that stores some characteristics of the object seen,
like shape, color, distance to eye, e.t.c. This method can
get more complicated by introducing complicated computer
vision techniques into it.
In my millepede model, I assume the millepede has no
eyes. The mechanism it uses to prevent being stopped by an
obstacle is an antenna system. Figure 4, there are antennas
directing forward on both sides of the head. The mechanism
of the two antennas is very similar with the ray tracing eyes
except the fact that it is much simpler.
Recall Figure 3, most real millepede do not have eyes.
The only thing that prevents the millepede from knocking
Fig. 8. The Food Detector. Antennas sense the smell of food.
into an obstacle is the antenna system. When moving
forward, the virtual millepede uses its antennas to feel
things, like a blind man using a walking stick. Either antenna
detecting an obstacle will trigger a signal to brain. The brain
receives this signal, then let the motion controller to turn to
the other side. The antenna system works very much like
the Breitenberg vehicle, which is simple and useful.
The millepedes antennas are always working. Therefore,
as long as the antennas are long enough, it could turn in
time. However, if we decrease the length of antennas, the
millepede would perhaps knock into an obstacle, because
the amplitude of turning angle is limited. The millepede can
only turn a small angle while still moving forward, i.e., a
pivot turn around body center is not possible for a millepede.
In real world, all millepede antennas are long enough. I
guess those with short antennas had vanished during the
millions of years because they keep on hitting rocks!
B. Food Detector: Smell
As pointed out in the 3D model section, a real antenna
can also sense the molecules in the air so that the millepede
knows where to nd food or lovers to mate, this is similar
to how human noses works (Figure 8).
For detection of food, the antenna has a searching area,
within which it can detect the molecular signal of food in
the air, it will tell the brain how far the food is and in
which direction it lies. In our simulation, the millepede
would simply focus on the closest food, which would
send the strongest molecular signal in the air. After the
antenna transmit information of smell to brain, the brain
will judge the smells from different sources, gure out
the source positions and make a turn to reach the nearest
one. If no obstacles are in front of the millepede, it will
move straightly toward the food. Otherwise, the behavior
of avoiding obstacle has priority over moving toward food.
The millipede makes decision on the y and can change its
decisions when new closer sources are detected.
V. CODING NOTES
A. Design of Classes
The articial millipede is coded using C++, all together
about 4000 lines. OpenGL library is used for drawing
graphics. All the codes can be downloaded from the project
website listed in Appendix I. The millipede class is designed
and has the variables and functions listed in Table.(I). Notice
that for millipede class, three other classes are created and
used, namely: Section, Antenna and Map. The Section class
is designed to compose the body of the millipede, and its
contents are given in Table.(II). The Map class provides
the map for the millipede to live in, and need be signed to
each millipede, it contains the shape of the ground, obstacles
and food sources. The Antenna class provides the millipede
with eyes and noses such that the brain of the millipede has
information to analyze.
There are three modes for the brain, each has different
functions and priorities. The rst mode is called random
walk mode, which has the lowest priority and is determined
by the lower part of the brain (which we call instinct
before). The second mode is called obstacle avoiding mode,
it has higher priority than the random walk mode. When
the millipedes antenna detects an obstacle, the brain would
immediately enter this mode and take actions after analyzing
the signal. The third mode is called the food tracking mode.
It has a higher priority than the random walking mode but
lower priority than the obstacle avoiding mode. When the
millipedes antenna detects a signal of food within its scope,
the brain would enter the food tracking mode and give
orders to the body such it turns toward the food source.
The obstacle avoiding mode has the highest priority and can
always interrupt other modes. New modes can be designed
and given different priorities, such as predator closing mode,
etc.
B. Within Each Frame
During each frame, the program do the following things
sequentially:
If in random walking mode, smell and search for food,
if detected food, enter food preying mode.
If not in obstacle avoiding mode, look around to check
obstacle, if see obstacle, enter obstacle avoiding mode.
Based on which mode the millipede is in and the
input information from antenna, millipede brain tells
the body how to move.
All the rotations are carried out and the matrix is solved
to resolve positions and velocities of all the sections for
current frame.
Display the millipede for current frame.
VI. SUMMARY
In summary, in this article, we conducted a complete
simulation of millepede for the rst time ever. The virtual
millepede has a physics guided motion system, an antenna
perception system and a brain.
TABLE I
DESIGN OF THE MILLIPEDE CLASS
variables for millipede class
variable name type notes
N Section private:int Number of sections
Head private:Section* Head section of millipede
AntennaL private:Antenna The left antenna
AntennaR private;Antenna The right antenna
Objective private:double Current objective turning angle
Process private:double Currently turned angle
BrainMode private:int The millipedes brain mode
MyMap private:Map* The associated map
Scope private:double The food search scope
functions for millipede class
function name return type notes
Centipede(void) no type Constructor
Centipede(void) no type Destructor
Set Head(Section*) public:void Set a section as millipede head
Get Head(void) public:Section* return the heads pointer
Get N(void) public:int return the number of sections
Set N(int) public:void set the number of sections
Brain(double) public:void process information/give orders
Move(double) private:void Core of bio-mechanics
Look(void) private:void Antennas touch feedback
Smell(void) private:void Antennas smell feedback
Set Map(Map*) public:void Set the associated map
Set Scope(double) public:void Set the smell scope
Get Scope(void) public:double return the scope
The Bio-Mechanical structure is simulated with spring-
dampers and rigid-body dynamics. Under the constraints
of a physical environment, the millepede can control the
movement of every body segment. Even assigned random
initial leg rotations, the millepede can automatically adjust
the legs and end up with all legs moving coordinately in a
wavelike pattern, which is actually the walking pattern of a
real millepede.
The perception system is made up with antennas. The
functions of antennas are very basic but essential. It pro-
vides two functionalities: road detection and food detection.
With this perception system, the millepede is able to avoid
obstacles while moving forward, and search for food at the
same time.
VII. ACKNOWLEDGEMENTS
Professor Demetri Terzopoulos is my mentor in the
Computer Science department. He is kind, modest and
knowledgeable. Without his support, I would not be able to
even join CS department, let alone working on this paper.
His course Articial Life opens my eyes and irritated my
interests to code an articial living thing by myself. Despite
being very busy, he respond to lots of my very simple
questions with detailed and careful explanations.
I also would like to sincerely thank my friend, Chenfanfu
Jiang, who is also a student of Demetri, for his help on
introducing Breitenberg vehicle to me.
Although I have never communicated with Xiao-Yuan Tu
[5] directly, her award-winning paper on Articial Fish
TABLE II
DESIGN OF THE SECTION CLASS
variables for Section class
variable name type notes
Index private:int Id number of section
Position[3] private:double Position of section
pPosition[3] private:double Previous Position of section
Color[3] private:double RGB color of the millipede
Dimension[3] private:double Size of the section
Velocity[3] private:double Speed of current section
NextSec private:Section* Pointer to the next section
PreSec private:Section* Pointer to the previous section
Force[3] private:double Calculated force on the section
Rlenght private:double Rest length of spring ahead
LegRotation private:double Current leg rotation
LegRotV private:int Direction of leg rotation
PushV private:double The rate of leg rotation
Direction private:double Direction of the front link
Fspring private:double Spring constant
Fdamper private:double Damper constant
functions for section class
function name return type notes
Section(void) no type Constructor
Section(void) no type Destructor
Set Color(double*) public:void Set a sections color
Set Dimension(double*) public:void* Set a sections size
Set LegRotation(double) public:void Set a sections leg rotation
Set Position(double*) public:void Set a sections position
Set pPosition(double*) public:void Set previous position
Set Index(int) public:void Set the id number
Set Next(Section*) public:void Set the next section
Set Prev(Section*) public:void Set the previous section
Set Velocity(double*) public:void Set the velocity
Set Fsrping(double) public:void Set the spring constant
Set Fdamper(double) public:void Set the damper constant
Set LegRotV(double) public:void Set the initial rotation direction
Set Direction(double) public:void Set the previous link direction
Set PushV(double) public:void Set the leg push rate
Get Position(void) public:double* Return the position
Get pPosition(void) public:double* Return previous position
Get Velocity(void) public:double* Return velocity
Get Color(void) public:double* Return the color of section
Get Dimension(void) public:double* Return the size of section
Get LegRotation(void) public:double Return the leg rotation
Get Direction(void) public:double Return previous link direction
Get Index(void) public:int Return the index number
Get PushV(void) public:double Return the push direction
Rotate All(double) public:void Rotate the leg and section
Get Next(void) public:Section* Return next section pointer
Get Prev(void) public:Section* Return previous section pointer
denitely enlightened me most on this piece of work of
Articial Millipede.
VIII. APPENDIX
1) The website of this project is:
https://sites.google.com/site/uclacs275/
2) Source codes are available at the website.
3) Demo of Locomotion: (Start with random leg cong-
uration, converge to wave very quickly): YouTube
4) Demo of Antenna System: (Tracing food and avoiding
obstacles): YouTube
REFERENCES
[1] http://en.wikipedia.org/wiki/Articial life
[2] Braitenberg, V. Vehicles: Experiments in synthetic psychology. Cam-
bridge, MA: MIT Press. (1984)
[3] Grieco, J.C.; Prieto, M.; Armada, M.; Gonzalez de Santos, P.; , A six-
legged climbing robot for high payloads, Control Applications, 1998.
Proceedings of the 1998 IEEE International Conference on , vol.1, no.,
pp.446-450 vol.1, 1-4 Sep (1998)
[4] Dorigo, M.; Maniezzo, V.; Colorni, A.; , Ant system: optimization
by a colony of cooperating agents, Systems, Man, and Cybernetics,
Part B: Cybernetics, IEEE Transactions on , vol.26, no.1, pp.29-41,
Feb (1996)
[5] Xiaoyuan Tu Articial Animals for Computer Animation: Biome-
chanics, Locomotion, Perception, and Behavior Ph.D Dissertation
, Department of Computer Science, University of Toronto, January
(1996)
[6] Auke Jan Ijspeert, Alessandro Crespi, Dimitri Ryczko, and Jean-Marie
Cabelguen From Swimming to Walking with a Salamander Robot
Driven by a Spinal Cord Model, Science 9 March 2007: 315 (5817),
1416-1420. (2007)
[7] Salomon, R.; Lichtensteiger, L.; , Exploring different coding schemes
for the evolution of an articial insect eye, Combinations of Evolu-
tionary Computation and Neural Networks, 2000 IEEE Symposium on
, vol., no., pp.10-16, (2000)