# Length and Width of a Line Following Robot

I'm building a line following robot. I have made different chassis designs. The main prototype I'm using is a rectangle base. At one side motors are placed. On the other side of the rectangle caster wheel is placed in the middle. Look at the following image.

By varying the values of distance, I have seen that the stability of the robot is varying rapidly.

I'm driving the robot using PID. I have seen that for some chassis designs it is very hard(sometimes impossible) to calculate correct constant values. And for some chassis it is very easy. By the word stability I meant this. I have a feeling that the robot dimensions, distance values and that stability has a relationship..

Is there an equation or something that can be used to estimate the value of the distance when the width of the robot is known..?

Other than that is there a relationship between robot weight and diameter of the wheel or robot dimensions and the diameter..?

Thanks for the attention!!

• Can you give us more information about what you mean by "stability"? I'm guessing you mean that the caster wheel is on a bit of an offset so it causes the vehicle to turn a bit when driving in reverse (to the right in your image)? If the caster wheel was just a ball with minimal friction then changing the distance shouldn't make any difference to the kinematics at all. – Brian Lynch Nov 27 '15 at 20:04
• Word stability is explained in the post. I edited the earlier post. – Ramesh-X Nov 27 '15 at 20:25
• Great, that helps a lot. How is your PID controller working? Are you controlling both speed and turn rate? – Brian Lynch Nov 27 '15 at 20:31
• PID algorithm is generating a values according to the error of sensor reading. The generated value is used to change the mid speed value of the motor. setMotorSpeed(midSpeed + value, midSpeed - value) According to the sign of the value, speed changes and robot turns.. – Ramesh-X Nov 27 '15 at 20:40
• Cool, so you are maintaining a constant midSpeed and then varying value to turn. – Brian Lynch Nov 27 '15 at 20:44

Actually, the caster wheel has ideally no effect on the kinematics of the vehicle. In reality there will be some resistance from the caster wheel that does impact the vehicle motion, but we can still ignore it for the sake of designing a control law.

Based on the extended discussion in the comments, your sensor can be used to measure the lateral error of the robot with respect to the line it is following. Consider the diagram below, where the robot position is depicted with a dark blue circle and its direction of motion is the red arrow (with constant speed $v$). The lateral error is $e$ (perpendicular distance to the line), while the heading error is $\alpha$ (angle of the velocity with respect to the line).

What you care about is having a control law that controls the robot heading so that an appropriate value of $\alpha$ causes $e$ to be minimized. To do that, consider the error dynamics of $e$:

$\dot{e} = v \sin \alpha$

Which can be extended to:

$\ddot{e} = v \dot{\alpha} \cos \alpha$

If we ignore the fact that the line direction may be changing (valid for most cases similar to roads), then the rate of change of the heading error is approximately the rate of change of the robot heading (turn rate $\omega$):

$\dot{\alpha} \approx \omega$

$\ddot{e} = v \omega \cos \alpha$

Now comes the tricky part. What we really want to do is minimize the error $e$ by controlling the turn rate $\omega$, but the above equation is non-linear and we prefer to design control laws with linear systems. So let's make up a new control input $\eta$ that is related to $\omega$:

$\eta = v \omega \cos \alpha$

Then we can make a feedback control law for $\eta$. I'll go straight to the answer and then follow it up with the details if you are interested...

The feedback controller can be a full PID as shown below:

$\eta = -K_p e - K_d \dot{e} - K_i \int e dt$

And then we calculate the necessary turn rate $\omega$:

$\omega = \frac{\eta}{v \cos \alpha}$

Normally you might do this by using a measurement of $\alpha$, but since you are only measuring $e$ you could just assume that term is constant and use:

$\omega = \frac{\eta}{v}$

Which is really just using a PID control law for $\omega$ based on $e$ but now with the factor $\frac{1}{v}$ in the gains.

With $\omega$ known, you can compute the necessary wheel speed differential as follows (based on your variable names, and where $b$ is the width between wheels):

midSpeed + value $= \frac{1}{2} \omega b + v$

$v =$ midSpeed

value $= \frac{1}{2}\omega b$

Overall, you are computing $\omega$ using a PID control law as a function of lateral error $e$ (coming from your sensor). You then compute value from the value for $\omega$ and use it to determine the left and right wheel speeds.

Now, read on for more details regarding the error dynamics and linearized control system:

We can write out the system dynamics like this, where we consider $z$ to be the vector of the error states.

$z = \begin{bmatrix} \dot{e} \\ e \end{bmatrix}$

$\dot{z} = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} z + \begin{bmatrix} 1 \\ 0 \end{bmatrix} \eta$

If you are familiar with linear control theory then you can start to see how this is a convenient form where we can make a feedback control law with input $\eta$ as a function of the error:

$\eta = -\begin{bmatrix} K_d & K_p \end{bmatrix} z$

$\dot{z} = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} z - \begin{bmatrix} 1 \\ 0 \end{bmatrix} \begin{bmatrix} K_d & K_p \end{bmatrix} z$

$\dot{z} = \begin{bmatrix} -K_d & -K_p \\ 1 & 0 \end{bmatrix} z$

This closed-loop system has the following characteristic equation:

$s^2 + K_d s + K_p = 0$

Which results in the poles (this is a PD control law, not PID):

$p = -\frac{1}{2}K_d \pm \sqrt{\frac{1}{4}K_d^2 - Kp}$

So if you wanted a critically damped system with no oscillations around the line, you could choose one of the gains and use the following relationship to get the other (start with smaller gains and tune until you get the response you want):

$K_p = \frac{1}{4}K_d^2$

• No problem, the only thing I didn't talk about was how to convert your 8-bit sensor reading into an estimate of the lateral error. That shouldn't be too hard but let me know if you need some ideas! – Brian Lynch Nov 28 '15 at 10:54
• I can do that.. But I have another question. When implementing this kind of a kinematic model, there can be error due to factors like mass, friction of the robot. How to minimize the error due to those factors..? Do I need to implement a kinetic model..? I think it would be hard.. – Ramesh-X Nov 28 '15 at 11:02
• What I have shown here is for a robot like yours but assuming that the wheel does not slip sideways. Mass has no consequence here since our input is the actual turn rate $\omega$, not the applied torque. This then assumes your robot has its own control system for applying appropriate voltage to the motors to achieve the input turn rate and speed. You are referring to a dynamic model, which is indeed harder but not too difficult. The real question is: do you need to? If your robot accepts $v$ and $\omega$ commands, then you don't have to worry about it. – Brian Lynch Nov 28 '15 at 11:23