*Figure 1. My Zumo robot for Arduino running at its maximum speed.*

When trying to control and model systems, it’s helpful to try to make connections to systems you’re already familiar with. One of the most celebrated systems in physics is the pendulum. So many systems can be described by the mathematics of the pendulum that a general term for such systems is used: they’re called harmonic oscillators. Another beautiful consequence of making this connection is that we’ll end up with a controller design with performance characteristics that do not depend upon the robot’s velocity.

How is a line-following robot like a harmonic oscillator? In the simplest case, the robot should be able to follow a straight line no matter how it’s originally oriented, so long as some of its sensors are still on the line. The robot should correct its orientation while moving along the line, eventually settling down to a path that’s on and parallel to the line.

Imagine lifting a pendulum out of its resting position and dropping it. The pendulum will swing back to its equilibrium, overshoot it, swing back, and so forth, slowly settling down to rest. This is very similar to the robot as it tracks a straight line. The main difference between the two systems is that the robot must turn about its center in order to change direction, while the pendulum bob has no such need. Intuitively, there must be a connection between these two systems.

To determine the precise connection, consider the following drawing.

*Figure 2. A robot displaced from a line and at an angle θ to it moving forward at a velocity v.*

The robot is moving with a forward velocity *v*, is displaced from the line, and is heading at an angle *θ* measured off the line. If the control system is properly designed, the angle *θ* should be small, so we can approximate the velocity components that are parallel and perpendicular to the line. The velocity components are approximated by

Recall that the equation of motion for a damped pendulum is

where *x* is the horizontal distance measured from the rest position, ζ (zeta) is the damping ratio, and α (alpha) is the harmonic frequency of the pendulum.

Just as the pendulum equation is concerned only with the horizontal displacement of the bob from rest, we will focus on the perpendicular distance of the robot from the line. We’ll change notation to make the connection clearer:

The perpendicular acceleration of the robot is then

where ω is the turning rate of the robot about its center. Notice we’ve also assumed the forward velocity of the robot to be constant. This choice makes controlling the robot simpler, focusing the controller design onto one variable, rather than two.

So far, the robot’s equation of motion is

The turning rate and forward velocities are the controlled parameters. The perpendicular distance *x* is determined by the robot’s sensors, and this signal can be differentiated to find *x*‘. What is the robot’s harmonic frequency α? While the pendulum is governed by gravity and its physical parameters, the robot is governed by our controller and our design choices, so we have to prescribe α (and ζ).

The choice of α will determine how quickly the robot will oscillate from one side of the line to the other. We can think about our choice in terms of a reasonable distance the robot should travel along the line before it makes a full swing from one side to the other. A natural unit of distance is the robot’s own body length. So, we should consider how the robot’s body length compares to the length of the wave the robot sweeps out as it oscillates about the line.

The length of that wave λ is

where *T* is the period of the wave (in units of time). So we see that the harmonic frequency is related to the wave length by

Now you can determine α based on a choice of λ, which you can think of in terms of the robot’s body length. For example, you might choose λ to be four times the robot’s body length.

The last parameter to discuss in the robot’s equation of motion is the damping ratio ζ. The value of ζ will determine how quickly the robot will settle down to the straight path. Let me point you to some excellent resources that discuss the effect ζ has on harmonic oscillators: Control Tutorials for MATLAB and Simulink , and Damping Ratio on Wikipedia.

Connecting the physics of the pendulum and the line-following robot affords a clear way to think about the control problem and its design. This approach is philosophically fun and even gives a controller design with a stability that does not depend upon the forward velocity of the robot, so long as the velocity does not push the physical limits of the robot’s construction.

My robot at the top of this article is going at its maximum speed. Can you push your robot to its limit? You can share links to videos of your line-following robot in the comments below.

Hi, Do you have code for simulating a line follower robot in MATLAB?. If you have please send

Hello Trinayan,

To learn how to simulate and control a line following robot, I recommend reading this research paper.