In this control engineering and robotics tutorial, we explain the basics of position controllers for mobile robots. As a test case, we use a differential drive robot. Differential drive robots are also called differential wheeled robots. We design a simple proportional controller that will drive the robot center from the initial to the desired location. We use a kinematics robot model developed in our previous tutorial to simulate the robot’s motion. We explain how to generate a 2D Pygame animation that simulates the robot’s motion and control performance. Here, it should be kept in mind that we develop a controller that is based on the kinematics of the robot without taking into account the robot’s dynamics described by mass, moments of inertia, and dynamics equations. The Python scripts used to implement the control algorithm and to simulate robot motion are available here.
The YouTube tutorial accompanying this post is given below.
Differential Drive Robot Position Controller
Here, we first briefly summarize the kinematics diagram and the kinematics differential equation model of the robot. For details, see our previous tutorial given here. The robot kinematic diagram is shown below.
The symbols used in this figure are explained below.
and are the translation coordinates of the body frame attached to the point with respect to the inertial frame . is the angle of rotation of the robot which is at the same time the angle between the body frame and the inertial frame. and are the coordinates in the body frame and at the same time they denote the axes of the body frame. is the instantaneous center of rotation. is the instantaneous angular velocity of the robot body. is the center point of the left wheel. is the center point of the right wheel. is the middle point between the points and . is the velocity of the center of the left wheel. is the velocity of the center of the right wheel. is the velocity of the point . is the angular velocity of the left wheel. is the angular velocity of the right wheel. is the distance between the point and the point . is the radius of the wheels. is the distance between the points and . is the projection of the velocity on the axis. is the projection of the velocity on the axis.
The kinematics system of differential equations describing the robot motion is given below (for more details, see our previous tutorial, given here):
(1)
On the other hand, for the implementation of the control algorithm, we need another equation relating
(2)
The robot is controlled by controlling the left and right wheel angular velocities represented by
In this tutorial, we are mainly interested in driving the center of the robot
Control Problem Formulation: Let
There are a number of approaches to solving this problem. Since this is an introductory tutorial, we will use a relatively simple approach based on a proportional controller. Here, the interested reader should keep in mind that this is NOT the most optimal controller that will optimize the travel distance, used energy, or a similar quantity.
The following diagram is instrumental in deriving the control algorithm
Let us suppose that at some time instant
Here, one important geometrical observation should be made. The velocity vector
From the current robot’s position, we can calculate the desired orientation angle
(3)
or
(4)
where the
The first controller is the controller that will change
(5)
where
What is the physical meaning of the equation (5)? If the
The orientation controller actually controls the angle of the velocity. However, we need a controller that will control the magnitude of the velocity. This controller will implicitly also control the position of the robot. The second controller has the following form
(6)
where
The controllers (5) and (6) determine the values of
(7)
That is, we invert the parameter matrix
(8)
Now, we are ready to summarize the control algorithm.
Summary of Control Algorithm for Differential Drive Robot
The control algorithm consists of the following steps.
- We observe the robot position
and the robot orientation - We compute
(9)
- We compute the desired angular wheel velocities
and as follows(10)
- Apply the computed values
and to the left and right wheel motor controllers that will generate the torques and move the wheels of the differential drive robot.
As mentioned at the beginning of this tutorial, we are not considering the dynamics of the robot. For us, the complete robot model is described by the kinematics equations (1). We are aware that this is an approximation, however, for robots with small masses and small moments of inertia this approximation can be sufficiently accurate to design the control inputs. Consequently, in our simulation, the model (1) serves as the “true” physical model of the robot. Over here, we write again these equations for clarity:
(11)
That is, in our simulations, once we compute
Python Simulation and Animation of Controller for Differential Drive Robot
We have developed Python codes for implementing the controller and for simulating the robot’s motion. We used Pygame to simulate the robot’s motion. The animations are shown in the video below. The Python scripts used to implement the control algorithm and to simulate robot motion are available here.