# Orientation and horizontal position control of a bar in 2D

I have a scenario where I have a bar of 0.1 m in length, 10N weight is applied in the center. Two forces are applied on the bar at both ends vertically, right one if 5.1 N and the left one is at changing magnitude, I denoted as F+5 N.

F is a value to be determined with the controller, initially 0. I want to be able to keep the bar facing upwards (upside down is prohibited), and not deviating from x = 0 much by controlling the changing force. F cannot be negative.

Initially system is at rest. After t = 0 system will rotate CCW as expected.

I implemented a basic P controller in Simulink as shown below to get following.

I have several questions related to this:

1. With this system(one input), can I obtain a solution which will keep both horizontal error and orientation error within a certain limit? If so, what kind of controller should I implement?
2. I wanted to add PID controller block of Simulink to tune the gains. However it raised error of 'the system cannot be linearized'. At first I thought this was related to underactuation (since I use only 1 input, but need 3 actually). But now I start to think that it is related to nonlinearity. What is the main reason that prevents non-linearization?
3. If I add 2 more forces, can I use PID for my purpose? Or the system becomes MIMO and I cannot?

1. There is quite a trivial solution to this problem if you take a step-back and look at it from a simple mechanical point of view! There's an open-loop value of $$F$$ that will perfectly keep $$x=0$$ and $$\theta=0$$. Try sticking in $$F=0.1N$$
2. You are right, the system is nonlinear, but you actually still should be able to keep $$x$$ marginally stable, even if not properly stable. The reason the bar is flying off to the left is because you have a steady-state error in $$\theta$$, which luckily you can fix by just adding an integral term. Now, because I don't have access to a MATLAB license I can't test this for you , but I would suggest adding one of these blocks here (+ a gain block) in parallel with you're proportional term. The key is that it should ONLY be feedback from $$\theta$$.
I am presuming here that you have tried to add feedback to $$x$$. If you write out the equations of motions you can see that the control input is multiplied by a function of $$\theta$$ which may be why MATLAB is having trouble linearising:
$$m \ddot x = -5.1sin(\theta) - 5sin(\theta) - Fsin(\theta)$$ $$m \ddot y = -10 + 5.1cos(\theta) + 5cos(\theta) + Fcos(\theta)$$ $$I \ddot \theta = 0.005 - 0.05F$$
There's a discussion here about what you could do about it how to handle state space model where states are multiplied by inputs ?. But as I've said earlier, you'll be able to stop $$x$$ from being completely unstable without even bothering to try and control it.