PID line follower with steering wheel

Hello, i’m making a packing machine for my company which is based on a PID line follower tricycle with a frontal steering wheel.
The sensor is an array of 8 phototransistors placed in line, and the PID error is how much distance is there between the center of the sensor array and the center of the line (positive or negative).

The direction of the robot is given by the frontal steering wheel. The turning is controlled by a 24v DC motor with it’s own driver (not a servo). An arduino mega 2560 control two of the driver’s inputs: go left, and go right (actually from the driver’s point of view is: go straight and go back).
So the PID output have to control the steering motor, but i’m not shure about what actually this output have to mean.

I started thinking that the PID output should be the direction of the steering wheel: so if the error is 0 the direction is straight, if the error is MAX the direction is 100% left and if the error is -MAX the
direction is 100% right.
I accomplished this by taking the time it takes for the motor to go from the left limit switch to the center “limit switch”. to know the steer direction i just have to keep track of the time i have the motor on (and in which direction), and realized a kind-of-servo.
This is working, or even, the robot is following the line, but when the line turn the steering wheel start to turn, than go straight, than turn than go straight in a kind of “parkinson” way. I tried to tune the PID parameters with trial and error tests, but i did not found a good combination.

Then i just realized that when the line is turning, a zero error does not mean “steering wheel straight”, but just “don’t turn more” or “stop the steering motor”. So a positive error is “steer a little more left” and a negative one is “steer a little more right”, but i can’t translate this into the role of the PID output… is it the time to keep the motor on? And what should appen if this time changes while the steering wheel is moving?
I came out with this code, that have to be executed in the main loop.

if(PID_out>0) {
    if(!DX) start_time = millis();
    if(!digitalRead(RightLimitSW) && millis()-start_time<PID_out )  {
        digitalWrite(sx,0);
       	digitalWrite(dx,1);
        DX=1; SX=0;
    } else {
        digitalWrite(sx,0);
        digitalWrite(dx,0);
        DX=0; SX=0;
    }
} else if(PID_out<0) {
    if(!SX) start_time = millis();
    if(!digitalRead(LeftLimitSW) && millis()-start_time<-PID_out )  {
        digitalWrite(sx,1);
        digitalWrite(dx,0);
        DX=0; SX=1;
    } else {
        digitalWrite(sx,0);
        digitalWrite(dx,0);
        DX=0; SX=0;
    }
} else {
    digitalWrite(sx,0);
    digitalWrite(dx,0);
    DX=0; SX=0;
}

I tried this one and it’s working better compared to the previous one, and it’s simpler.
I am now in the PID tuning phase, but i understand that not only the parameters influence the PID, but also the way you “use” the PID output does, and i’m absolutley not shure that this is the best way.
I tried to search on internet about a “steering wheel” line follower, but i just can find material about the classic “two motor” one. So i have to compare with somebody about this… Is there a “standard” way to manage the steering wheel pid? or maybe you have some idea or faced the same problem before?

Then i just realized that when the line is turning, a zero error does not mean "steering wheel straight", but just "don't turn more" or "stop the steering motor". So a positive error is "steer a little more left" and a negative one is "steer a little more right", but i can't translate this into the role of the PID output... is it the time to keep the motor on? And what should appen if this time changes while the steering wheel is moving?

The PID output is the error value, isn't it? It's positive, zero, or negative, depending on the amount of deviation between the steered direction and the actual direction (of the line).

So, you need to know the current servo position, and increase or decrease that value, based on the PID output.

You are likely not going to use the magnitude of the output in a direct fashion. Instead, you'll use the value to decide if you need a little change or a big change, and the sign of the change. Then, you'll apply the change, and check again.

The key is to check again often enough so that tiny inputs are all that are ever needed. Watch a kid learning to ride a bicycle. Look at the big inputs they give the system. Compare that to an experienced person on a bicycle. You can barely see the inputs.

With a steering wheel you need to compensate for forward speed - the faster you are going the more rapidly the robot responds to changes in steering direction, so you should probably scale down the output value proportionate to the forward speed, so that the PID parameters
are likely to work similarly/stably at a range of different speeds.

The error value is usually the input to a PID algorithm, its the difference between actual
(fed-back) and wanted (commanded) values (here left/right position) and is signed.
The output is the drive to the external system value. If you have an integral term the
output need not be zero-based, since the I-term will compensate for any offset. In general
though its best to arrange for it to be zero based so the I-term can be zero.

A PID implementation might take the actual and wanted values directly and calculate
the error itself of course. There's more than one way to code things.