Yansi, if I understand you correctly. We get the error by "w - w_ref", then we apply integral multiplied with constant for Integral part, and for the proportional part we multiply just with a constant. Then we sum the signals, and connect directly with output which is I_ref?
How do we know that we get electrical current (I) or torque (T) on the output? This part I don't understand, on the output we can get any physical quantity.
Are you talking about motor or PID controller? If about PID controller then you are the one who sets the relationship between the input and output variable.
You already have definied what is the input variable, it's an error of the variable you are controlling, and you know the output, this is what you want to control.
So let's say you want to control DC motor speed, so the input is speed error and the output is motor supply voltage.
The transfer function is T = Output/Input
What is the input? Speed error, let's say in RPM.
What is the output? Motor supply voltage, in Volts.
Now you construct your PID controller which units of transfer function are in Volts per RPM.
Any transfer function is: T = Output/Input (in Laplace domain)
Specifically, transfer function of one of variants of (there are several, check on wikipedia) PID controller is: T = Kp + Ki/s + Kd*s
Set it side by side: Kp + Ki/s + Kd*s = Output/Input = Voltage/Speed [V/RPM]
So by tuning PID controller (Kp, Ki, Kd gains in PID controller equation) you basically telling PID controller how many volts it has to put per 1 RPM of error signal.
Example:
Let's say that you set Ki = 0, Kd = 0, and Kp = 2, so you have only Proportional controller. Equation is now: Voltage = Kp*Speed = 2*Speed.
So if you have 10 RPM error at some instant, then you will output 20 volts to motor.
Now, if you are asking about plant/process, in this example DC motor, how do we know what is it's transfer function, what is the input and how it is coupled to output, everything comes from analysis.
Check this out:
http://ctms.engin.umich.edu/CTMS/index.php?example=MotorSpeed§ion=SystemModelingAs you see, DC motor consists of electrical part and mechanical part.
In general, the torque generated by a DC motor is proportional to the armature current and the strength of the magnetic field. In this example we will assume that the magnetic field is constant and, therefore, that the motor torque is proportional to only the armature current i by a constant factor Kt as shown in the equation below. This is referred to as an armature-controlled motor.
Personally I dunno much about motors but take a look at this analysis:
https://www.precisionmicrodrives.com/content/dc-motor-speed-voltage-and-torque-relationships/It states that:
In summary, we can highlight the two main variables which affect the speed of the motor in our final equation:
Input Voltage: For a fixed load, the speed of the motor is affected by applied voltage. Increase in voltage = increase in speed
Load Torque: For a fixed voltage, the speed of the motor is inversely affected by the load. Increase in load torque = decrease in speed
Now you asked about speed control, @Yansi showed earlier a cascade PI controller which controls both, speed and torque.
Perhaps it is possible to ignore torque part and just construct one PI controller in case if you want to control speed for fixed load?
I think that cascade control shown by @Yansi is the universal, common way of doing it in servomechanisms?
From what I recall from control theory classes cascaded PID doesn't guarantee stability right (you mentioned earlier the problem with double integrators etc)
Yet they still are cascade PID's without a problem? Or modern servos and drives use modern control theory? Please answer if you know

Also keep in mind practical issues: Integral windup and physical limitations. Found a series of videos shining some light about PID theory, DC motor model, controlling it and practical considerations: