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$
setMotorSpeed(midSpeed + value, midSpeed - value)
According to the sign of the value, speed changes and robot turns.. $\endgroup$midSpeed
and then varyingvalue
to turn. $\endgroup$