# Basic general question about controllers

Suppose I have a mechanical system which is free to move on a given rail [-5m, 5m] like a motorized cart. The whole system can be mathematically expressed through a *linear timeinvariant* system equations.

If I need to *control* *only* the position (for example saying the controller: "move to +2.3") I can simply design a PID controller that, given a set point moves the cart to that position.

Now I need much more and I want to *control* the *position* **and** the *velocity* of the cart. So I need for example to say: "move to +2.3 with a specific velocity's profile". Of course the *vel = 0* at the end position.

Question: how should I design such a controller? Do I need specifically a special type of controller? Or I have a huge choice?

Any help, graph, link and example is really appreciated.

Regards

## Answers 2

PID would work just fine. Your system can be easily modeled as a linear system and is relatively easy to control. When you want to choose a control method, you need to know the dynamics of your system, computation resources, and how much you wanna go deep into mathematical stuff(one reason why so many people choose PID).

To solve your control problem using PID, you need to define your X and Y as functions of time based on your desired velocity. So you will have: $$ X(t), Y(t)$$

Or in case of moving on a rail, define travel distance as a function of time. Then in each iteration of your control loop you know where the cart was supposed to be and where it really is. The difference is the error that you should put in PID equation. It might not always be so straight forward. In most of multi-output control systems error is a mix of multiple state errors(such as path tracking in 2D with differential wheel robots).

The Matlab code below might help you better understand the process. In case you don't have access to Matlab, Octave should be able to run the code too(maybe with some small adjustments).

I've assumed that there is a rail that looks like this:

And you want to move on it with a velocity profile like this:

Then follow this example:

The best control you can design is "exact feed forward linearization based on differential flatness". This is a complete approach to design control laws for flat systems.

Just PID is not a good idea : you will get overshoot and you do not master precisely position/velocity.

Flatness is a generalization on controllability. Hence you are sure that your system can achieve any position/velocity profile provided you remain inside the physical constraints.