# How to execute trajectory?

I have a trajectory which is a function of time that returns tuples of position, velocity, acceleration and jerk for each moment. So at every control loop iteration I would like the motion of my actuator to match these values. However it is not clear how to build a control system which will be able to follow position, velocity, acceleration and jerk commands altogether.

The actual question is that of control system input. In the vast majority of cases input is just a force which in context of PWM is just a number. Therefore natural question arises: should I anyhow map my 4 trajectory parameters to this one input of control system(if yes then how?) or is there any other way?

• you can not independently control all of those parameters. In any case i dont see how you could begin to generalize an answer to this without a detailed description of the system. – agentp Sep 13 '17 at 22:43
• You actually can control them all, but you need a system with totally overkill force/torque capacity. Which is a silly approach to the problem. Drive position, capping speed, acceleration and jerk to maximum allowable values is a real-world problem. Drive with all these preset is an exercise in futility and a waste of resources. – SF. Sep 18 '17 at 18:13

## 2 Answers

You have to choose a controller that best fits the system you are trying to control. You have to take into consideration the variables you are trying to control when deciding on the controller. Although the trajectory generator outputs four different values you don't have to use all of them.

Judging from your question I assume you're trying to control the motion of something, maybe the movement of a robot arm or something similar, from position A to B. This has to happen in a smooth manner, which is why you have a trajectory. If this doesn't describe your system you will at least get a notion of how you can "merge" the trajectory outputs together.

A simple controller that is easy to implement is the PID controller. It takes two of the trajectory outputs into account (position and velocity). Its controller law is expressed as

$$u(t) = K_p \cdot e(t) + K_i \cdot \int e(t) + K_d \cdot \dot{e}(t)$$

where $u(t)$ is the input to the actuator, if you only have one actuator. The unit of $u(t)$ doesn't matter as you have to scale the PID parts anyway (see below).

$e(t)$ is the error, and in this particular case defined as $e(t) = p_d - p$ (difference between desired position and actual measured position). Desired position is what you get from the trajectory. That makes $\dot{e} = v_d - v$. You get the desired velocity from the trajectory. You have to measure the velocity $v$. If you can't measure it you have to estimate it with a state observer. $\int e(t)$ is the accumulated error over time.

$K_p$, $K_i$ and $K_d$ are scaling factors (or gains). These are usually constants and have to be chosen by you using dimensional analysis and tuning on the real system. You choose the gains so that $u(t)$ looks reasonable with respect to magnitude.

You can expand the PID controller to include acceleration and jerk by adding additional parts to it. But as mentioned before, even though the trajectory outputs four parameters doesn't mean you have to use all of them, it just makes the motion smoother if implemented correctly. You could for instance choose to only use a P controller

$$u(t) = K_p \cdot e(t)$$

I'm not going to write all the theory behind this controller here. You can read more on Wikipedia.

If you want to track a trajectory and its derivatives is equivalent to just tracking that trajectory. However depending on your controller and reference signal you might get a steady state error.

In order to know how to choose an appropriate controller we have to look at how a potential reference could look like. In the worst case the highest derivative of the reference we want to track is a constant, so of the form $t^n$. The Laplace transform of this is $n!\,s^{-1-n}$. So in order for the steady state error to be zero the sensitivity transfer function should have bigger positive slope at low frequencies than the negative slope of the Laplace transform of the reference. This implies that in general you want your openloop (plant times controller transfer function) to have at least $n+1$ integrators.

But I should also mention that you can also get a huge performance improvement by using feed forward.