Are there any better/ advanced ways of steering a line following robot other than pid controller? If so what are them?

  • $\begingroup$ LQR is more robust, but more mathematically complicated and probably overkill for this problem. $\endgroup$
    – Paul
    Jul 4, 2016 at 4:13
  • $\begingroup$ What do your states look like? What are your inputs? What are the system dynamics? Are you just interested in following a line or is the desired position in space a function of time or some other aspect of the environment? $\endgroup$
    – holmeski
    Jul 4, 2016 at 19:15
  • $\begingroup$ Assume it is your ordinary LFR. I am not trying to program a specific line follower, but rather trying to find a new way to make a LFR with better steering etc. I'm interested in just following the line. If you could give me some pointers, (if there are other ways) I can look them up in the internet and learn on my own. :) $\endgroup$
    – Ivantha
    Jul 5, 2016 at 0:36
  • $\begingroup$ Welcome to Robotics Ivantha, but I'm afraid that Unbounded Design Questions are off-topic because there are many ways to solve any given design problem, so questions that ask for a list of approaches or a subjective recommendation on a method (for how to build something, how to accomplish something, what something is capable of, etc.) are off-topic. $\endgroup$
    – Chuck
    Jul 6, 2016 at 12:44

1 Answer 1


Because you don't have any specific robot in mind, let's assume that you have a two-wheeled differential drive robot (TWDDR). TWDDRs can be modeled with unicycle dynamics of the following form: $$\dot{z}=\left[\begin{matrix}\dot{x}\\ \dot{y} \\ \dot{\theta} \end{matrix}\right] = \left[\begin{matrix}cos(\theta)&0\\sin(\theta)&0\\0&1\end{matrix}\right] \left[\begin{matrix}v\\\omega\end{matrix}\right],$$ where $x$ and $y$ are Cartesian coordinates of the robot, and $\theta \in (-\pi,\pi]$ is the angle between the heading and the $x$-axis. The input vector $\left[v, \omega \right]^T$ consists of linear and angular velocity inputs. For simplicity, I will assume that you can specify these inputs directly, which is reasonable for most off-the-shelf robots--if you want to implement this from scratch, then you have to specify velocities for the left and right wheels.

Following a line is essentially a trajectory tracking problem. For unicycle robots, trajectory tracking is achieved by controlling a point, which is holonomic, some small distance $l$ away from the center of the the two wheels rather than controlling the unicycle robot directly. To do this, we can derive the following rotation matrix to transform the control law of the robot to the control law of the point: $$\dot{p}=\left[\begin{matrix}\dot{p_x}\\\dot{p_y}\end{matrix}\right]=\left[\begin{matrix}\text{cos}(\theta)&-l\text{sin}(\theta)\\\text{sin}(\theta)&l \text{cos}(\theta)\end{matrix}\right]\left[\begin{matrix}v\\\omega\end{matrix}\right]$$

$\dot{p}$ is the velocity of the point being controlled, and it is decomposed into its $x$ and $y$ components.

At this point, control is quite simple; we control the point directly! The dynamics become: $$\dot{z}=\left[\begin{matrix}\dot{x}\\ \dot{y} \\ \dot{\theta} \end{matrix}\right] = \left[\begin{matrix}cos(\theta)&0\\sin(\theta)&0\\0&1\end{matrix}\right] \left[\begin{matrix}v\\\omega\end{matrix}\right]=\left[\begin{matrix}cos(\theta)&0\\sin(\theta)&0\\0&1\end{matrix}\right] \left[\begin{matrix}cos(\theta)&sin(\theta)\\-\frac{sin(\theta)}{l}&-\frac{cos(\theta)}{l}\end{matrix}\right]\left[\begin{matrix}\dot{p}_x\\\dot{p}_y\end{matrix}\right],$$Setting $$\dot{p}=u=r(t)=\left[\begin{matrix}r_x(t)\\r_y(t)\end{matrix}\right],$$ accomplishes this, where $u$ is the input, and $r(t)$ is the reference trajectory that you want, decomposed into its $x$ and $y$ components; this will accomplish movement along the trajectory.

With the controller designed, the last component of building a line-following robot will be to implement some form of perception. If you have a downward facing camera and assume a level surface, consistent lighting, and good contrast between the line and its background, then you can use simple computer vision techniques to measure the error between the point $p$ and the desired trajectory. A simple proportional controller can be used to drive the robot along the line.


Not the answer you're looking for? Browse other questions tagged or ask your own question.